Skip to content

Instantly share code, notes, and snippets.

@dristic
Created July 31, 2013 18:21
Show Gist options
  • Save dristic/6124662 to your computer and use it in GitHub Desktop.
Save dristic/6124662 to your computer and use it in GitHub Desktop.
WebRTC Data Channel Examples.
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!"
});
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