Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make janus.js pass linter #2772

Merged
merged 13 commits into from
Sep 27, 2021
16 changes: 16 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
"env": {
"browser": true,
"es6": true,
"jquery": true
atoppi marked this conversation as resolved.
Show resolved Hide resolved
},
"extends": "eslint:recommended",
"rules": {
atoppi marked this conversation as resolved.
Show resolved Hide resolved
"no-console": "off",
"no-empty": "off",
},
"globals": {
"adapter": "readonly",
"RTCRtpTransceiver": "readonly"
}
};
21 changes: 21 additions & 0 deletions .github/workflows/janus-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,24 @@ jobs:
./configure $JANUS_CONFIG_COMMON $JANUS_CONFIG_OPTS
make -j$(nproc)
make check-fuzzers
javascript-lint:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Install modules
run: npm install --only=dev
atoppi marked this conversation as resolved.
Show resolved Hide resolved
- name: Run ESLint
run: node_modules/.bin/eslint html/janus.js
javascript-rollup:
atoppi marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Rollup
run: |
cd npm
npm install
npm run rollup -- --o janus.cjs.js --f cjs
- uses: actions/upload-artifact@v2
atoppi marked this conversation as resolved.
Show resolved Hide resolved
with:
name: janus.cjs.js
path: npm/janus.cjs.js
90 changes: 42 additions & 48 deletions html/janus.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";
atoppi marked this conversation as resolved.
Show resolved Hide resolved

