Skip to content

Instantly share code, notes, and snippets.

@ToeJamson
Created July 15, 2013 21:43
Show Gist options
  • Select an option

  • Save ToeJamson/6003771 to your computer and use it in GitHub Desktop.

Select an option

Save ToeJamson/6003771 to your computer and use it in GitHub Desktop.
PubShare
pubnub.subscribe({
channel: protocol.CHANNEL,
callback: this.handleSignal.bind(this),
presence: this.handlePresence.bind(this)
});
handlePresence: function (msg) {
var conn = this.connections[msg.uuid];
if (conn) {
// Pass the message to specific contact/connection
conn.handlePresence(msg);
}
else {
// Create a new connection and update the UI list
}
}
handleSignal: function (msg) {
if (msg.action === protocol.ANSWER) {
console.log("THE OTHER PERSON IS READY");
this.p2pSetup();
}
else if (msg.action === protocol.OFFER) {
// Someone's ready to send a file.
// Let user opt-in to receive file data
// Update UI to indicate there is a file available
}
else if (msg.action === protocol.ERR_REJECT) {
alert("Unable to communicate with " + this.email);
}
else if (msg.action === protocol.CANCEL) {
alert(this.email + " cancelled the share.");
}
}
p2pSetup: function () {
console.log("Setting up P2P...");
this.shareStart = Date.now();
this.pubnub.subscribe({
user: this.id, // Indicates P2P communication
callback: this.onP2PMessage
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment