Commit 6ade384a authored by maybites's avatar maybites
Browse files

new remote peer list creation. each remote peer will be create in sequence instead of all together.

parent adc26810
...@@ -23,8 +23,8 @@ function bang() ...@@ -23,8 +23,8 @@ function bang()
function joined(_joined){ function joined(_joined){
if(_joined == 0){ if(_joined == 0){
dpost("local peer left room. cleaning up list of remote peers.."); dpost("local peer left room. cleaning up list of remote peers..");
clear(); //clear();
done(); //done();
} }
} }
...@@ -47,10 +47,12 @@ function clear() ...@@ -47,10 +47,12 @@ function clear()
} }
for(var i = 0; i < keys.length; i++){ for(var i = 0; i < keys.length; i++){
var localPeer = myPeerList.get(keys[i]); var localPeer = myPeerList.get(keys[i]);
if(localPeer.get("verified") !== 3){
localPeer.set("verified", 0); localPeer.set("verified", 0);
myPeerList.set(keys[i], localPeer); myPeerList.set(keys[i], localPeer);
} }
} }
}
} }
// next we get all the current peers sequentially // next we get all the current peers sequentially
...@@ -64,18 +66,19 @@ function append(_peerName, _peerID, _peerLocalIPv4, _peerPublicIPv4) ...@@ -64,18 +66,19 @@ function append(_peerName, _peerID, _peerLocalIPv4, _peerPublicIPv4)
localPeer.get("peerLocalIPv4") !== _peerLocalIPv4 || localPeer.get("peerLocalIPv4") !== _peerLocalIPv4 ||
localPeer.get("peerPublicIPv4") !== _peerPublicIPv4){ localPeer.get("peerPublicIPv4") !== _peerPublicIPv4){
// something changed. // something changed.
dpost("update peer ("+_peerName+")");
localPeer.set("peerName", _peerName); localPeer.set("peerName", _peerName);
localPeer.set("peerLocalIPv4", _peerLocalIPv4); localPeer.set("peerLocalIPv4", _peerLocalIPv4);
localPeer.set("peerPublicIPv4", _peerPublicIPv4); localPeer.set("peerPublicIPv4", _peerPublicIPv4);
localPeer.set("verified", 2); // this indicates a changed peer localPeer.set("verified", 2); // this indicates a changed peer
} else {
// verify the remote peer
localPeer.set("verified", 1); // this indicates an existing peer
} }
myPeerList.set(_peerID, localPeer); myPeerList.set(_peerID, localPeer);
} }
// since in the last step a peer might have been removed because of a change we test again // since in the last step a peer might have been removed because of a change we test again
if(!myPeerList.contains(_peerID)){ if(!myPeerList.contains(_peerID)){
dpost("append peer ("+_peerName+")");
var localPeer = new Dict(); var localPeer = new Dict();
localPeer.set("peerName", _peerName); localPeer.set("peerName", _peerName);
localPeer.set("peerLocalIPv4", _peerLocalIPv4); localPeer.set("peerLocalIPv4", _peerLocalIPv4);
...@@ -88,19 +91,21 @@ function append(_peerName, _peerID, _peerLocalIPv4, _peerPublicIPv4) ...@@ -88,19 +91,21 @@ function append(_peerName, _peerID, _peerLocalIPv4, _peerPublicIPv4)
// once we got all the peer info, we can create, rearrange, cleanup // once we got all the peer info, we can create, rearrange, cleanup
function done() function done()
{ {
dpost("updating remote peer list...");
// first remove all the peers not verified // first remove all the peers not verified
var keys = myPeerList.getkeys(); var keys = myPeerList.getkeys();
if(keys != null){ if(keys != null){
if(typeof(keys) == 'string'){ if(typeof(keys) == 'string'){
keys = [keys]; keys = [keys];
} }
dpost("remote peers found:" + keys);
for(var i = 0; i < keys.length; i++){ for(var i = 0; i < keys.length; i++){
var localPeer = myPeerList.get(keys[i]); var localPeer = myPeerList.get(keys[i]);
if(localPeer.get("verified") === 0){ if(localPeer.get("verified") === 0){
dpost("remove remote peer: " + localPeer.get("peerName")); dpost("... remove remote peer: " + localPeer.get("peerName"));
// this peer has gone // this peer has gone
removePeer(keys[i]); removePeer(keys[i]);
return; // peer is beeing removed and sends a 'done' message
} }
} }
} }
...@@ -113,9 +118,11 @@ function done() ...@@ -113,9 +118,11 @@ function done()
for(var i = 0; i < keys.length; i++){ for(var i = 0; i < keys.length; i++){
var localPeer = myPeerList.get(keys[i]); var localPeer = myPeerList.get(keys[i]);
if(localPeer.get("verified") === 3){ if(localPeer.get("verified") === 3){
dpost("add remote peer: " + localPeer.get("peerName")); dpost("... add remote peer: " + localPeer.get("peerName"));
slots.push(keys[i]);
createPeer(keys[i]); createPeer(keys[i]);
localPeer.set("verified", 1); // this indicates an existing peer
myPeerList.set(keys[i], localPeer);
return; // peer is beeing removed and sends a 'done' message
} }
} }
} }
...@@ -124,19 +131,25 @@ function done() ...@@ -124,19 +131,25 @@ function done()
slots.forEach(update); slots.forEach(update);
} }
function createPeer(_peerID){
this.patcher.remove(this.patcher.getnamed(_peerID));
this.patcher.message(makeCreationMessage(_peerID));
}
function update(_peerID, _index) { function update(_peerID, _index) {
var localPeer = myPeerList.get(_peerID); var localPeer = myPeerList.get(_peerID);
if(localPeer.get("verified") === 2){
messnamed("pl_" + _peerID, "peerName", localPeer.get("peerName")); messnamed("pl_" + _peerID, "peerName", localPeer.get("peerName"));
messnamed("pl_" + _peerID, "peerLocalIPv4", localPeer.get("peerLocalIPv4")); messnamed("pl_" + _peerID, "peerLocalIP", localPeer.get("peerLocalIPv4"));
messnamed("pl_" + _peerID, "peerPublicIPv4", localPeer.get("peerPublicIPv4")); messnamed("pl_" + _peerID, "peerPublicIP", localPeer.get("peerPublicIPv4"));
messnamed("pl_" + _peerID, "roomName", myRoomName); messnamed("pl_" + _peerID, "roomName", myRoomName);
messnamed("pl_" + _peerID, "roomID", myRoomID); messnamed("pl_" + _peerID, "roomID", myRoomID);
messnamed("pl_" + _peerID, "slot", _index); messnamed("pl_" + _peerID, "slot", _index);
localPeer.set("verified", 1); // this indicates an verified peer
myPeerList.set(_peerID, localPeer);
}
}
function createPeer(_peerID){
slots.push(_peerID);
this.patcher.remove(this.patcher.getnamed(_peerID));
this.patcher.message(makeCreationMessage(_peerID));
} }
function makeCreationMessage(_peerID){ function makeCreationMessage(_peerID){
...@@ -158,13 +171,13 @@ function makeCreationMessage(_peerID){ ...@@ -158,13 +171,13 @@ function makeCreationMessage(_peerID){
msp.push(1); msp.push(1);
msp.push("@args"); msp.push("@args");
msp.push("remote"); msp.push("remote");
msp.push(slotIndex);
msp.push(_peerID); msp.push(_peerID);
msp.push(localPeer.get("peerName")); msp.push(localPeer.get("peerName"));
msp.push(localPeer.get("peerLocalIPv4")); msp.push(localPeer.get("peerLocalIPv4"));
msp.push(localPeer.get("peerPublicIPv4")); msp.push(localPeer.get("peerPublicIPv4"));
msp.push(myRoomName); msp.push(myRoomName);
msp.push(myRoomID); msp.push(myRoomID);
msp.push(slotIndex);
//dpost("makeCreationMessage() " + msp + "\n"); //dpost("makeCreationMessage() " + msp + "\n");
return msp; return msp;
} }
......
...@@ -10,44 +10,96 @@ var mySlotSize = 45; ...@@ -10,44 +10,96 @@ var mySlotSize = 45;
var myPeerName = null; var myPeerName = null;
var myPeerID = null; var myPeerID = null;
var myRoomName = null;
var myRoomID = null;
var myPeerPublicIP = null;
var myPeerLocalIP = null;
var mySlotIndex = -1; var mySlotIndex = -1;
var taskMover = null; var taskMover = null;
function dpost(_post){
post("peer("+myPeerName+"): " + _post + "\n");
}
function done(){ function done(){
init(); init();
} }
/**********************
Init Functions
**********************/
function init(){ function init(){
// myNodeVarName = getKeyValuefromDB(myNodeName, "_conn.id"); // myNodeVarName = getKeyValuefromDB(myNodeName, "_conn.id");
post("init peer..("+myPeerName+") \n"); if(myPeerName !== null){
initNodeSpace(); initNodeSpace();
post("...init("+myPeerName+") done\n"); }
}
/* recursively gets the the parents patcher information
*/
function initNodeSpace(){
if(this.patcher.box.patcher.box != null){
myUberPatcher = this.patcher.box.patcher.box.patcher;
}
} }
/**********************
Init Functions
**********************/
function peerName(_peerName){ function peerName(_peerName){
if(myPeerName !== _peerName){
myPeerName = _peerName; myPeerName = _peerName;
outlet(0, "peerName", myPeerName);
}
} }
function peerID(_peerID){ function peerID(_peerID){
if(myPeerID !== _peerID){
myPeerID = _peerID; myPeerID = _peerID;
outlet(0, "peerID", myPeerID);
}
}
function peerLocalIP(_peerLocalIP){
if(myPeerLocalIP !== _peerLocalIP){
myPeerLocalIP = _peerLocalIP;
outlet(0, "peerLocalIPv4", myPeerLocalIP);
}
}
function peerPublicIP(_peerPublicIP){
if(myPeerPublicIP !== _peerPublicIP){
myPeerPublicIP = _peerPublicIP;
outlet(0, "peerPublicIP", myPeerPublicIP);
}
}
function roomName(_roomName){
if(myRoomName !== _roomName){
myRoomName = _roomName;
outlet(0, "roomName", myRoomName);
}
}
function roomID(_roomID){
if(myRoomID !== _roomID){
myRoomID = _roomID;
outlet(0, "roomID", myRoomID);
}
} }
function slot(_index){ function slot(_index){
if(mySlotIndex == -1){ if(mySlotIndex == -1){
mySlotIndex = _index; mySlotIndex = _index;
post("..start creation animation..("+myPeerName+") \n"); dpost("start creation animation...");
// start creation animation // start creation animation
taskMover = new Task(creaMover, this, 720, 0, 20); taskMover = new Task(creaMover, this, 720, 0, 20);
taskMover.interval = 33; // 60fps taskMover.interval = 33; // 60fps
taskMover.repeat(21); taskMover.repeat(21);
} }
if(mySlotIndex != _index){ if(mySlotIndex != _index){
post("..start reshuffle animation..("+myPeerName+") \n"); dpost("start reshuffle animation...");
// start reshuflle animation // start reshuflle animation
taskMover = new Task(shuffleMover, this, mySlotIndex, _index, 20); taskMover = new Task(shuffleMover, this, mySlotIndex, _index, 20);
taskMover.interval = 33; // 60fps taskMover.interval = 33; // 60fps
...@@ -57,12 +109,12 @@ function slot(_index){ ...@@ -57,12 +109,12 @@ function slot(_index){
} }
function remove(){ function remove(){
post("..start remove animation..("+myPeerName+") \n"); dpost("start remove animation... \n");
// remove abstraction // remove abstraction
outlet(0, "peerJoined", 0);
taskMover = new Task(reMover, this, 0, 720, 20); taskMover = new Task(reMover, this, 0, 720, 20);
taskMover.interval = 33; // 60fps taskMover.interval = 33; // 60fps
taskMover.repeat(21); taskMover.repeat(21);
outlet(0, "peerJoined", 0);
} }
function shuffleMover(_indxStart, _indxTarget, _maxStep) function shuffleMover(_indxStart, _indxTarget, _maxStep)
...@@ -72,6 +124,8 @@ function shuffleMover(_indxStart, _indxTarget, _maxStep) ...@@ -72,6 +124,8 @@ function shuffleMover(_indxStart, _indxTarget, _maxStep)
myUberPatcher.message("script", "sendbox", myPeerID, "presentation_position", 0, (_indxStart + (_indxTarget - _indxStart)/_maxStep * iter) * mySlotSize); myUberPatcher.message("script", "sendbox", myPeerID, "presentation_position", 0, (_indxStart + (_indxTarget - _indxStart)/_maxStep * iter) * mySlotSize);
} else { } else {
arguments.callee.task.cancel(); arguments.callee.task.cancel();
dpost("... reshuffle animation done.");
messnamed("peerManager", "done");
} }
} }
...@@ -82,6 +136,9 @@ function creaMover(_indxStart, _indxTarget, _maxStep) ...@@ -82,6 +136,9 @@ function creaMover(_indxStart, _indxTarget, _maxStep)
myUberPatcher.message("script", "sendbox", myPeerID, "presentation_position", _indxStart + (_indxTarget - _indxStart)/_maxStep * iter, mySlotIndex * mySlotSize); myUberPatcher.message("script", "sendbox", myPeerID, "presentation_position", _indxStart + (_indxTarget - _indxStart)/_maxStep * iter, mySlotIndex * mySlotSize);
} else { } else {
arguments.callee.task.cancel(); arguments.callee.task.cancel();
dpost("... creation animation done.");
outlet(0, "peerJoined", 1);
messnamed("peerManager", "done");
} }
} }
...@@ -92,18 +149,12 @@ function reMover(_indxStart, _indxTarget, _maxStep) ...@@ -92,18 +149,12 @@ function reMover(_indxStart, _indxTarget, _maxStep)
myUberPatcher.message("script", "sendbox", myPeerID, "presentation_position", _indxStart + (_indxTarget - _indxStart)/_maxStep * iter, mySlotIndex * mySlotSize); myUberPatcher.message("script", "sendbox", myPeerID, "presentation_position", _indxStart + (_indxTarget - _indxStart)/_maxStep * iter, mySlotIndex * mySlotSize);
} else { } else {
arguments.callee.task.cancel(); arguments.callee.task.cancel();
dpost("... remove animation done.");
messnamed("peerManager", "done");
myUberPatcher.remove(myUberPatcher.getnamed(myPeerID)); myUberPatcher.remove(myUberPatcher.getnamed(myPeerID));
} }
} }
/* recursively gets the the parents patcher information
*/
function initNodeSpace(){
if(this.patcher.box.patcher.box != null){
myUberPatcher = this.patcher.box.patcher.box.patcher;
}
}
function anything(){ function anything(){
// ignore everything else // ignore everything else
} }
\ No newline at end of file
...@@ -129,10 +129,17 @@ const handlers = { ...@@ -129,10 +129,17 @@ const handlers = {
if(proxyHost !== null && proxyRoom !== null){ if(proxyHost !== null && proxyRoom !== null){
console.log('Atempting to restart proxy: ' + _port + ' at ' + proxyHost + ' in ' + proxyRoom); console.log('Atempting to restart proxy: ' + _port + ' at ' + proxyHost + ' in ' + proxyRoom);
try { try {
console.log('... stopping proxy....');
const resDel = await superagent.delete('http://'+proxyHost+':3591/proxies/' + _port); const resDel = await superagent.delete('http://'+proxyHost+':3591/proxies/' + _port);
let reply = JSON.parse(resDel["text"]); let reply = JSON.parse(resDel["text"]);
console.log(reply["msg"]); console.log(reply["msg"]);
} catch (err) {
let reply = JSON.parse(err.response["text"]);
console.error(reply["msg"]);
}
try {
console.log('... starting proxy....');
// current date // current date
let date = new Date(); let date = new Date();
......
This diff is collapsed.
...@@ -3,14 +3,14 @@ ...@@ -3,14 +3,14 @@
"fileversion" : 1, "fileversion" : 1,
"appversion" : { "appversion" : {
"major" : 8, "major" : 8,
"minor" : 1, "minor" : 2,
"revision" : 10, "revision" : 0,
"architecture" : "x64", "architecture" : "x64",
"modernui" : 1 "modernui" : 1
} }
, ,
"classnamespace" : "box", "classnamespace" : "box",
"rect" : [ 925.0, 259.0, 995.0, 471.0 ], "rect" : [ 398.0, 389.0, 995.0, 471.0 ],
"bglocked" : 0, "bglocked" : 0,
"openinpresentation" : 1, "openinpresentation" : 1,
"default_fontsize" : 12.0, "default_fontsize" : 12.0,
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
"box" : { "box" : {
"comment" : "", "comment" : "",
"id" : "obj-4", "id" : "obj-4",
"index" : 1, "index" : 0,
"maxclass" : "inlet", "maxclass" : "inlet",
"numinlets" : 0, "numinlets" : 0,
"numoutlets" : 1, "numoutlets" : 1,
...@@ -89,14 +89,14 @@ ...@@ -89,14 +89,14 @@
"fileversion" : 1, "fileversion" : 1,
"appversion" : { "appversion" : {
"major" : 8, "major" : 8,
"minor" : 1, "minor" : 2,
"revision" : 10, "revision" : 0,
"architecture" : "x64", "architecture" : "x64",
"modernui" : 1 "modernui" : 1
} }
, ,
"classnamespace" : "box", "classnamespace" : "box",
"rect" : [ 875.0, 347.0, 640.0, 480.0 ], "rect" : [ 810.0, 232.0, 451.0, 404.0 ],
"bglocked" : 0, "bglocked" : 0,
"openinpresentation" : 0, "openinpresentation" : 0,
"default_fontsize" : 12.0, "default_fontsize" : 12.0,
...@@ -125,13 +125,49 @@ ...@@ -125,13 +125,49 @@
"subpatcher_template" : "", "subpatcher_template" : "",
"assistshowspatchername" : 0, "assistshowspatchername" : 0,
"boxes" : [ { "boxes" : [ {
"box" : {
"id" : "obj-4",
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 81.0, 183.0, 35.0, 22.0 ],
"text" : "done"
}
}
, {
"box" : {
"id" : "obj-2",
"maxclass" : "newobj",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "bang" ],
"patching_rect" : [ 81.0, 146.0, 61.0, 22.0 ],
"text" : "delay 100"
}
}
, {
"box" : {
"id" : "obj-5",
"maxclass" : "newobj",
"numinlets" : 0,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 302.0, 259.0, 87.0, 22.0 ],
"text" : "r peerManager"
}
}
, {
"box" : { "box" : {
"id" : "obj-13", "id" : "obj-13",
"maxclass" : "newobj", "maxclass" : "newobj",
"numinlets" : 1, "numinlets" : 1,
"numoutlets" : 1, "numoutlets" : 1,
"outlettype" : [ "" ], "outlettype" : [ "" ],
"patching_rect" : [ 245.0, 358.0, 95.0, 22.0 ], "patching_rect" : [ 189.0, 160.0, 95.0, 22.0 ],
"text" : "prepend roomID" "text" : "prepend roomID"
} }
...@@ -143,7 +179,7 @@ ...@@ -143,7 +179,7 @@
"numinlets" : 1, "numinlets" : 1,
"numoutlets" : 1, "numoutlets" : 1,
"outlettype" : [ "" ], "outlettype" : [ "" ],
"patching_rect" : [ 213.5, 385.0, 115.0, 22.0 ], "patching_rect" : [ 157.5, 187.0, 115.0, 22.0 ],
"text" : "prepend roomName" "text" : "prepend roomName"
} }
...@@ -155,7 +191,7 @@ ...@@ -155,7 +191,7 @@
"numinlets" : 3, "numinlets" : 3,
"numoutlets" : 3, "numoutlets" : 3,
"outlettype" : [ "", "", "" ], "outlettype" : [ "", "", "" ],
"patching_rect" : [ 213.5, 330.0, 82.0, 22.0 ], "patching_rect" : [ 157.5, 132.0, 82.0, 22.0 ],
"text" : "route name id" "text" : "route name id"
} }
...@@ -167,7 +203,7 @@ ...@@ -167,7 +203,7 @@
"numinlets" : 2, "numinlets" : 2,
"numoutlets" : 2, "numoutlets" : 2,
"outlettype" : [ "", "" ], "outlettype" : [ "", "" ],
"patching_rect" : [ 213.5, 303.0, 67.0, 22.0 ], "patching_rect" : [ 157.5, 105.0, 67.0, 22.0 ],
"text" : "route room" "text" : "route room"
} }
...@@ -176,11 +212,11 @@ ...@@ -176,11 +212,11 @@
"box" : { "box" : {
"id" : "obj-9", "id" : "obj-9",
"maxclass" : "newobj", "maxclass" : "newobj",
"numinlets" : 2, "numinlets" : 3,
"numoutlets" : 2, "numoutlets" : 3,
"outlettype" : [ "", "" ], "outlettype" : [ "", "", "" ],
"patching_rect" : [ 134.0, 303.0, 69.0, 22.0 ], "patching_rect" : [ 41.0, 105.0, 99.0, 22.0 ],
"text" : "route menu" "text" : "route menu done"
} }
} }
...@@ -191,7 +227,7 @@ ...@@ -191,7 +227,7 @@
"numinlets" : 3,