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()
function joined(_joined){
if(_joined == 0){
dpost("local peer left room. cleaning up list of remote peers..");
clear();
done();
//clear();
//done();
}
}
......@@ -47,8 +47,10 @@ function clear()
}
for(var i = 0; i < keys.length; i++){
var localPeer = myPeerList.get(keys[i]);
localPeer.set("verified", 0);
myPeerList.set(keys[i], localPeer);
if(localPeer.get("verified") !== 3){
localPeer.set("verified", 0);
myPeerList.set(keys[i], localPeer);
}
}
}
}
......@@ -56,26 +58,27 @@ function clear()
// next we get all the current peers sequentially
function append(_peerName, _peerID, _peerLocalIPv4, _peerPublicIPv4)
{
// first test if the peerID is already existing
// first test if the peerID is already existing
if(myPeerList.contains(_peerID)){
// we make a sanity check if nothing has changed
// we make a sanity check if nothing has changed
var localPeer = myPeerList.get(_peerID);
if(localPeer.get("peerName") !== _peerName ||
localPeer.get("peerLocalIPv4") !== _peerLocalIPv4 ||
localPeer.get("peerPublicIPv4") !== _peerPublicIPv4){
// something changed.
localPeer.set("peerName", _peerName);
dpost("update peer ("+_peerName+")");
localPeer.set("peerName", _peerName);
localPeer.set("peerLocalIPv4", _peerLocalIPv4);
localPeer.set("peerPublicIPv4", _peerPublicIPv4);
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);
}
// since in the last step a peer might have been removed because of a change we test again
if(!myPeerList.contains(_peerID)){
dpost("append peer ("+_peerName+")");
var localPeer = new Dict();
localPeer.set("peerName", _peerName);
localPeer.set("peerLocalIPv4", _peerLocalIPv4);
......@@ -88,19 +91,21 @@ function append(_peerName, _peerID, _peerLocalIPv4, _peerPublicIPv4)
// once we got all the peer info, we can create, rearrange, cleanup
function done()
{
dpost("updating remote peer list...");
// first remove all the peers not verified
var keys = myPeerList.getkeys();
if(keys != null){
if(typeof(keys) == 'string'){
keys = [keys];
}
dpost("remote peers found:" + keys);
for(var i = 0; i < keys.length; i++){
var localPeer = myPeerList.get(keys[i]);
if(localPeer.get("verified") === 0){
dpost("remove remote peer: " + localPeer.get("peerName"));
dpost("... remove remote peer: " + localPeer.get("peerName"));
// this peer has gone
removePeer(keys[i]);
return; // peer is beeing removed and sends a 'done' message
}
}
}
......@@ -113,9 +118,11 @@ function done()
for(var i = 0; i < keys.length; i++){
var localPeer = myPeerList.get(keys[i]);
if(localPeer.get("verified") === 3){
dpost("add remote peer: " + localPeer.get("peerName"));
slots.push(keys[i]);
dpost("... add remote peer: " + localPeer.get("peerName"));
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,21 +131,27 @@ function done()
slots.forEach(update);
}
function update(_peerID, _index) {
var localPeer = myPeerList.get(_peerID);
if(localPeer.get("verified") === 2){
messnamed("pl_" + _peerID, "peerName", localPeer.get("peerName"));
messnamed("pl_" + _peerID, "peerLocalIP", localPeer.get("peerLocalIPv4"));
messnamed("pl_" + _peerID, "peerPublicIP", localPeer.get("peerPublicIPv4"));
messnamed("pl_" + _peerID, "roomName", myRoomName);
messnamed("pl_" + _peerID, "roomID", myRoomID);
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 update(_peerID, _index) {
var localPeer = myPeerList.get(_peerID);
messnamed("pl_" + _peerID, "peerName", localPeer.get("peerName"));
messnamed("pl_" + _peerID, "peerLocalIPv4", localPeer.get("peerLocalIPv4"));
messnamed("pl_" + _peerID, "peerPublicIPv4", localPeer.get("peerPublicIPv4"));
messnamed("pl_" + _peerID, "roomName", myRoomName);
messnamed("pl_" + _peerID, "roomID", myRoomID);
messnamed("pl_" + _peerID, "slot", _index);
}
function makeCreationMessage(_peerID){
var localPeer = myPeerList.get(_peerID);
var slotIndex = slots.indexOf(_peerID)
......@@ -158,13 +171,13 @@ function makeCreationMessage(_peerID){
msp.push(1);
msp.push("@args");
msp.push("remote");
msp.push(slotIndex);
msp.push(_peerID);
msp.push(localPeer.get("peerName"));
msp.push(localPeer.get("peerLocalIPv4"));
msp.push(localPeer.get("peerPublicIPv4"));
msp.push(myRoomName);
msp.push(myRoomID);
msp.push(slotIndex);
//dpost("makeCreationMessage() " + msp + "\n");
return msp;
}
......
......@@ -10,44 +10,96 @@ var mySlotSize = 45;
var myPeerName = null;
var myPeerID = null;
var myRoomName = null;
var myRoomID = null;
var myPeerPublicIP = null;
var myPeerLocalIP = null;
var mySlotIndex = -1;
var taskMover = null;
function dpost(_post){
post("peer("+myPeerName+"): " + _post + "\n");
}
function done(){
init();
}
/**********************
Init Functions
**********************/
function init(){
// myNodeVarName = getKeyValuefromDB(myNodeName, "_conn.id");
post("init peer..("+myPeerName+") \n");
initNodeSpace();
post("...init("+myPeerName+") done\n");
if(myPeerName !== null){
initNodeSpace();
}
}
/* 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){
myPeerName = _peerName;
if(myPeerName !== _peerName){
myPeerName = _peerName;
outlet(0, "peerName", myPeerName);
}
}
function peerID(_peerID){
myPeerID = _peerID;
if(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){
if(mySlotIndex == -1){
mySlotIndex = _index;
post("..start creation animation..("+myPeerName+") \n");
dpost("start creation animation...");
// start creation animation
taskMover = new Task(creaMover, this, 720, 0, 20);
taskMover.interval = 33; // 60fps
taskMover.repeat(21);
}
if(mySlotIndex != _index){
post("..start reshuffle animation..("+myPeerName+") \n");
dpost("start reshuffle animation...");
// start reshuflle animation
taskMover = new Task(shuffleMover, this, mySlotIndex, _index, 20);
taskMover.interval = 33; // 60fps
......@@ -57,12 +109,12 @@ function slot(_index){
}
function remove(){
post("..start remove animation..("+myPeerName+") \n");
dpost("start remove animation... \n");
// remove abstraction
outlet(0, "peerJoined", 0);
taskMover = new Task(reMover, this, 0, 720, 20);
taskMover.interval = 33; // 60fps
taskMover.repeat(21);
outlet(0, "peerJoined", 0);
}
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);
} else {
arguments.callee.task.cancel();
dpost("... reshuffle animation done.");
messnamed("peerManager", "done");
}
}
......@@ -82,6 +136,9 @@ function creaMover(_indxStart, _indxTarget, _maxStep)
myUberPatcher.message("script", "sendbox", myPeerID, "presentation_position", _indxStart + (_indxTarget - _indxStart)/_maxStep * iter, mySlotIndex * mySlotSize);
} else {
arguments.callee.task.cancel();
dpost("... creation animation done.");
outlet(0, "peerJoined", 1);
messnamed("peerManager", "done");
}
}
......@@ -92,18 +149,12 @@ function reMover(_indxStart, _indxTarget, _maxStep)
myUberPatcher.message("script", "sendbox", myPeerID, "presentation_position", _indxStart + (_indxTarget - _indxStart)/_maxStep * iter, mySlotIndex * mySlotSize);
} else {
arguments.callee.task.cancel();
dpost("... remove animation done.");
messnamed("peerManager", "done");
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(){
// ignore everything else
}
\ No newline at end of file
......@@ -129,10 +129,17 @@ const handlers = {
if(proxyHost !== null && proxyRoom !== null){
console.log('Atempting to restart proxy: ' + _port + ' at ' + proxyHost + ' in ' + proxyRoom);
try {
console.log('... stopping proxy....');
const resDel = await superagent.delete('http://'+proxyHost+':3591/proxies/' + _port);
let reply = JSON.parse(resDel["text"]);
console.log(reply["msg"]);
} catch (err) {
let reply = JSON.parse(err.response["text"]);
console.error(reply["msg"]);
}
try {
console.log('... starting proxy....');
// current date
let date = new Date();
......
This diff is collapsed.
......@@ -3,14 +3,14 @@
"fileversion" : 1,
"appversion" : {
"major" : 8,
"minor" : 1,
"revision" : 10,
"minor" : 2,
"revision" : 0,
"architecture" : "x64",
"modernui" : 1
}
,
"classnamespace" : "box",
"rect" : [ 925.0, 259.0, 995.0, 471.0 ],
"rect" : [ 398.0, 389.0, 995.0, 471.0 ],
"bglocked" : 0,
"openinpresentation" : 1,
"default_fontsize" : 12.0,
......@@ -69,7 +69,7 @@
"box" : {
"comment" : "",
"id" : "obj-4",
"index" : 1,
"index" : 0,
"maxclass" : "inlet",
"numinlets" : 0,
"numoutlets" : 1,
......@@ -89,14 +89,14 @@
"fileversion" : 1,
"appversion" : {
"major" : 8,
"minor" : 1,
"revision" : 10,
"minor" : 2,
"revision" : 0,
"architecture" : "x64",
"modernui" : 1
}
,
"classnamespace" : "box",
"rect" : [ 875.0, 347.0, 640.0, 480.0 ],
"rect" : [ 810.0, 232.0, 451.0, 404.0 ],
"bglocked" : 0,
"openinpresentation" : 0,
"default_fontsize" : 12.0,
......@@ -125,13 +125,49 @@
"subpatcher_template" : "",
"assistshowspatchername" : 0,
"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" : {
"id" : "obj-13",
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 245.0, 358.0, 95.0, 22.0 ],
"patching_rect" : [ 189.0, 160.0, 95.0, 22.0 ],
"text" : "prepend roomID"
}
......@@ -143,7 +179,7 @@
"numinlets" : 1,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 213.5, 385.0, 115.0, 22.0 ],
"patching_rect" : [ 157.5, 187.0, 115.0, 22.0 ],
"text" : "prepend roomName"
}
......@@ -155,7 +191,7 @@
"numinlets" : 3,
"numoutlets" : 3,
"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"
}
......@@ -167,7 +203,7 @@
"numinlets" : 2,
"numoutlets" : 2,
"outlettype" : [ "", "" ],
"patching_rect" : [ 213.5, 303.0, 67.0, 22.0 ],
"patching_rect" : [ 157.5, 105.0, 67.0, 22.0 ],
"text" : "route room"
}
......@@ -176,11 +212,11 @@
"box" : {
"id" : "obj-9",
"maxclass" : "newobj",
"numinlets" : 2,
"numoutlets" : 2,
"outlettype" : [ "", "" ],
"patching_rect" : [ 134.0, 303.0, 69.0, 22.0 ],
"text" : "route menu"
"numinlets" : 3,
"numoutlets" : 3,
"outlettype" : [ "", "", "" ],
"patching_rect" : [ 41.0, 105.0, 99.0, 22.0 ],
"text" : "route menu done"
}
}
......@@ -191,7 +227,7 @@
"numinlets" : 3,
"numoutlets" : 3,
"outlettype" : [ "", "", "" ],
"patching_rect" : [ 139.0, 272.0, 168.0, 22.0 ],
"patching_rect" : [ 41.0, 74.0, 168.0, 22.0 ],
"text" : "route peers peer"
}
......@@ -203,73 +239,10 @@
"numinlets" : 0,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 139.0, 237.0, 83.0, 22.0 ],
"patching_rect" : [ 41.0, 39.0, 83.0, 22.0 ],
"text" : "r iBusPeerList"
}
}
, {
"box" : {
"id" : "obj-4",
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 85.5, 84.0, 394.0, 22.0 ],
"text" : "clear, append cesar kjhwe7h2jwenw 192.168.1.4 234.123.242.231, done"
}
}
, {
"box" : {
"id" : "obj-2",
"linecount" : 2,
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 70.0, 47.0, 563.0, 35.0 ],
"text" : "clear, append maximilian iuhqwejnqwezg3 192.168.1.2 234.123.242.123, append cesar kjhwe7h2jwenw 192.168.1.4 234.123.242.231, done"
}
}
, {
"box" : {
"id" : "obj-7",
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 49.0, 115.0, 67.0, 22.0 ],
"text" : "clear, done"
}
}
, {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-33",
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 85.5, 151.0, 321.0, 22.0 ],
"text" : "script newobject newobj @text \"trigger b b b\" @fixwidth 1"
}
}
, {
"box" : {
"id" : "obj-3",
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 33.0, 21.0, 426.0, 22.0 ],
"text" : "clear, append maximilian iuhqwejnqwezg3 192.168.1.2 234.123.242.123, done"
}
}
, {
"box" : {
......@@ -279,7 +252,7 @@
"maxclass" : "outlet",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 41.0, 425.0, 30.0, 30.0 ]
"patching_rect" : [ 41.0, 330.0, 30.0, 30.0 ]
}
}
......@@ -328,7 +301,7 @@
}
, {
"patchline" : {
"destination" : [ "obj-1", 0 ],
"destination" : [ "obj-4", 0 ],
"source" : [ "obj-2", 0 ]
}
......@@ -336,14 +309,14 @@
, {
"patchline" : {
"destination" : [ "obj-1", 0 ],
"source" : [ "obj-3", 0 ]
"source" : [ "obj-4", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-1", 0 ],
"source" : [ "obj-4", 0 ]
"source" : [ "obj-5", 0 ]
}
}
......@@ -360,13 +333,6 @@
"source" : [ "obj-6", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-1", 0 ],
"source" : [ "obj-7", 0 ]
}
}
, {
"patchline" : {
......@@ -378,14 +344,14 @@
, {
"patchline" : {
"destination" : [ "obj-1", 0 ],
"source" : [ "obj-9", 1 ]
"source" : [ "obj-9", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-1", 0 ],
"source" : [ "obj-9", 0 ]
"destination" : [ "obj-2", 0 ],
"source" : [ "obj-9", 1 ]
}
}
......@@ -443,7 +409,16 @@
}
}
]
],
"dependency_cache" : [ {
"name" : "peerList.js",
"bootpath" : "~/Arbeiten/01_projekte/181111_IASpace/01_projekte/20xx_Telematik/01_dev/telemersive-gateway/code",
"patcherrelativepath" : "../../code",
"type" : "TEXT",
"implicit" : 1
}
],
"autosave" : 0
}
}