diff options
| author | Gubolin <gubolin@fantasymail.de> | 2015-03-20 20:53:20 +0100 |
|---|---|---|
| committer | Gubolin <gubolin@fantasymail.de> | 2015-03-20 20:53:20 +0100 |
| commit | 121cf8b3658909f79571b621e9a9916c7f601dfc (patch) | |
| tree | ff2136892b76a278ecdb721894c628a08d66e9d9 /gui.js | |
| parent | 9163b3ca714086e1877249bf38e47040bd1b3e67 (diff) | |
| download | snap-121cf8b3658909f79571b621e9a9916c7f601dfc.tar.gz snap-121cf8b3658909f79571b621e9a9916c7f601dfc.zip | |
create one peer per IDEp2p
Diffstat (limited to 'gui.js')
| -rw-r--r-- | gui.js | 31 |
1 files changed, 30 insertions, 1 deletions
@@ -246,7 +246,36 @@ IDE_Morph.prototype.init = function (isAutoFill) { // override inherited properites: this.color = this.backgroundColor; - window.peers = []; + this.createPeer(); +}; + +IDE_Morph.prototype.createPeer = function() { + var myself = this; + this.peer = new Peer(this.peerId, { + host: 'snapmesh.herokuapp.com', + port: 443, + secure: true, + path: '/' + }); + + this.peer.on('open', function (id) { + myself.peerId = id; + }); + this.peer.on('disconnected', function () { + myself.peer.destroy(); + myself.createPeer(); + }); + this.peer.on('error', function (err) { + console.log(err); // DEBUG + }); + + this.peer.on('connection', function (connection) { + connection.on('open', function () { + connection.on('data', function (data) { + myself.stage.newPeerMessage(data, connection.peer); + }); + }); + }); }; IDE_Morph.prototype.openIn = function (world) { |
