Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 32 additions & 25 deletions lib/opentok.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function decodeSessionId(sessionId) {
* <a href="https://tokbox.com/account">TokBox account page</a>.)
*/
// eslint-disable-next-line consistent-return
OpenTok = function (apiKey, apiSecret, env) {
OpenTok = function(apiKey, apiSecret, env) {
var apiConfig;
var clientConfig;
var config;
Expand All @@ -78,9 +78,9 @@ OpenTok = function (apiKey, apiSecret, env) {
// validate arguments: apiKey := Number|String, apiSecret := String
if (!(_.isNumber(apiKey) || _.isString(apiKey)) || !_.isString(apiSecret)) {
throw new Error('Invalid arguments when initializing OpenTok: apiKey='
+ apiKey
+ ', apiSecret='
+ apiSecret);
+ apiKey
+ ', apiSecret='
+ apiSecret);
}

// apiKey argument can be a Number, but we will internally store it as a String
Expand All @@ -95,7 +95,7 @@ OpenTok = function (apiKey, apiSecret, env) {

// TODO: this is a pretty obvious seam, the integration could be more smooth
apiConfig = {
apiEndpoint: callVonage ? 'https://video.api.vonage.com' : 'https://api.opentok.com' ,
apiEndpoint: callVonage ? 'https://video.api.vonage.com' : 'https://api.opentok.com',
apiKey: apiKey,
apiSecret: apiSecret,
auth: {
Expand Down Expand Up @@ -905,7 +905,7 @@ OpenTok = function (apiKey, apiSecret, env) {
* @method #startBroadcast
* @memberof OpenTok
*/
OpenTok.prototype.startBroadcast = function (sessionId, options, callback) {
OpenTok.prototype.startBroadcast = function(sessionId, options, callback) {
var client = this.client;

if (typeof callback !== 'function') {
Expand All @@ -929,7 +929,7 @@ OpenTok = function (apiKey, apiSecret, env) {
return;
}
}
client.startBroadcast(options, function (err, json) {
client.startBroadcast(options, function(err, json) {
if (err) {
return callback(new Error('Failed to start broadcast. ' + err));
}
Expand Down Expand Up @@ -1056,7 +1056,7 @@ OpenTok = function (apiKey, apiSecret, env) {
throw new errors.ArgumentError('No callback given to stopBroadcast');
}

client.stopBroadcast(broadcastId, function (err, json) {
client.stopBroadcast(broadcastId, function(err, json) {
if (err) return callback(new Error('Failed to stop broadcast. ' + err));
return callback(null, new Broadcast(client, json));
});
Expand Down Expand Up @@ -1086,7 +1086,7 @@ OpenTok = function (apiKey, apiSecret, env) {
throw new errors.ArgumentError('No callback given to getBroadcast');
}

client.getBroadcast(broadcastId, function (err, json) {
client.getBroadcast(broadcastId, function(err, json) {
if (err) return callback(new Error('Failed to get broadcast. ' + err));
return callback(null, new Broadcast(client, json));
});
Expand Down Expand Up @@ -1277,6 +1277,9 @@ OpenTok = function (apiKey, apiSecret, env) {
* <code>headers</code> (Object) &mdash; An object of key-value pairs of headers to be
* sent to your WebSocket server with each message, with a maximum length of 512 bytes.
* </li>
* <li>
* <code>audioRate</code> (String) &mdash; The audio rate to be used for the WebSocket connection.
* </li>
* </ul>
*
* @param callback {Function} The function to call upon completing the operation. Upon error,
Expand Down Expand Up @@ -1352,7 +1355,11 @@ OpenTok = function (apiKey, apiSecret, env) {
body.websocket.bidirectional = options.bidirectional;
}

this.client.websocketConnect(body, function (err, json) {
if (options.audioRate) {
body.websocket.audioRate = options.audioRate;
}

this.client.websocketConnect(body, function(err, json) {
if (err) return callback(new Error('Error connecting to websocket: ' + err.message));
return callback(null, json);
});
Expand Down Expand Up @@ -1415,16 +1422,16 @@ OpenTok = function (apiKey, apiSecret, env) {
layoutObj = classListArray[i];
if (typeof layoutObj.id !== 'string') {
return callback(new Error('Invalid arguments -- each element in the streamClassArray '
+ 'must have an id string.'));
+ 'must have an id string.'));
}
if (!Array.isArray(layoutObj.layoutClassList)) {
return callback(new Error('Invalid arguments -- each element in the streamClassArray '
+ 'must have a layoutClassList array.'));
+ 'must have a layoutClassList array.'));
}
for (j = 0; j < layoutObj.layoutClassList.length; j += 1) {
if (typeof layoutObj.layoutClassList[j] !== 'string') {
return callback(new Error('Invalid arguments -- each element in the layoutClassList '
+ 'array must be a string (defining class names).'));
+ 'array must be a string (defining class names).'));
}
}
}
Expand Down Expand Up @@ -1871,7 +1878,7 @@ OpenTok = function (apiKey, apiSecret, env) {
* the SIP call</li>
* </ul>
*/
OpenTok.prototype.dial = function (sessionId, token, sipUri, options, callback) {
OpenTok.prototype.dial = function(sessionId, token, sipUri, options, callback) {
var self = this;
var body;

Expand Down Expand Up @@ -1928,7 +1935,7 @@ OpenTok.prototype.dial = function (sessionId, token, sipUri, options, callback)
body.sip.streams = options.streams;
}

this.client.dial(body, function (err, json) {
this.client.dial(body, function(err, json) {
if (err) return callback(new Error('Failed to dial endpoint. ' + err));
return callback(null, new SipInterconnect(self, json));
});
Expand Down Expand Up @@ -2032,7 +2039,7 @@ for the OpenTok session. Set to <code>"true"</code> or <code>"false"</code>.
* </li>
* </ul>
*/
OpenTok.prototype.createSession = function (opts, callback) {
OpenTok.prototype.createSession = function(opts, callback) {
var backupOpts;
var self = this;
var mediaModeToParam;
Expand Down Expand Up @@ -2062,14 +2069,14 @@ OpenTok.prototype.createSession = function (opts, callback) {
}

if (opts.archiveMode === 'always' && opts.mediaMode !== 'routed') {
return process.nextTick(function () {
return process.nextTick(function() {
callback(new Error('A session with always archive mode must also have the routed media mode.'));
});
}
if ('location' in opts && !net.isIPv4(opts.location)) {
return process.nextTick(function () {
return process.nextTick(function() {
callback(new Error('Invalid arguments when calling createSession, location must be an '
+ 'IPv4 address'));
+ 'IPv4 address'));
});
}

Expand Down Expand Up @@ -2157,7 +2164,7 @@ OpenTok.prototype.createSession = function (opts, callback) {
* @return The token string.
*/

OpenTok.prototype.generateToken = function (sessionId, opts, generateT1Token = false) {
OpenTok.prototype.generateToken = function(sessionId, opts, generateT1Token = false) {
if (this.client?.c?.callVonage) {
const now = Math.round(new Date().getTime() / 1000);
const claims = {
Expand Down Expand Up @@ -2252,9 +2259,9 @@ OpenTok.prototype.generateToken = function (sessionId, opts, generateT1Token = f
}
if (tokenData.expire_time < now) {
throw new Error('Invalid expireTime for token generation, time cannot be in the past: '
+ tokenData.expire_time
+ ' < '
+ now);
+ tokenData.expire_time
+ ' < '
+ now);
}
if (
tokenData.connection_data
Expand All @@ -2268,7 +2275,7 @@ OpenTok.prototype.generateToken = function (sessionId, opts, generateT1Token = f
&& tokenData.initial_layout_class_list.length > 1024
) {
throw new Error('Invalid initial layout class list for token generation, must have '
+ 'concatenated length of less than 1024');
+ 'concatenated length of less than 1024');
}

if (generateT1Token) {
Expand All @@ -2283,7 +2290,7 @@ OpenTok.prototype.generateToken = function (sessionId, opts, generateT1Token = f
* @param none
* @returns {string} JWT
*/
OpenTok.prototype.generateJwt = function () {
OpenTok.prototype.generateJwt = function() {
return generateJwt(this.client.c);
};

Expand Down
Loading
Loading