Created
February 21, 2016 23:09
-
-
Save szimek/8a22f1f5471cb48a4658 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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() | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Old code, it doesn't work now.
createObjectURL(stream)
returns undefinedSending 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.