Skip to content

Instantly share code, notes, and snippets.

@eduartua
Created May 29, 2024 17:54
Show Gist options
  • Save eduartua/c624e49a124a5c25ef81c19521697da1 to your computer and use it in GitHub Desktop.
Save eduartua/c624e49a124a5c25ef81c19521697da1 to your computer and use it in GitHub Desktop.
<html>
<head>
<title>pion test</title>
</head>
<body>
<video id="video" autoplay controls playsinline> </video>
</body>
<script>
let pc = new RTCPeerConnection({
iceServers: [
{
urls: 'stun:stun.l.google.com:19302'
}
]
});
navigator.mediaDevices.getUserMedia({ audio: true })
.then(stream => {
stream.getTracks().forEach(function(track) {
pc.addTrack(track, stream);
});
}).catch(err => {
throw new Error('error adding track', err)
})
pc.ontrack = function (event) {
document.getElementById('video').srcObject = event.streams[0]
}
pc.addTransceiver('audio')
pc.createOffer()
.then(offer => {
pc.setLocalDescription(offer)
return fetch(`/doSignaling`, {
method: 'post',
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json'
},
body: JSON.stringify(offer)
})
})
.then(res => res.json())
.then(res => pc.setRemoteDescription(res))
.catch(alert)
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment