Mercurial > hg > nodescore
comparison 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 |
comparison
equal
deleted
inserted
replaced
22:bb02a593b7d5 | 23:e1a02869da08 |
---|---|
101 } | 101 } |
102 | 102 |
103 socket.on('startChr', function () { startChr();}); | 103 socket.on('startChr', function () { startChr();}); |
104 socket.on('stopChr', function () { stopChr();}); | 104 socket.on('stopChr', function () { stopChr();}); |
105 socket.on('resetChr', function () { resetChr();}); | 105 socket.on('resetChr', function () { resetChr();}); |
106 | |
107 //////////////////////////////////////////// | |
108 // | |
109 /////////////////////////////////////////// | |
110 | |
111 | |
112 | 106 |
113 //////////////////////////////////////////// | 107 //////////////////////////////////////////// |
114 // some latency calculations | 108 // some latency calculations |
115 /////////////////////////////////////////// | 109 /////////////////////////////////////////// |
110 | |
111 /* | |
112 a ping is periodically broadcast to all connected clients each | |
113 connected returns a pong to the server via an "emit" and in turn | |
114 the server returns each unique client a report of the latency | |
115 via another emit - the emit only sends to the source of the | |
116 request, whereas the broadcast.emit.. broadcasts.. ie to all | |
117 connected clients | |
118 | |
119 TODO: smooth range and average out results to remove erratic ping | |
120 times. | |
121 | |
122 TODO: | |
123 The result then needs to be used to stagger outgoing messages to | |
124 compensate for latency - how much compensation is more connected | |
125 to the time that any audio/video feed needs to encode/decode as | |
126 the latency of the route from node A to node B is inavoidable?! | |
127 so maybe latency is irrelevant in this context - we just need to | |
128 stagger signals according to encoding decoding times.. hmmm | |
129 */ | |
130 | |
131 | |
132 | |
133 // periodically broadcast a ping | |
116 | 134 |
117 function serverTime(freq) { | 135 function serverTime(freq) { |
118 // clearInterval(); | 136 // clearInterval(); |
119 st=setInterval(function() { | 137 st=setInterval(function() { |
120 var d = new Date(); var n = d.getTime(); | 138 var d = new Date(); var n = d.getTime(); |
121 socket.emit("timeFromServer", n); | 139 socket.emit("timeFromServer", n); |
140 socket.broadcast.emit("timeFromServer", n); | |
141 | |
122 }, freq); | 142 }, freq); |
123 } | 143 } |
144 | |
145 // recieve the pong calculate the latency and | |
146 // return the response to the client | |
147 | |
124 socket.on("clientTimeResponse", function(x) { | 148 socket.on("clientTimeResponse", function(x) { |
125 var d = new Date(); var n = d.getTime(); | 149 var d = new Date(); var n = d.getTime(); |
126 var latency = (n-x)/2; | 150 var latency = (n-x)/2; |
127 //console.log("SERVERTIME:"+x + " LATENCY:" + latency); | 151 //console.log("SERVERTIME:"+x + " LATENCY:" + latency); |
128 socket.emit("latencyFromServer", latency); | 152 socket.emit("latencyFromServer", latency); |
153 | |
129 }); | 154 }); |
155 | |
156 // this is the trigger from the control client to start the process | |
157 // maybe remove this and have latency connections constantly running | |
130 | 158 |
131 socket.on("getLatencies", function(x){ | 159 socket.on("getLatencies", function(x){ |
132 serverTime(x); | 160 serverTime(x); |
133 }); | 161 }); |
134 | 162 |
211 ztime -= 1000 | 239 ztime -= 1000 |
212 | 240 |
213 }, tempoms) | 241 }, tempoms) |
214 | 242 |
215 | 243 |
216 socket.on('stopSeq', function (seq) { | 244 // socket.on('stopSeq', function (seq) { |
217 console.log("stop") | 245 // console.log("stop") |
218 clearInterval(tock); | 246 // clearInterval(tock); |
219 sequencerState=0; | 247 // sequencerState=0; |
220 stopChr(); | 248 // stopChr(); |
221 }); | 249 // }); |
222 | |
223 }; | 250 }; |
224 | 251 |
225 step = function (seq) { | 252 step = function (seq) { |
226 clearInterval(countdowntick); | 253 clearInterval(countdowntick); |
227 countdowntick(seq) | 254 countdowntick(seq) |