diff options
| author | Gubolin <gubolin@fantasymail.de> | 2015-03-08 09:52:49 +0100 |
|---|---|---|
| committer | Gubolin <gubolin@fantasymail.de> | 2015-03-08 09:52:49 +0100 |
| commit | 808076ff0f36d87a514a56de747f0c937624e75d (patch) | |
| tree | e61fc54710bdaddecc2c82389ebde9088a627f91 /threads.js | |
| parent | 3db303417ecb4d7200f65be05204acdf2d77aa7c (diff) | |
| parent | da6c1a37a3f760ec787299f5a7f2bbf1a149acf5 (diff) | |
| download | snap-808076ff0f36d87a514a56de747f0c937624e75d.tar.gz snap-808076ff0f36d87a514a56de747f0c937624e75d.zip | |
Merge branch p2p into development
Diffstat (limited to 'threads.js')
| -rw-r--r-- | threads.js | 50 |
1 files changed, 50 insertions, 0 deletions
@@ -1320,6 +1320,56 @@ Process.prototype.doRemoveTemporaries = function () { } }; +// Peer to peer primitives + +Process.prototype.sendPeerMessage = function (message, peer) { + var myself = this; + + if (peer instanceof List) { + peer.asArray().forEach(function (singlePeer) { + myself.sendPeerMessage(message, singlePeer); + }); + return; + } + + var stage = this.homeContext.receiver.parentThatIsA(StageMorph), + ide = this.homeContext.receiver.parentThatIsA(IDE_Morph); + var connection = stage.peer.connect(peer, {reliable: true}); + connection.on('open', function () { + var data; + if (typeof message == "string") { + data = message; + } else if (typeof message == "function") { + data = message.toString(); + } else { + data = ide.serializer.serialize(message); + } + connection.send(data); + }); +}; + +Process.prototype.reportPeerList = function () { + var myself = this; + + if (!this.context.wait) { + var stage = this.homeContext.receiver.parentThatIsA(StageMorph); + stage.peer.listAllPeers(function (peers) { + myself.context.result = new List(peers); + }); + this.context.wait = true; + } else if (this.context.result) { + return this.context.result; + } + + this.pushContext('doYield'); + this.pushContext(); +}; + +Process.prototype.reportPeerId = function () { + var stage = this.homeContext.receiver.parentThatIsA(StageMorph); + return stage.peerId; +}; + // Process lists primitives Process.prototype.reportNewList = function (elements) { |
