client/webrtc.js
/** test and average time took to download image from server, called recursively timesToTest times */
test and average time took to download image from server, called recursively timesToTest times
test and average time took to download image from server called recursively timesToTest times
function testLatency(cb) {
    var tStart = new Date().getTime();
    if (i<timesToTest-1) {
      dummyImage.src = testImage + '?t=' + tStart;
      dummyImage.onload = function() {
        var tEnd = new Date().getTime();
        var tTimeTook = tEnd-tStart;
        arrTimes[i] = tTimeTook;
        testLatency(cb);
        i++;
      };
    } else {
      var sum = arrTimes.reduce(function(a, b) { return a + b; });
      var avg = sum / arrTimes.length;
      cb(avg);
    }
  }
function testLatency ( cb ) { var tStart = new Date ( ) . getTime ( ) ; if ( i < timesToTest - 1 ) { dummyImage . src = testImage + '?t=' + tStart ; dummyImage . onload = function ( ) { var tEnd = new Date ( ) . getTime ( ) ; var tTimeTook = tEnd - tStart ; arrTimes [ i ] = tTimeTook ; testLatency ( cb ) ; i ++ ; } ; } else { var sum = arrTimes . reduce ( function ( a , b ) { return a + b ; } ) ; var avg = sum / arrTimes . length ; cb ( avg ) ; } }
test and average time took to download image from server, called recursively timesToTest times
test and average time took to download image from server called recursively timesToTest times
/** calculate average of array items then callback */