Skip to content

Instantly share code, notes, and snippets.

@XavM
Created April 25, 2019 10:03
Show Gist options
  • Save XavM/78bac54fd17a1870016342df7894ed64 to your computer and use it in GitHub Desktop.
Save XavM/78bac54fd17a1870016342df7894ed64 to your computer and use it in GitHub Desktop.
[Safari only] "transceiverRequest" sent in a loop when the non initiator ".addStream"
<!DOCTYPE html>
<html lang="en" >
<head>
<script src="https://cdn.jsdelivr.net/gh/feross/simple-peer@c5f8a8ded50ef354d5a0f8a3700f8817565ed032/simplepeer.min.js"></script>
</head>
<body>
<button id="startVideoPeer1">Start Video Chat Peer1</button>
<button id="startVideoPeer2">Start Video Chat Peer2</button>
<p>
<video autoplay="" playsinline="" muted="" width="150px" id="video1"></video>
<video autoplay="" playsinline="" muted="" width="150px" id="video2"></video>
<script>
function main() {
var peer1 = new SimplePeer({ initiator: true })
var peer2 = new SimplePeer()
peer1.on('signal', function (data) {
console.log('signal on peer1')
peer2.signal(data)
})
peer2.on('signal', function (data) {
console.log('signal on peer2')
peer1.signal(data)
})
peer1.on('stream', function (stream) {
console.log('stream on peer1')
var video = document.querySelector('#video1')
video.srcObject = stream;
video.play()
})
peer2.on('stream', function (stream) {
console.log('stream on peer2')
var video = document.querySelector('#video2')
video.srcObject = stream;
video.play()
})
document.querySelector('#startVideoPeer1').onclick = async function() {
stream = await navigator.mediaDevices.getUserMedia({ video: { width: 150, height: 125 }, audio: false })
peer1.addStream(stream);
}
document.querySelector('#startVideoPeer2').onclick = async function() {
stream = await navigator.mediaDevices.getUserMedia({ video: { width: 150, height: 125 }, audio: false })
peer2.addStream(stream);
}
}
main()
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment