diff nodescore.js @ 23:e1a02869da08

reduced to one score file with menu to choose which part stream to receive added latency results to client and tweeked some css
author tzara <rc-web@kiben.net>
date Wed, 11 Jul 2012 14:17:43 +0100
parents bb02a593b7d5
children 22f1c38007ff
line wrap: on
line diff
--- a/nodescore.js	Wed Jul 11 09:51:05 2012 +0100
+++ b/nodescore.js	Wed Jul 11 14:17:43 2012 +0100
@@ -103,30 +103,58 @@
     socket.on('startChr', function () { startChr();});
     socket.on('stopChr', function () { stopChr();});
     socket.on('resetChr', function () { resetChr();});
-     
-    ////////////////////////////////////////////
-    // 
-    ///////////////////////////////////////////
-
-
 
     ////////////////////////////////////////////  
     // some latency calculations
     ///////////////////////////////////////////
 
+    /*
+      a ping is periodically broadcast to all connected clients each
+      connected returns a pong to the server via an "emit" and in turn
+      the server returns each unique client a report of the latency
+      via another emit - the emit only sends to the source of the
+      request, whereas the broadcast.emit..  broadcasts.. ie to all
+      connected clients
+
+      TODO: smooth range and average out results to remove erratic ping
+      times.
+
+      TODO:
+      The result then needs to be used to stagger outgoing messages to
+      compensate for latency - how much compensation is more connected
+      to the time that any audio/video feed needs to encode/decode as
+      the latency of the route from node A to node B is inavoidable?!
+      so maybe latency is irrelevant in this context - we just need to
+      stagger signals according to encoding decoding times.. hmmm
+    */
+    
+
+
+// periodically broadcast  a ping
+
     function serverTime(freq) {
 	//	clearInterval();
 	st=setInterval(function() {
 	    var d = new Date(); var n = d.getTime(); 
 	    socket.emit("timeFromServer", n); 
+	    socket.broadcast.emit("timeFromServer", n); 
+
 	}, freq);   
     }
+
+    // recieve the pong calculate the latency and
+    // return the response to the client
+
     socket.on("clientTimeResponse", function(x) {
 	var d = new Date(); var n = d.getTime();
 	var latency = (n-x)/2;
 	//console.log("SERVERTIME:"+x + " LATENCY:" + latency);
 	socket.emit("latencyFromServer", latency);
+
     });	      
+
+    // this is the trigger from the control client to start the process
+    // maybe remove this and have latency connections constantly running
     
     socket.on("getLatencies", function(x){
 	serverTime(x);
@@ -213,13 +241,12 @@
 	}, tempoms)
 
 
-	socket.on('stopSeq', function (seq) { 
-	    console.log("stop")
-	    clearInterval(tock);	    
-	    sequencerState=0;  
-	    stopChr();
-	});
-
+//	socket.on('stopSeq', function (seq) { 
+//	    console.log("stop")
+//	    clearInterval(tock);	    
+//	    sequencerState=0;  
+//	    stopChr();
+//	});
 			  };
     
     step = function (seq) {