diff --git a/lib/callbacks.js b/lib/callbacks.js
index eb1c30a5..a7a20082 100644
--- a/lib/callbacks.js
+++ b/lib/callbacks.js
@@ -65,26 +65,29 @@ exports.listCallbacks = function (config, options, callback) {
throw (new errors.ArgumentError('No callback given to listCallbacks'));
}
api(config, 'GET', '/callback', null, function (err, response, body) {
- if (!err && body && body.constructor === String) {
- try {
- body = JSON.parse(body);
- }
- catch (_err) {
- err = _err;
- }
+ if (err) {
+ callback(err);
}
- if (err || Math.floor(response.statusCode / 100) !== 2) {
- if (response && response.statusCode === 403) {
+
+ try {
+ body = JSON.parse(body);
+ }
+ catch (_err) {
+ err = _err;
+ }
+
+ switch (response.statusCode) {
+ case 200:
+ callback(null, body.map(function (item) {
+ return new Callback(config, item);
+ }));
+ return;
+ case 403:
callback(new errors.AuthError('Invalid API key or secret'));
- }
- else {
+ return;
+ default:
callback(new errors.RequestError('Unexpected response from OpenTok: ' + JSON.stringify(body || { statusCode: response.statusCode, statusMessage: response.statusMessage })));
- }
- }
- else {
- callback(null, body.map(function (item) {
- return new Callback(config, item);
- }));
+ return;
}
});
};
@@ -104,20 +107,21 @@ exports.registerCallback = function (config, options, callback) {
}, function apiCallback(err, response, body) {
if (err) {
callback(err);
+ return;
}
- else if (Math.floor(response.statusCode / 100) !== 2) {
- if (response && response.statusCode === 404) {
+
+ switch(response.statusCode) {
+ case 200:
+ callback(null, new Callback(config, body));
+ return;
+ case 404:
callback(new errors.CallbackError('Callback event not found'));
- }
- else if (response && response.statusCode === 403) {
+ return;
+ case 403:
callback(new errors.AuthError('Invalid API key or secret'));
- }
- else {
+ return;
+ default:
callback(new errors.RequestError('Unexpected response from OpenTok: ' + JSON.stringify(body || { statusCode: response.statusCode, statusMessage: response.statusMessage })));
- }
- }
- else {
- callback(null, new Callback(config, body));
}
});
};
@@ -138,20 +142,24 @@ exports.unregisterCallback = function (config, callbackId, callback) {
function (err, response, body) {
if (err) {
callback(err);
+ return;
}
- else if (Math.floor(response.statusCode / 100) !== 2) {
- if (response && response.statusCode === 404) {
+
+ switch (response.statusCode) {
+ case 204:
+ callback(null);
+ return;
+ case 404:
callback(new errors.CallbackError('Callback not found'));
- }
- else if (response && response.statusCode === 403) {
+ return;
+ case 403:
callback(new errors.AuthError('Invalid API key or secret'));
- }
- else {
- callback(new errors.RequestError('Unexpected response from OpenTok: ' + JSON.stringify(body || { statusCode: response.statusCode, statusMessage: response.statusMessage })));
- }
- }
- else {
- callback(null);
+ return;
+ default:
+ callback(new errors.RequestError('Unexpected response from OpenTok: ' + JSON.stringify(body || {
+ statusCode: response.statusCode,
+ statusMessage: response.statusMessage
+ })));
}
}
);
diff --git a/lib/moderation.js b/lib/moderation.js
index e27bd1ff..71d5af02 100644
--- a/lib/moderation.js
+++ b/lib/moderation.js
@@ -15,7 +15,7 @@ var api = function (config, method, session, connection, body, callback) {
(config.uaAddendum ? ' ' + config.uaAddendum : '')
};
- if (body && ['POST', 'PATCH', 'PUT'].includes(method)) {
+ if (body) {
headers['Content-Type'] = 'application/json';
}
@@ -37,6 +37,7 @@ var api = function (config, method, session, connection, body, callback) {
callback(null, otResponse, body);
})
.catch(async (error) => {
+ /* istanbul ignore next */
callback(error);
});
};
diff --git a/lib/opentok.js b/lib/opentok.js
index 08ff22b7..5dfa4d52 100644
--- a/lib/opentok.js
+++ b/lib/opentok.js
@@ -36,9 +36,7 @@ function decodeSessionId(sessionId) {
if (typeof Buffer.from === 'function') {
sessionId = Buffer.from(sessionId, 'base64').toString('ascii');
}
- else {
- sessionId = Buffer.from(sessionId, 'base64').toString('ascii');
- }
+
// separate fields
fields = sessionId.split('~');
return {
@@ -1158,7 +1156,7 @@ OpenTok = function (apiKey, apiSecret, env) {
* an error
object is passed in as the first parameter of the function.
* Upon success, the function is called with no error object passed in (as the first parameter)
* and the second parameter is an object with the following properties:
- *
+ *
*
id
-- A unique ID identifying the Audio Streamer WebSocket connection.
@@ -1168,7 +1166,7 @@ OpenTok = function (apiKey, apiSecret, env) {
* WebSocket connection in the OpenTok session.
* e2ee
(Boolean) —
* Determines whether to enable
`end-to-end encryption