diff options
| author | Code WvS <code-wvs@quantentunnel.de> | 2015-03-08 10:01:11 +0100 |
|---|---|---|
| committer | Code WvS <code-wvs@quantentunnel.de> | 2015-03-08 10:01:11 +0100 |
| commit | 0b9b31b84c1070e51d4d3e257db5ccb1e63db683 (patch) | |
| tree | 5d15dda7804c76f28ceacb285241163b83dba284 /threads.js | |
| parent | 6769c91b58751b15ca45528ef0afbbc23a7525d2 (diff) | |
| parent | da6c1a37a3f760ec787299f5a7f2bbf1a149acf5 (diff) | |
| download | snap-yow-0b9b31b84c1070e51d4d3e257db5ccb1e63db683.tar.gz snap-yow-0b9b31b84c1070e51d4d3e257db5ccb1e63db683.zip | |
Merge remote branch "p2p"
Diffstat (limited to 'threads.js')
| -rw-r--r-- | threads.js | 50 |
1 files changed, 50 insertions, 0 deletions
@@ -1295,6 +1295,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) { |
