Created
April 3, 2024 01:32
-
-
Save Sean-Der/21ebaa25522f430524af5bfca3bdb836 to your computer and use it in GitHub Desktop.
Minimal WHEP Player against Broadcast Box
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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