Skip to content

Instantly share code, notes, and snippets.

@szimek
Created February 21, 2016 23:09
Show Gist options
  • Save szimek/8a22f1f5471cb48a4658 to your computer and use it in GitHub Desktop.
Save szimek/8a22f1f5471cb48a4658 to your computer and use it in GitHub Desktop.
var SimplePeer = require('simple-peer')
// get video/voice stream
navigator.getUserMedia({ video: true, audio: true }, gotMedia, function () {})
function gotMedia (stream) {
var peer1 = new SimplePeer({ initiator: true })
var peer2 = new SimplePeer({ stream: stream })
peer1.on('signal', function (data) {
peer2.signal(data)
})
peer2.on('signal', function (data) {
peer1.signal(data)
})
peer1.on('stream', function (stream) {
// got remote video stream, now let's show it in a video tag
var video = document.querySelector('video')
video.src = window.URL.createObjectURL(stream)
video.play()
})
}
@makamekm
Copy link

makamekm commented May 1, 2020

Old code, it doesn't work now.
createObjectURL(stream) returns undefined
Sending signals in this way will break one of the pears, because they can send signals multiple times, but if you catch it more than ones, you get an exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment