Created
July 31, 2013 18:21
-
-
Save dristic/6124662 to your computer and use it in GitHub Desktop.
WebRTC Data Channel Examples.
This file contains 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 pubnub = PUBNUB.init({ | |
publish_key: 'demo', | |
subscribe_key: 'demo' | |
}); | |
// Here is where you can use PubNub Presence to get the UUID of the other user | |
// var uuid = 'ABC123' | |
pubnub.subscribe({ | |
user: uuid, // This tells PubNub to use WebRTC Data Channel | |
callback: function (message) { | |
console.log("I got the message: ", message); | |
} | |
}); | |
pubnub.publish({ | |
user: uuid, // This tells PubNub to use WebRTC Data Channel | |
message: "Hello World!" | |
}); |
This file contains 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 peerConnection = new RTCPeerConnection(); | |
var dataChannel = peerConnection.createDataChannel(“mylabel”); | |
dataChannel.onmessage = function (event) { | |
console.log(“I got a data channel message”, event.data); | |
}; | |
dataChannel.send(“Hello World!”); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment