-
-
Save ToeJamson/6003771 to your computer and use it in GitHub Desktop.
PubShare
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
| 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