Created
September 9, 2014 00:33
-
-
Save tokafish/2ee8aa007b111c9c91b9 to your computer and use it in GitHub Desktop.
Simple Peer
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 peer1 = new SimplePeer({ initiator: true }); | |
var peer2 = new SimplePeer(); | |
peer1.on('signal', function (data) { | |
// when peer1 has signaling data, give it to peer2 | |
peer2.signal(data); | |
}); | |
peer2.on('signal', function (data) { | |
// same as above, but in reverse | |
peer1.signal(data); | |
}); | |
peer1.on('ready', function () { | |
// wait for 'ready' event before using the data channel | |
peer1.send('hey peer2, how is it going?') | |
}); | |
peer2.on('message', function (data) { | |
// got a data channel message | |
console.log('got a message from peer1: ' + data); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment