vendor/opentok.js
function measureUploadBandwidth(url, payload) {
      var xhr = new XMLHttpRequest(),
        resultPromise = new OT.$.RSVP.Promise(function(resolve, reject) {

          var startTs,
            lastTs,
            lastLoaded;
          xhr.upload.addEventListener('progress', function(evt) {
            if (!startTs) {
              startTs = Date.now();
            }
            lastLoaded = evt.loaded;
          });
          xhr.addEventListener('load', function() {
            lastTs = Date.now();
            resolve(1000 * 8 * lastLoaded / (lastTs - startTs));
          });
          xhr.addEventListener('error', function(e) {
            reject(e);
          });
          xhr.addEventListener('abort', function() {
            reject();
          });
          xhr.open('POST', url);
          xhr.send(payload);
        });

      return {
        promise: resultPromise,
        abort: function() {
          xhr.abort();
        }
      };
    }
function measureUploadBandwidth(url, payload) {
      var xhr = new XMLHttpRequest(),
        resultPromise = new OT.$.RSVP.Promise(function(resolve, reject) {

          var startTs,
            lastTs,
            lastLoaded;
          xhr.upload.addEventListener('progress', function(evt) {
            if (!startTs) {
              startTs = Date.now();
            }
            lastLoaded = evt.loaded;
          });
          xhr.addEventListener('load', function() {
            lastTs = Date.now();
            resolve(1000 * 8 * lastLoaded / (lastTs - startTs));
          });
          xhr.addEventListener('error', function(e) {
            reject(e);
          });
          xhr.addEventListener('abort', function() {
            reject();
          });
          xhr.open('POST', url);
          xhr.send(payload);
        });

      return {
        promise: resultPromise,
        abort: function() {
          xhr.abort();
        }
      };
    }
function measureUploadBandwidth ( url , payload ) { var xhr = new XMLHttpRequest ( ) , resultPromise = new OT . $ . RSVP . Promise ( function ( resolve , reject ) { var startTs , lastTs , lastLoaded ; xhr . upload . addEventListener ( 'progress' , function ( evt ) { if ( ! startTs ) { startTs = Date . now ( ) ; } lastLoaded = evt . loaded ; } ) ; xhr . addEventListener ( 'load' , function ( ) { lastTs = Date . now ( ) ; resolve ( 1000 * 8 * lastLoaded / ( lastTs - startTs ) ) ; } ) ; xhr . addEventListener ( 'error' , function ( e ) { reject ( e ) ; } ) ; xhr . addEventListener ( 'abort' , function ( ) { reject ( ) ; } ) ; xhr . open ( 'POST' , url ) ; xhr . send ( payload ) ; } ) ; return { promise : resultPromise , abort : function ( ) { xhr . abort ( ) ; } } ; }
Measures the bandwidth in bps.

@param {string} url
@param {ArrayBuffer} payload
@returns {{promise: Promise, abort: function}}
Measures the bandwidth in bps .