Skip to content

Instantly share code, notes, and snippets.

@Sean-Der
Created April 3, 2024 01:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sean-Der/21ebaa25522f430524af5bfca3bdb836 to your computer and use it in GitHub Desktop.
Save Sean-Der/21ebaa25522f430524af5bfca3bdb836 to your computer and use it in GitHub Desktop.
Minimal WHEP Player against Broadcast Box
<html>
<head>
<title>whep-static</title>
</head>
<body>
<h3> Video </h3>
<video id="videoPlayer" autoplay muted controls style="width: 500"> </video>
<h3> ICE Connection States </h3>
<div id="iceConnectionStates"></div> <br />
</body>
<script>
let peerConnection = new RTCPeerConnection()
peerConnection.addTransceiver('audio', { direction: 'recvonly' })
peerConnection.addTransceiver('video', { direction: 'recvonly' })
peerConnection.ontrack = function (event) {
document.getElementById('videoPlayer').srcObject = event.streams[0]
}
peerConnection.oniceconnectionstatechange = () => {
let el = document.createElement('p')
el.appendChild(document.createTextNode(peerConnection.iceConnectionState))
document.getElementById('iceConnectionStates').appendChild(el);
}
peerConnection.createOffer().then(offer => {
peerConnection.setLocalDescription(offer)
fetch(`https://b.siobud.com/api/whep`, {
method: 'POST',
body: offer.sdp,
headers: {
Authorization: `Bearer seanTest`,
'Content-Type': 'application/sdp'
}
}).then(r => r.text())
.then(answer => {
console.log(answer)
peerConnection.setRemoteDescription({
sdp: answer,
type: 'answer'
})
})
})
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment