Skip to content

Commit

Permalink
REMOVE opentok eslint dependency and add fixes for latest versions of…
Browse files Browse the repository at this point in the history
… eslint and airbnb style
  • Loading branch information
ggarber committed Jan 3, 2017
1 parent 648e497 commit e0e7de0
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 88 deletions.
15 changes: 12 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
{
"extends": "eslint-config-opentok",
{
"extends": "eslint-config-airbnb",
"rules": {
"no-eq-null": 0,
"vars-on-top": 0,
"no-console": 0,
"no-alert": 0,
"spaced-comment": 0,
"valid-jsdoc": 0,
"prefer-arrow-callback": 0,
"prefer-rest-params": 0,
"space-before-function-paren": 0,
"no-var": 0,
"strict": 0,
"func-names": 0,
"no-plusplus": 0,
"prefer-template": 0,
"object-shorthand": 0,

"no-use-before-define": 0,
"no-undef": 0,
"new-cap": 0,
"no-param-reassign": 0,
"consistent-this": 0,
Expand Down
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
},
"devDependencies": {
"chromedriver": "^2.16.0",
"eslint": "^1.10.3",
"eslint-config-opentok": "1.0.2",
"eslint-plugin-require-path-exists": "^1.0.15",
"eslint": "^3.12.2",
"eslint-config-airbnb": "^13.0.0",
"eslint-config-airbnb-base": "^11.0.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^2.2.3",
"eslint-plugin-react": "^6.8.0",
"eslint-plugin-require-path-exists": "^1.1.5",
"selenium-webdriver": "^2.48.0",
"tape": "^4.0.0",
"testling": "^1.7.1",
Expand All @@ -20,7 +24,7 @@
"webrtc-adapter-test": "^0.2.7"
},
"scripts": {
"test": "eslint rtcstats.js",
"test": "./node_modules/.bin/eslint rtcstats.js",
"dist": "uglifyjs -o min.js rtcstats.js",
"test-travis": "cp test/testpage.html node_modules/webrtc-adapter-test/ && test/run-tests"
},
Expand Down
165 changes: 84 additions & 81 deletions rtcstats.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';

(function() {
// transforms a maplike to an object. Mostly for getStats +
// JSON.parse(JSON.stringify())
Expand All @@ -13,6 +14,61 @@
return o;
}

// apply a delta compression to the stats report. Reduces size by ~90%.
// To reduce further, report keys could be compressed.
function deltaCompression(oldStats, newStats) {
newStats = JSON.parse(JSON.stringify(newStats));
Object.keys(newStats).forEach(function(id) {
if (!oldStats[id]) {
return;
}
var report = newStats[id];
Object.keys(report).forEach(function(name) {
if (report[name] === oldStats[id][name]) {
delete newStats[id][name];
}
delete report.timestamp;
if (Object.keys(report).length === 0) {
delete newStats[id];
}
});
});
// TODO: moving the timestamp to the top-level is not compression but...
newStats.timestamp = new Date();
return newStats;
}

function mangleChromeStats(pc, response) {
var standardReport = {};
var reports = response.result();
reports.forEach(function(report) {
var standardStats = {
id: report.id,
timestamp: report.timestamp.getTime(),
type: report.type,
};
report.names().forEach(function(name) {
standardStats[name] = report.stat(name);
});
// backfill mediaType -- until https://codereview.chromium.org/1307633007/ lands.
if (report.type === 'ssrc' && !standardStats.mediaType && standardStats.googTrackId) {
// look up track kind in local or remote streams.
var streams = pc.getRemoteStreams().concat(pc.getLocalStreams());
for (var i = 0; i < streams.length && !standardStats.mediaType; i++) {
var tracks = streams[i].getTracks();
for (var j = 0; j < tracks.length; j++) {
if (tracks[j].id === standardStats.googTrackId) {
standardStats.mediaType = tracks[j].kind;
report.mediaType = tracks[j].kind;
}
}
}
}
standardReport[standardStats.id] = standardStats;
});
return standardReport;
}

var wsURL = 'wss://rtcstats.tokbox.com/';
var PROTOCOL_VERSION = '1.0';
var buffer = [];
Expand Down Expand Up @@ -51,7 +107,8 @@
}
}

var origPeerConnection = window.webkitRTCPeerConnection || window.RTCPeerConnection || window.mozRTCPeerConnection;
var origPeerConnection = window.webkitRTCPeerConnection ||
window.RTCPeerConnection || window.mozRTCPeerConnection;
if (origPeerConnection) {
var peerconnectioncounter = 0;
var isChrome = origPeerConnection === window.webkitRTCPeerConnection;
Expand All @@ -61,7 +118,7 @@

config = JSON.parse(JSON.stringify(config)); // deepcopy
// don't log credentials
(config && config.iceServers || []).forEach(function(server) {
((config && config.iceServers) || []).forEach(function(server) {
delete server.credential;
});

Expand Down Expand Up @@ -131,7 +188,7 @@
args[1].apply(null, [err]);
}
},
opts
opts,
]);
});
};
Expand All @@ -145,21 +202,21 @@
trace(method, id, args[0]);
return new Promise(function(resolve, reject) {
nativeMethod.apply(pc, [args[0],
function() {
trace(method + 'OnSuccess', id);
resolve();
if (args.length >= 2) {
args[1].apply(null, []);
}
},
function(err) {
trace(method + 'OnFailure', id, err);
reject(err);
if (args.length >= 3) {
args[2].apply(null, [err]);
}
}]
);
function() {
trace(method + 'OnSuccess', id);
resolve();
if (args.length >= 2) {
args[1].apply(null, []);
}
},
function(err) {
trace(method + 'OnFailure', id, err);
reject(err);
if (args.length >= 3) {
args[2].apply(null, [err]);
}
}],
);
});
};
});
Expand Down Expand Up @@ -224,7 +281,7 @@
return arguments.length ?
origPeerConnection.generateCertificate.apply(null, arguments)
: origPeerConnection.generateCertificate;
}
},
});
}
if (window.webkitRTCPeerConnection) {
Expand All @@ -245,14 +302,14 @@
id: stream.id,
tracks: stream.getTracks().map(function(track) {
return {
id: track.id, // unique identifier (GUID) for the track
kind: track.kind, // `audio` or `video`
label: track.label, // identified the track source
enabled: track.enabled, // application can control it
muted: track.muted, // application cannot control it (read-only)
readyState: track.readyState // `live` or `ended`
id: track.id, // unique identifier (GUID) for the track
kind: track.kind, // `audio` or `video`
label: track.label, // identified the track source
enabled: track.enabled, // application can control it
muted: track.muted, // application cannot control it (read-only)
readyState: track.readyState, // `live` or `ended`
};
})
}),
};
}
if (navigator.webkitGetUserMedia || navigator.mozGetUserMedia) {
Expand All @@ -277,7 +334,7 @@
if (eb) {
eb(err);
}
}
},
);
};
if (navigator.webkitGetUserMedia) {
Expand Down Expand Up @@ -309,60 +366,6 @@
}
});
*/
// apply a delta compression to the stats report. Reduces size by ~90%.
// To reduce further, report keys could be compressed.
function deltaCompression(oldStats, newStats) {
newStats = JSON.parse(JSON.stringify(newStats));
Object.keys(newStats).forEach(function(id) {
if (!oldStats[id]) {
return;
}
var report = newStats[id];
Object.keys(report).forEach(function(name) {
if (report[name] === oldStats[id][name]) {
delete newStats[id][name];
}
delete report.timestamp;
if (Object.keys(report).length === 0) {
delete newStats[id];
}
});
});
// TODO: moving the timestamp to the top-level is not compression but...
newStats.timestamp = new Date();
return newStats;
}

function mangleChromeStats(pc, response) {
var standardReport = {};
var reports = response.result();
reports.forEach(function(report) {
var standardStats = {
id: report.id,
timestamp: report.timestamp.getTime(),
type: report.type
};
report.names().forEach(function(name) {
standardStats[name] = report.stat(name);
});
// backfill mediaType -- until https://codereview.chromium.org/1307633007/ lands.
if (report.type === 'ssrc' && !standardStats.mediaType && standardStats.googTrackId) {
// look up track kind in local or remote streams.
var streams = pc.getRemoteStreams().concat(pc.getLocalStreams());
for (var i = 0; i < streams.length && !standardStats.mediaType; i++) {
var tracks = streams[i].getTracks();
for (var j = 0; j < tracks.length; j++) {
if (tracks[j].id === standardStats.googTrackId) {
standardStats.mediaType = tracks[j].kind;
report.mediaType = tracks[j].kind;
}
}
}
}
standardReport[standardStats.id] = standardStats;
});
return standardReport;
}

/*
function filterBoringStats(results) {
Expand Down

0 comments on commit e0e7de0

Please sign in to comment.