/*
The MIT License (MIT)

Expand Down Expand Up @@ -230,8 +232,8 @@ Janus.init = function(options) {
// Already initialized
options.callback();
} else {
if(typeof console == "undefined" || typeof console.log == "undefined") {
console = { log: function() {} };
if(typeof console.log == "undefined") {
atoppi marked this conversation as resolved.
Show resolved Hide resolved
console.log = function() {};
}
// Console logging (all debugging disabled by default)
Janus.trace = Janus.noop;
Expand Down Expand Up @@ -337,7 +339,7 @@ Janus.init = function(options) {
var iOS = ['iPad', 'iPhone', 'iPod'].indexOf(navigator.platform) >= 0;
var eventName = iOS ? 'pagehide' : 'beforeunload';
var oldOBF = window["on" + eventName];
window.addEventListener(eventName, function(event) {
window.addEventListener(eventName, function() {
Janus.log("Closing window");
for(var s in Janus.sessions) {
if(Janus.sessions[s] && Janus.sessions[s].destroyOnUnload) {
Expand Down Expand Up @@ -609,9 +611,9 @@ function Janus(gatewayCallbacks) {
// Just info on the Janus instance
Janus.debug("Got info on the Janus instance");
Janus.debug(json);
var transaction = json["transaction"];
const transaction = json["transaction"];
if(transaction) {
var reportSuccess = transactions[transaction];
const reportSuccess = transactions[transaction];
if(reportSuccess)
reportSuccess(json);
delete transactions[transaction];
Expand All @@ -621,9 +623,9 @@ function Janus(gatewayCallbacks) {
// Just an ack, we can probably ignore
Janus.debug("Got an ack on session " + sessionId);
Janus.debug(json);
var transaction = json["transaction"];
const transaction = json["transaction"];
if(transaction) {
var reportSuccess = transactions[transaction];
const reportSuccess = transactions[transaction];
if(reportSuccess)
reportSuccess(json);
delete transactions[transaction];
Expand All @@ -633,22 +635,22 @@ function Janus(gatewayCallbacks) {
// Success!
Janus.debug("Got a success on session " + sessionId);
Janus.debug(json);
var transaction = json["transaction"];
const transaction = json["transaction"];
if(transaction) {
var reportSuccess = transactions[transaction];
const reportSuccess = transactions[transaction];
if(reportSuccess)
reportSuccess(json);
delete transactions[transaction];
}
return;
} else if(json["janus"] === "trickle") {
// We got a trickle candidate from Janus
var sender = json["sender"];
const sender = json["sender"];
if(!sender) {
Janus.warn("Missing sender...");
return;
}
var pluginHandle = pluginHandles[sender];
const pluginHandle = pluginHandles[sender];
if(!pluginHandle) {
Janus.debug("This handle is not attached to this session");
return;
Expand Down Expand Up @@ -679,12 +681,12 @@ function Janus(gatewayCallbacks) {
// The PeerConnection with the server is up! Notify this
Janus.debug("Got a webrtcup event on session " + sessionId);
Janus.debug(json);
var sender = json["sender"];
const sender = json["sender"];
if(!sender) {
Janus.warn("Missing sender...");
return;
}
var pluginHandle = pluginHandles[sender];
const pluginHandle = pluginHandles[sender];
if(!pluginHandle) {
Janus.debug("This handle is not attached to this session");
return;
Expand All @@ -695,12 +697,12 @@ function Janus(gatewayCallbacks) {
// A plugin asked the core to hangup a PeerConnection on one of our handles
Janus.debug("Got a hangup event on session " + sessionId);
Janus.debug(json);
var sender = json["sender"];
const sender = json["sender"];
if(!sender) {
Janus.warn("Missing sender...");
return;
}
var pluginHandle = pluginHandles[sender];
const pluginHandle = pluginHandles[sender];
if(!pluginHandle) {
Janus.debug("This handle is not attached to this session");
return;
Expand All @@ -711,12 +713,12 @@ function Janus(gatewayCallbacks) {
// A plugin asked the core to detach one of our handles
Janus.debug("Got a detached event on session " + sessionId);
Janus.debug(json);
var sender = json["sender"];
const sender = json["sender"];
if(!sender) {
Janus.warn("Missing sender...");
return;
}
var pluginHandle = pluginHandles[sender];
const pluginHandle = pluginHandles[sender];
if(!pluginHandle) {
// Don't warn here because destroyHandle causes this situation.
return;
Expand All @@ -727,12 +729,12 @@ function Janus(gatewayCallbacks) {
// Media started/stopped flowing
Janus.debug("Got a media event on session " + sessionId);
Janus.debug(json);
var sender = json["sender"];
const sender = json["sender"];
if(!sender) {
Janus.warn("Missing sender...");
return;
}
var pluginHandle = pluginHandles[sender];
const pluginHandle = pluginHandles[sender];
if(!pluginHandle) {
Janus.debug("This handle is not attached to this session");
return;
Expand All @@ -742,12 +744,12 @@ function Janus(gatewayCallbacks) {
Janus.debug("Got a slowlink event on session " + sessionId);
Janus.debug(json);
// Trouble uplink or downlink
var sender = json["sender"];
const sender = json["sender"];
if(!sender) {
Janus.warn("Missing sender...");
return;
}
var pluginHandle = pluginHandles[sender];
const pluginHandle = pluginHandles[sender];
if(!pluginHandle) {
Janus.debug("This handle is not attached to this session");
return;
Expand All @@ -769,7 +771,7 @@ function Janus(gatewayCallbacks) {
} else if(json["janus"] === "event") {
Janus.debug("Got a plugin event on session " + sessionId);
Janus.debug(json);
var sender = json["sender"];
const sender = json["sender"];
if(!sender) {
Janus.warn("Missing sender...");
return;
Expand All @@ -782,7 +784,7 @@ function Janus(gatewayCallbacks) {
Janus.debug(" -- Event is coming from " + sender + " (" + plugindata["plugin"] + ")");
var data = plugindata["data"];
Janus.debug(data);
var pluginHandle = pluginHandles[sender];
const pluginHandle = pluginHandles[sender];
if(!pluginHandle) {
Janus.warn("This handle is not attached to this session");
return;
Expand Down Expand Up @@ -1101,7 +1103,7 @@ function Janus(gatewayCallbacks) {
gatewayCallbacks.destroyed();
}
};
var onUnbindError = function(event) {
var onUnbindError = function() {
unbindWebSocket();
callbacks.error("Failed to destroy the server: Is the server down?");
if(notifyDestroyed)
Expand Down Expand Up @@ -1758,9 +1760,9 @@ function Janus(gatewayCallbacks) {
// Use Transceivers
Janus.log((media.replaceAudio ? "Replacing" : "Adding") + " audio track:", stream.getAudioTracks()[0]);
var audioTransceiver = null;
var transceivers = config.pc.getTransceivers();
const transceivers = config.pc.getTransceivers();
if(transceivers && transceivers.length > 0) {
for(var t of transceivers) {
for(const t of transceivers) {
if((t.sender && t.sender.track && t.sender.track.kind === "audio") ||
(t.receiver && t.receiver.track && t.receiver.track.kind === "audio")) {
audioTransceiver = t;
Expand All @@ -1785,9 +1787,9 @@ function Janus(gatewayCallbacks) {
// Use Transceivers
Janus.log((media.replaceVideo ? "Replacing" : "Adding") + " video track:", stream.getVideoTracks()[0]);
var videoTransceiver = null;
var transceivers = config.pc.getTransceivers();
const transceivers = config.pc.getTransceivers();
if(transceivers && transceivers.length > 0) {
for(var t of transceivers) {
for(const t of transceivers) {
if((t.sender && t.sender.track && t.sender.track.kind === "video") ||
(t.receiver && t.receiver.track && t.receiver.track.kind === "video")) {
videoTransceiver = t;
Expand Down Expand Up @@ -1850,7 +1852,7 @@ function Janus(gatewayCallbacks) {
config.bitrate.value = "0 kbits/sec";
}
Janus.log("Preparing local SDP and gathering candidates (trickle=" + config.trickle + ")");
config.pc.oniceconnectionstatechange = function(e) {
config.pc.oniceconnectionstatechange = function() {
if(config.pc)
pluginHandle.iceState(config.pc.iceConnectionState);
};
Expand Down Expand Up @@ -1949,7 +1951,7 @@ function Janus(gatewayCallbacks) {
pluginHandle.onremotestream(config.remoteStream);
} catch(e) {
Janus.error(e);
};
}
}
};
};
Expand Down Expand Up @@ -2301,46 +2303,38 @@ function Janus(gatewayCallbacks) {
videoSupport = media.video;
} else {
var width = 0;
var height = 0, maxHeight = 0;
atoppi marked this conversation as resolved.
Show resolved Hide resolved
var height = 0;
if(media.video === 'lowres') {
// Small resolution, 4:3
height = 240;
maxHeight = 240;
width = 320;
} else if(media.video === 'lowres-16:9') {
// Small resolution, 16:9
height = 180;
maxHeight = 180;
width = 320;
} else if(media.video === 'hires' || media.video === 'hires-16:9' || media.video === 'hdres') {
// High(HD) resolution is only 16:9
height = 720;
maxHeight = 720;
width = 1280;
} else if(media.video === 'fhdres') {
// Full HD resolution is only 16:9
height = 1080;
maxHeight = 1080;
width = 1920;
} else if(media.video === '4kres') {
// 4K resolution is only 16:9
height = 2160;
maxHeight = 2160;
width = 3840;
} else if(media.video === 'stdres') {
// Normal resolution, 4:3
height = 480;
maxHeight = 480;
width = 640;
} else if(media.video === 'stdres-16:9') {
// Normal resolution, 16:9
height = 360;
maxHeight = 360;
width = 640;
} else {
Janus.log("Default video setting is stdres 4:3");
height = 480;
maxHeight = 480;
width = 640;
}
Janus.log("Adding media constraint:", media.video);
Expand Down Expand Up @@ -2386,15 +2380,15 @@ function Janus(gatewayCallbacks) {
}
// We're going to try and use the extension for Chrome 34+, the old approach
// for older versions of Chrome, or the experimental support in Firefox 33+
function callbackUserMedia (error, stream) {
const callbackUserMedia = function(error, stream) {
pluginHandle.consentDialog(false);
if(error) {
callbacks.error(error);
} else {
streamsDone(handleId, jsep, media, callbacks, stream);
}
}
function getScreenMedia(constraints, gsmCallback, useAudio) {
const getScreenMedia = function(constraints, gsmCallback, useAudio) {
Janus.log("Adding media constraint (screen capture)");
Janus.debug(constraints);
navigator.mediaDevices.getUserMedia(constraints)
Expand Down Expand Up @@ -3352,10 +3346,10 @@ function Janus(gatewayCallbacks) {
var ssrc = [ -1 ], ssrc_fid = [ -1 ];
var cname = null, msid = null, mslabel = null, label = null;
var insertAt = -1;
for(var i=0; i<lines.length; i++) {
var mline = lines[i].match(/m=(\w+) */);
for(let i=0; i<lines.length; i++) {
const mline = lines[i].match(/m=(\w+) */);
if(mline) {
var medium = mline[1];
const medium = mline[1];
if(medium === "video") {
// New video m-line: make sure it's the first one
if(ssrc[0] < 0) {
Expand Down Expand Up @@ -3424,10 +3418,10 @@ function Janus(gatewayCallbacks) {
// Couldn't find a FID attribute, let's just take the first video SSRC we find
insertAt = -1;
video = false;
for(var i=0; i<lines.length; i++) {
var mline = lines[i].match(/m=(\w+) */);
for(let i=0; i<lines.length; i++) {
const mline = lines[i].match(/m=(\w+) */);
if(mline) {
var medium = mline[1];
const medium = mline[1];
if(medium === "video") {
// New video m-line: make sure it's the first one
if(ssrc[0] < 0) {
Expand Down Expand Up @@ -3457,7 +3451,7 @@ function Janus(gatewayCallbacks) {
continue;
}
} else {
var match = lines[i].match('a=ssrc:' + ssrc[0] + ' cname:(.+)')
let match = lines[i].match('a=ssrc:' + ssrc[0] + ' cname:(.+)')
if(match) {
cname = match[1];
}
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
"homepage": "https://github.com/meetecho/janus-gateway#readme",
"dependencies": {
"webrtc-adapter": "8.0.0"
},
"devDependencies": {
"eslint": "5.0.1"
atoppi marked this conversation as resolved.
Show resolved Hide resolved
}
}