From e45562fc530f74fff38baa7ba8c4f39ab8e4e08f Mon Sep 17 00:00:00 2001 From: jmoenig Date: Fri, 6 Feb 2015 11:29:46 +0100 Subject: Added url switch #cloud: to open a shared project in edit mode --- gui.js | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'gui.js') diff --git a/gui.js b/gui.js index 73fffe9..b30b6de 100644 --- a/gui.js +++ b/gui.js @@ -69,7 +69,7 @@ SpeechBubbleMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.gui = '2015-January-21'; +modules.gui = '2015-February-06'; // Declarations @@ -390,6 +390,46 @@ IDE_Morph.prototype.openIn = function (world) { }, this.cloudError() ); + } else if (location.hash.substr(0, 7) === '#cloud:') { + this.shield = new Morph(); + this.shield.alpha = 0; + this.shield.setExtent(this.parent.extent()); + this.parent.add(this.shield); + myself.showMessage('Fetching project\nfrom the cloud...'); + + // make sure to lowercase the username + dict = SnapCloud.parseDict(location.hash.substr(7)); + dict.Username = dict.Username.toLowerCase(); + + SnapCloud.getPublicProject( + SnapCloud.encodeDict(dict), + function (projectData) { + var msg; + myself.nextSteps([ + function () { + msg = myself.showMessage('Opening project...'); + }, + function () {nop(); }, // yield (bug in Chrome) + function () { + if (projectData.indexOf(' Date: Fri, 20 Feb 2015 12:49:18 +0100 Subject: Un-hide “Save to disk” feature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (currently supported by both Chrome and Firefox, but not by Safari) --- gui.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'gui.js') diff --git a/gui.js b/gui.js index b30b6de..5f7f3ab 100644 --- a/gui.js +++ b/gui.js @@ -69,7 +69,7 @@ SpeechBubbleMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.gui = '2015-February-06'; +modules.gui = '2015-February-20'; // Declarations @@ -2349,14 +2349,11 @@ IDE_Morph.prototype.projectMenu = function () { menu.addItem('New', 'createNewProject'); menu.addItem('Open...', 'openProjectsBrowser'); menu.addItem('Save', "save"); - if (shiftClicked) { - menu.addItem( - 'Save to disk', - 'saveProjectToDisk', - 'experimental - store this project\nin your downloads folder', - new Color(100, 0, 0) - ); - } + menu.addItem( + 'Save to disk', + 'saveProjectToDisk', + 'store this project\nin your downloads folder\n(not supported by all browsers)' + ); menu.addItem('Save As...', 'saveProjectsBrowser'); menu.addLine(); menu.addItem( -- cgit v1.3.1 From 662a743f4ed564f2c296e2370c555ca44e12116d Mon Sep 17 00:00:00 2001 From: jmoenig Date: Fri, 20 Feb 2015 15:01:43 +0100 Subject: Make “project data in URLs” a hidden dev option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (prevent long urls per default) --- gui.js | 43 +++++++++++++++++++++++++++++++++++++------ history.txt | 1 + 2 files changed, 38 insertions(+), 6 deletions(-) (limited to 'gui.js') diff --git a/gui.js b/gui.js index 5f7f3ab..c3104c5 100644 --- a/gui.js +++ b/gui.js @@ -202,6 +202,7 @@ IDE_Morph.prototype.init = function (isAutoFill) { // restore saved user preferences this.userLanguage = null; // user language preference for startup + this.projectsInURLs = false; this.applySavedSettings(); // additional properties: @@ -1779,6 +1780,7 @@ IDE_Morph.prototype.applySavedSettings = function () { language = this.getSetting('language'), click = this.getSetting('click'), longform = this.getSetting('longform'), + longurls = this.getSetting('longurls'), plainprototype = this.getSetting('plainprototype'); // design @@ -1812,6 +1814,13 @@ IDE_Morph.prototype.applySavedSettings = function () { InputSlotDialogMorph.prototype.isLaunchingExpanded = true; } + // project data in URLs + if (longurls) { + this.projectsInURLs = true; + } else { + this.projectsInURLs = false; + } + // plain prototype labels if (plainprototype) { BlockLabelPlaceHolderMorph.prototype.plainLabel = true; @@ -2281,6 +2290,21 @@ IDE_Morph.prototype.settingsMenu = function () { 'check for alternative\nGUI design', false ); + addPreference( + 'Project URLs', + function () { + myself.projectsInURLs = !myself.projectsInURLs; + if (myself.projectsInURLs) { + myself.saveSetting('longurls', true); + } else { + myself.removeSetting('longurls'); + } + }, + myself.projectsInURLs, + 'uncheck to disable\nproject data in URLs', + 'check to enable\nproject data in URLs', + true + ); addPreference( 'Sprite Nesting', function () { @@ -2352,7 +2376,8 @@ IDE_Morph.prototype.projectMenu = function () { menu.addItem( 'Save to disk', 'saveProjectToDisk', - 'store this project\nin your downloads folder\n(not supported by all browsers)' + 'store this project\nin your downloads folder\n' + + '(not supported by all browsers)' ); menu.addItem('Save As...', 'saveProjectsBrowser'); menu.addLine(); @@ -2825,7 +2850,7 @@ IDE_Morph.prototype.rawSaveProject = function (name) { try { localStorage['-snap-project-' + name] = str = this.serializer.serialize(this.stage); - location.hash = '#open:' + str; + this.setURL('#open:' + str); this.showMessage('Saved!', 1); } catch (err) { this.showMessage('Save failed: ' + err); @@ -2833,7 +2858,7 @@ IDE_Morph.prototype.rawSaveProject = function (name) { } else { localStorage['-snap-project-' + name] = str = this.serializer.serialize(this.stage); - location.hash = '#open:' + str; + this.setURL('#open:' + str); this.showMessage('Saved!', 1); } } @@ -2874,7 +2899,7 @@ IDE_Morph.prototype.exportProject = function (name, plain) { str = encodeURIComponent( this.serializer.serialize(this.stage) ); - location.hash = '#open:' + str; + this.setURL('#open:' + str); window.open('data:text/' + (plain ? 'plain,' + str : 'xml,' + str)); menu.destroy(); @@ -2887,7 +2912,7 @@ IDE_Morph.prototype.exportProject = function (name, plain) { str = encodeURIComponent( this.serializer.serialize(this.stage) ); - location.hash = '#open:' + str; + this.setURL('#open:' + str); window.open('data:text/' + (plain ? 'plain,' + str : 'xml,' + str)); menu.destroy(); @@ -3161,7 +3186,13 @@ IDE_Morph.prototype.openProject = function (name) { this.setProjectName(name); str = localStorage['-snap-project-' + name]; this.openProjectString(str); - location.hash = '#open:' + str; + this.setURL('#open:' + str); + } +}; + +IDE_Morph.prototype.setURL = function (str) { + if (this.projectsInURLs) { + location.hash = str; } }; diff --git a/history.txt b/history.txt index 1a69cfb..e125b70 100755 --- a/history.txt +++ b/history.txt @@ -2440,3 +2440,4 @@ ______ * Malayam, Tamil and Telagu translations, thanks, Vinay Kumar!! * Un-hide “Save to disk” feature (currently supported by both Chrome and Firefox, but not by Safari) * Update German translation +* GUI: Make “project data in URLs” a hidden dev option (prevent long urls per default) -- cgit v1.3.1 From e6dcf07b3de5cac657fc453d1da7814091a53500 Mon Sep 17 00:00:00 2001 From: jmoenig Date: Mon, 23 Feb 2015 14:56:10 +0100 Subject: Update German translation --- gui.js | 6 +++--- history.txt | 5 +++++ lang-de.js | 21 ++++++++++++++++----- locale.js | 4 ++-- 4 files changed, 26 insertions(+), 10 deletions(-) (limited to 'gui.js') diff --git a/gui.js b/gui.js index c3104c5..9fddf4d 100644 --- a/gui.js +++ b/gui.js @@ -69,7 +69,7 @@ SpeechBubbleMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.gui = '2015-February-20'; +modules.gui = '2015-February-23'; // Declarations @@ -2376,8 +2376,8 @@ IDE_Morph.prototype.projectMenu = function () { menu.addItem( 'Save to disk', 'saveProjectToDisk', - 'store this project\nin your downloads folder\n' - + '(not supported by all browsers)' + 'store this project\nin the downloads folder\n' + + '(in supporting browsers)' ); menu.addItem('Save As...', 'saveProjectsBrowser'); menu.addLine(); diff --git a/history.txt b/history.txt index e125b70..50464ee 100755 --- a/history.txt +++ b/history.txt @@ -2441,3 +2441,8 @@ ______ * Un-hide “Save to disk” feature (currently supported by both Chrome and Firefox, but not by Safari) * Update German translation * GUI: Make “project data in URLs” a hidden dev option (prevent long urls per default) + +150223 +------ +* Blocks, Objects: Add user-interaction choices to the “When I am ...” hat block +* Update German translation diff --git a/lang-de.js b/lang-de.js index 2a0dff7..3040cc2 100644 --- a/lang-de.js +++ b/lang-de.js @@ -185,7 +185,7 @@ SnapTranslator.dict.de = { 'translator_e-mail': 'jens@moenig.org', // optional 'last_changed': - '2015-02-20', // this, too, will appear in the Translators tab + '2015-02-23', // this, too, will appear in the Translators tab // GUI // control bar: @@ -417,8 +417,18 @@ SnapTranslator.dict.de = { 'Wenn %greenflag angeklickt', 'when %keyHat key pressed': 'Wenn Taste %keyHat gedr\u00fcckt', - 'when I am clicked': - 'Wenn ich angeklickt werde', + 'when I am %interaction': + 'Wenn ich %interaction werde', + 'clicked': + 'angeklickt', + 'pressed': + 'gedr\u00fcckt', + 'dropped': + 'abgestellt', + 'mouse-entered': + 'vom Mauszeiger betreten', + 'mouse-departed': + 'vom Mauszeiger verlassen', 'when I receive %msgHat': 'Wenn ich %msgHat empfange', 'broadcast %msg': @@ -649,8 +659,9 @@ SnapTranslator.dict.de = { 'Sichern', 'Save to disk': 'Abpeichern', - 'store this project\nin your downloads folder\n(not supported by all browsers)': - 'dieses Projekt herunterladen\nund lokal speichern\n(nicht von allen Browsern unters\u00fctzt)', + 'store this project\nin the downloads folder\n(in supporting browsers)': + 'dieses Projekt herunterladen\nund lokal speichern\n' + + '(nicht von allen Browsern unters\u00fctzt)', 'Save As...': 'Sichern als...', 'Import...': diff --git a/locale.js b/locale.js index af9ea6f..f6059d6 100644 --- a/locale.js +++ b/locale.js @@ -42,7 +42,7 @@ /*global modules, contains*/ -modules.locale = '2015-February-20'; +modules.locale = '2015-February-23'; // Global stuff @@ -149,7 +149,7 @@ SnapTranslator.dict.de = { 'translator_e-mail': 'jens@moenig.org', 'last_changed': - '2015-02-20' + '2015-02-23' }; SnapTranslator.dict.it = { -- cgit v1.3.1 From 438fe4e3619c5dc52ca625a1e16048b30cf16c7d Mon Sep 17 00:00:00 2001 From: Gubolin Date: Tue, 24 Feb 2015 10:18:33 +0100 Subject: merge --- gui.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gui.js') diff --git a/gui.js b/gui.js index aa381ee..a7302dc 100644 --- a/gui.js +++ b/gui.js @@ -484,7 +484,7 @@ IDE_Morph.prototype.openIn = function (world) { myself.shield.destroy(); myself.shield = null; msg.destroy(); - myself.toggleAppMode(true); + myself.toggleAppMode(false); } ]); }, -- cgit v1.3.1 From ee88f7ad398fe9867ad1bcf1c2588704fc012151 Mon Sep 17 00:00:00 2001 From: Jens Mönig Date: Sat, 28 Feb 2015 05:44:59 -0800 Subject: Cache inputs - accelerate recursive reporters and warped / turbo recursive commands by up to 40% --- blocks.js | 29 ++++++++++++++++++++++++----- gui.js | 13 ++++++++++++- history.txt | 4 ++++ store.js | 3 ++- 4 files changed, 42 insertions(+), 7 deletions(-) (limited to 'gui.js') diff --git a/blocks.js b/blocks.js index 72aa5d0..5cdcc1c 100644 --- a/blocks.js +++ b/blocks.js @@ -155,7 +155,7 @@ DialogBoxMorph, BlockInputFragmentMorph, PrototypeHatBlockMorph, Costume*/ // Global stuff //////////////////////////////////////////////////////// -modules.blocks = '2015-February-23'; +modules.blocks = '2015-February-28'; var SyntaxElementMorph; @@ -340,6 +340,7 @@ SyntaxElementMorph.prototype.setScale = function (num) { }; SyntaxElementMorph.prototype.setScale(1); +SyntaxElementMorph.prototype.isCachingInputs = true; // SyntaxElementMorph instance creation: @@ -356,6 +357,7 @@ SyntaxElementMorph.prototype.init = function () { SyntaxElementMorph.uber.init.call(this); this.defaults = []; + this.cachedInputs = null; }; // SyntaxElementMorph accessing: @@ -375,10 +377,12 @@ SyntaxElementMorph.prototype.parts = function () { SyntaxElementMorph.prototype.inputs = function () { // answer my arguments and nested reporters - return this.parts().filter(function (part) { - return part instanceof SyntaxElementMorph; - }); - + if (isNil(this.cachedInputs) || !this.isCachingInputs) { + this.cachedInputs = this.parts().filter(function (part) { + return part instanceof SyntaxElementMorph; + }); + } + return this.cachedInputs; }; SyntaxElementMorph.prototype.allInputs = function () { @@ -494,6 +498,7 @@ SyntaxElementMorph.prototype.replaceInput = function (oldArg, newArg) { replacement.drawNew(); this.fixLayout(); } + this.cachedInputs = null; this.endLayout(); }; @@ -529,6 +534,7 @@ SyntaxElementMorph.prototype.silentReplaceInput = function (oldArg, newArg) { replacement.drawNew(); this.fixLayout(); } + this.cachedInputs = null; }; SyntaxElementMorph.prototype.revertToDefaultInput = function (arg, noValues) { @@ -571,6 +577,7 @@ SyntaxElementMorph.prototype.revertToDefaultInput = function (arg, noValues) { } else if (deflt instanceof RingMorph) { deflt.fixBlockColor(); } + this.cachedInputs = null; }; SyntaxElementMorph.prototype.isLocked = function () { @@ -1942,6 +1949,7 @@ BlockMorph.prototype.init = function () { BlockMorph.uber.init.call(this); this.color = new Color(0, 17, 173); + this.cashedInputs = null; }; BlockMorph.prototype.receiver = function () { @@ -2047,6 +2055,7 @@ BlockMorph.prototype.setSpec = function (spec) { }); this.blockSpec = spec; this.fixLayout(); + this.cachedInputs = null; }; BlockMorph.prototype.buildSpec = function () { @@ -2439,6 +2448,7 @@ BlockMorph.prototype.restoreInputs = function (oldInputs) { } i += 1; }); + this.cachedInputs = null; }; BlockMorph.prototype.showHelp = function () { @@ -3034,6 +3044,7 @@ BlockMorph.prototype.fullCopy = function () { //block.comment = null; }); + ans.cachedInputs = null; return ans; }; @@ -9186,6 +9197,10 @@ MultiArgMorph.prototype = new ArgMorph(); MultiArgMorph.prototype.constructor = MultiArgMorph; MultiArgMorph.uber = ArgMorph.prototype; +// MultiArgMorph preferences settings + +MultiArgMorph.prototype.isCachingInputs = false; + // MultiArgMorph instance creation: function MultiArgMorph( @@ -9616,6 +9631,10 @@ ArgLabelMorph.prototype = new ArgMorph(); ArgLabelMorph.prototype.constructor = ArgLabelMorph; ArgLabelMorph.uber = ArgMorph.prototype; +// ArgLabelMorph preferences settings + +ArgLabelMorph.prototype.isCachingInputs = false; + // MultiArgMorph instance creation: function ArgLabelMorph(argMorph, labelTxt) { diff --git a/gui.js b/gui.js index 9fddf4d..75220b3 100644 --- a/gui.js +++ b/gui.js @@ -69,7 +69,7 @@ SpeechBubbleMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.gui = '2015-February-23'; +modules.gui = '2015-February-28'; // Declarations @@ -2266,6 +2266,17 @@ IDE_Morph.prototype.settingsMenu = function () { 'uncheck to run scripts\nat normal speed', 'check to prioritize\nscript execution' ); + addPreference( + 'Cache Inputs', + function () { + SyntaxElementMorph.prototype.isCachingInputs = + !SyntaxElementMorph.prototype.isCachingInputs; + }, + SyntaxElementMorph.prototype.isCachingInputs, + 'uncheck to stop caching\ninputs (for debugging the evaluator)', + 'check to cache inputs\nboosts recursion', + true + ); addPreference( 'Rasterize SVGs', function () { diff --git a/history.txt b/history.txt index 7b0b6e5..1c33405 100755 --- a/history.txt +++ b/history.txt @@ -2451,3 +2451,7 @@ ______ 150224 ------ * Store: fixed #725 + +150228 +------ +* Blocks, Store, GUI: Cache inputs, accelerates evaluating recursive reporters and warped / turbo recursive commands by up to 40% diff --git a/store.js b/store.js index 91ff40e..b17fb49 100644 --- a/store.js +++ b/store.js @@ -61,7 +61,7 @@ SyntaxElementMorph, Variable*/ // Global stuff //////////////////////////////////////////////////////// -modules.store = '2015-February-24'; +modules.store = '2015-February-28'; // XML_Serializer /////////////////////////////////////////////////////// @@ -1027,6 +1027,7 @@ SnapSerializer.prototype.loadBlock = function (model, isReporter) { this.loadInput(child, inputs[i], block); } }, this); + block.cachedInputs = null; return block; }; -- cgit v1.3.1 From 53936404d5c8ed7a6433e8e9f71c235d34b477b9 Mon Sep 17 00:00:00 2001 From: Gubolin Date: Sun, 8 Mar 2015 09:28:56 +0100 Subject: rewrite peering flow; add peer id blocks --- gui.js | 2 + objects.js | 142 ++++++++++++++++++++++++++++++++++++------------------------- threads.js | 41 ++++++++++++++++++ 3 files changed, 126 insertions(+), 59 deletions(-) (limited to 'gui.js') diff --git a/gui.js b/gui.js index 75220b3..1f51405 100644 --- a/gui.js +++ b/gui.js @@ -245,6 +245,8 @@ IDE_Morph.prototype.init = function (isAutoFill) { // override inherited properites: this.color = this.backgroundColor; + + window.peers = []; }; IDE_Morph.prototype.openIn = function (world) { diff --git a/objects.js b/objects.js index 116c792..9399269 100644 --- a/objects.js +++ b/objects.js @@ -1188,6 +1188,16 @@ SpriteMorph.prototype.initBlocks = function () { category: 'other', spec: 'send %s to %s' }, + reportPeerId: { + type: 'reporter', + category: 'other', + spec: 'my peer id' + }, + reportPeerList: { + type: 'reporter', + category: 'other', + spec: 'peers online' + }, // Code mapping - experimental doMapCodeOrHeader: { // experimental @@ -2118,6 +2128,8 @@ SpriteMorph.prototype.blockTemplates = function (category) { blocks.push(block('receivePeerMessage')); blocks.push(block('sendPeerMessage')); + blocks.push(block('reportPeerId')); + blocks.push(block('reportPeerList')); blocks.push('='); @@ -4408,86 +4420,96 @@ StageMorph.prototype.init = function (globals) { this.setColor(new Color(255, 255, 255)); this.fps = this.frameRate; - this.peer = new Peer({ + this.initPeering(); +}; + +StageMorph.prototype.initPeering = function (id) { + var myself = this; + + if (window.peers) { + // I don't know why, but it works. + window.peers.forEach(function (oldpeer) { + if (id != oldpeer.id) { + oldpeer.destroy() + } + }); + } + + this.peer = new Peer(id, { host: 'snapmesh.herokuapp.com', - port: 80, + port: 443, + secure: true, path: '/' }); - var myself = this; this.peer.on('open', function (id) { myself.peerId = id; - console.log('Id: ' + id); // DEBUG + }); + this.peer.on('disconnected', function () { + // peer.reconnect does not work (?) because 'id' is undefined + if (!myself.peer.destroyed) { + myself.initPeering(myself.peerId); + } + }); + 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) { - var ide = myself.parentThatIsA(IDE_Morph); - var hats = [], model, message; - try { - model = ide.serializer.parse(data); - message = ide.serializer.loadValue(model); - - // TODO: If a Context is sent, a new Sprite appears. - // This below is just a workaround for one-level rings, - // objects should be cleaned recursively. - message.receiver = null; - message.outerContext = null; - } catch (err) { - console.log(err); // DEBUG - // Ok, it does not seem to be XML. It must be a string then. - message = data; - } - - // call hat blocks - myself.children.concat(myself).forEach(function (morph) { - if (morph instanceof SpriteMorph - || morph instanceof StageMorph) { - hats = hats.concat( - morph.allHatBlocksFor('__peer__message__')); - } - }); - hats.forEach(function (block) { - var process = myself.threads.startProcess(block, - myself.isThreadSafe); - process.context.outerContext.variables.addVar('message'); - process.context.outerContext.variables.setVar( - 'message', - message - ); - process.context.outerContext.variables.addVar('peer'); - process.context.outerContext.variables.setVar( - 'peer', - connection.peer - ); - }); + myself.newPeerMessage(data, connection.peer); }); }); }); + + window.peers.push(this.peer); }; -// peer to peer communication +StageMorph.prototype.newPeerMessage = function (data, peer) { + var ide = this.parentThatIsA(IDE_Morph); + var myself = this; + var hats = [], model, message; -SpriteMorph.prototype.sendPeerMessage = function (message, peer) { - var stage = this.parentThatIsA(StageMorph), - ide = this.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); + try { + model = ide.serializer.parse(data); + message = ide.serializer.loadValue(model); + + // TODO: If a Context is sent, a new Sprite appears. + // This below is just a workaround for one-level rings, + // objects should be cleaned recursively. + message.receiver = null; + message.outerContext = null; + } catch (err) { + console.log(err); // DEBUG + // Ok, it does not seem to be XML. It must be a string then. + message = data; + } + + // call hat blocks + this.children.concat(myself).forEach(function (morph) { + if (morph instanceof SpriteMorph + || morph instanceof StageMorph) { + hats = hats.concat( + morph.allHatBlocksFor('__peer__message__')); } - connection.send(data); + }); + hats.forEach(function (block) { + var process = myself.threads.startProcess(block, + myself.isThreadSafe); + process.context.outerContext.variables.addVar('message'); + process.context.outerContext.variables.setVar( + 'message', + message + ); + process.context.outerContext.variables.addVar('peer'); + process.context.outerContext.variables.setVar( + 'peer', + peer + ); }); }; -StageMorph.prototype.sendPeerMessage = SpriteMorph.prototype.sendPeerMessage; - // StageMorph scaling StageMorph.prototype.setScale = function (number) { @@ -5407,6 +5429,8 @@ StageMorph.prototype.blockTemplates = function (category) { blocks.push(block('receivePeerMessage')); blocks.push(block('sendPeerMessage')); + blocks.push(block('reportPeerId')); + blocks.push(block('reportPeerList')); blocks.push('='); if (StageMorph.prototype.enableCodeMapping) { diff --git a/threads.js b/threads.js index 50af8dd..bc8e429 100644 --- a/threads.js +++ b/threads.js @@ -1295,6 +1295,47 @@ Process.prototype.doRemoveTemporaries = function () { } }; +// Peer to peer primitives + +Process.prototype.sendPeerMessage = function (message, peer) { + 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) { -- cgit v1.3.1