Last active
August 29, 2015 14:06
-
-
Save tokafish/8922e1205f2ca6d4497d 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 peer = new SimplePeer({ initiator: true }); | |
peer.on('signal', function (data) { | |
channel.trigger('client-signal-' + peerUserId, { userId: currentUser.id, data: data }); | |
}); | |
peer.on('ready', function () { | |
peer.send('hey peer, how is it going?') | |
}); |
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 peer = undefined; | |
channel.bind('client-signal-' + currentUser.id, function(signal) { | |
if (peer === undefined) { | |
peer = new SimplePeer(); | |
peer.on('signal', function (data) { | |
channel.trigger('client-signal-' + signal.userId, { userId: currentUser.id, data: data }); | |
}); | |
peer.on('message', function (data) { | |
console.log('got a message from remote peer: ' + data); | |
}); | |
} | |
peer.signal(signal.data) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment