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M,IAAI,MAAM,sCAAwC,EAAU,MAEpE,IAAK,EAAE,SAAS,EAAU,aACxB,MAAM,IAAI,MAAM,4CAA8C,EAAU,aAE1E,GAAI,EAAU,YAAc,EAC1B,MAAM,IAAI,MAAM,wEACV,EAAU,YACV,MACA,GAER,GACE,EAAU,kBACN,EAAU,gBAAgB,OAAS,OACjC,EAAE,SAAS,EAAU,kBAE3B,MAAM,IAAI,MAAM,gFAElB,GACE,EAAU,2BACP,EAAU,0BAA0B,OAAS,KAEhD,MAAM,IAAI,MAAM,2GAIlB,OAAI,EACK,YAAY,EAAW,KAAK,OAAQ,KAAK,WAG3C,YAAY,KAAK,OAAO,EAAG,EACpC,EAOA,QAAQ,UAAU,YAAc,WAC9B,OAAO,YAAY,KAAK,OAAO,EACjC,EAmCA,OAAO,QAAU,QAEL,OACN,OAAO,UAAU,eAAe,KAAK,OAAQ,OAC/C,QAAQ,KAAO,OAAO","file":"/npm/opentok@2.23.1/lib/opentok.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/opentok@2.23.1/lib/opentok.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/*\n * OpenTok server-side SDK\n */\n\n// Dependencies\nconst debug = require('debug');\nvar net = require('net');\nvar _ = require('lodash');\nvar encodeToken = require('opentok-token');\nvar Client = require('./client');\nvar Session = require('./session');\nvar Stream = require('./stream');\nvar archiving = require('./archiving');\nvar Broadcast = require('./broadcast');\nvar SipInterconnect = require('./sipInterconnect');\nvar moderation = require('./moderation');\nvar signaling = require('./signaling');\nvar errors = require('./errors');\nvar callbacks = require('./callbacks');\nvar generateJwt = require('./generateJwt');\nvar render = require('./render.js');\nvar captions = require('./captions.js');\nvar OpenTok;\nvar key;\nconst { tokenGenerate } = require('@vonage/jwt');\n\nconst log = debug('@opentok');\n/*\n * decodes a sessionId into the metadata that it contains\n * @param     {string}         sessionId\n * @returns   {?SessionInfo}    sessionInfo\n */\nfunction decodeSessionId(sessionId) {\n  var fields;\n  // remove sentinal (e.g. '1_', '2_')\n  sessionId = sessionId.substring(2);\n  // replace invalid base64 chars\n  sessionId = sessionId.replace(/-/g, '+').replace(/_/g, '/');\n  // base64 decode\n  if (typeof Buffer.from === 'function') {\n    sessionId = Buffer.from(sessionId, 'base64').toString('ascii');\n  }\n\n  // separate fields\n  fields = sessionId.split('~');\n  return {\n    apiKey: fields[1],\n    location: fields[2],\n    create_time: new Date(fields[3])\n  };\n}\n\n/**\n * Contains methods for creating OpenTok sessions, generating tokens, working with archives, and more.\n * <p>\n * To create a new OpenTok object, call the OpenTok constructor with your OpenTok API key\n * and the API secret for your <a href=\"https://tokbox.com/account\">TokBox account</a>.\n * Do not publicly share your API secret. You will use it with the OpenTok constructor\n * (only on your web server) to create OpenTok sessions.\n * <p>\n * Be sure to include the entire OpenTok Node.js SDK on your web server.\n *\n * @class OpenTok\n *\n * @param apiKey {String} Your OpenTok API key. (See your\n * <a href=\"https://tokbox.com/account\">TokBox account page</a>.)\n * @param apiSecret {String} Your OpenTok API secret. (See your\n * <a href=\"https://tokbox.com/account\">TokBox account page</a>.)\n */\n// eslint-disable-next-line consistent-return\nOpenTok = function (apiKey, apiSecret, env) {\n  var apiConfig;\n  var clientConfig;\n  var config;\n  // we're loose about calling this constructor with `new`, we got your back\n  if (!(this instanceof OpenTok)) return new OpenTok(apiKey, apiSecret, env);\n\n  // validate arguments: apiKey := Number|String, apiSecret := String\n  if (!(_.isNumber(apiKey) || _.isString(apiKey)) || !_.isString(apiSecret)) {\n    throw new Error('Invalid arguments when initializing OpenTok: apiKey='\n        + apiKey\n        + ', apiSecret='\n        + apiSecret);\n  }\n\n  // apiKey argument can be a Number, but we will internally store it as a String\n  if (_.isNumber(apiKey)) apiKey = apiKey.toString();\n\n  this.client = new Client({ apiKey: apiKey, apiSecret: apiSecret });\n  this.apiKey = apiKey;\n  this.apiSecret = apiSecret;\n\n  const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\n  const callVonage = `${apiSecret}`.startsWith('-----BEGIN PRIVATE KEY') && uuidRegex.test(apiKey);\n\n  // TODO: this is a pretty obvious seam, the integration could be more smooth\n  apiConfig = {\n    apiEndpoint: callVonage ? 'https://video.api.vonage.com' : 'https://api.opentok.com' ,\n    apiKey: apiKey,\n    apiSecret: apiSecret,\n    auth: {\n      expire: 300\n    },\n    callVonage: callVonage,\n  };\n\n  // env can be either an object with a bunch of DI options, or a simple string for the apiUrl\n  clientConfig = {\n    request: {},\n    apiUrl: callVonage ? 'https://video.api.vonage.com' : 'https://api.opentok.com',\n    callVonage: callVonage,\n  };\n  if (_.isString(env)) {\n    clientConfig.apiUrl = env;\n    apiConfig.apiEndpoint = env;\n  }\n\n  if (_.isObject(env) && !_.isFunction(env) && !_.isArray(env)) {\n    if (_.isString(env.apiUrl)) {\n      clientConfig.apiUrl = env.apiUrl;\n      apiConfig.apiEndpoint = env.apiUrl;\n    }\n    if (_.isString(env.proxy)) {\n      clientConfig.request.proxy = env.proxy;\n      apiConfig.proxy = env.proxy;\n    }\n    if (_.isString(env.uaAddendum)) {\n      clientConfig.uaAddendum = env.uaAddendum;\n      apiConfig.uaAddendum = env.uaAddendum;\n    }\n\n    if (parseInt(env.timeout, 10)) {\n      clientConfig.request.timeout = parseInt(env.timeout, 10);\n    }\n  }\n\n  config = this.client.config(clientConfig);\n  this.apiUrl = config.apiUrl;\n\n  /**\n  * Starts archiving an OpenTok session.\n  * <p>\n  * Clients must be actively connected to the OpenTok session for you to successfully start\n  * recording an archive.\n  * <p>\n  * You can only record one archive at a time for a given session. You can only record archives\n  * of sessions that uses the OpenTok Media Router (sessions with the media mode set to routed);\n  * you cannot archive sessions with the media mode set to relayed.\n  *\n  * @param sessionId The session ID of the OpenTok session to archive.\n  *\n  * @param options {Object} An optional options object with the following properties (each\n  * of which is optional):\n  * <p>\n  * <ul>\n  *   <li>\n  *     <code>name</code> (String) &mdash; the name of the archive, which you can use to identify\n  *     the archive. The name is set as a property of the Archive object, and it is a property of\n  *     archive-related events in the OpenTok client libraries.\n  *   </li>\n  *   <li>\n  *     <code>hasAudio</code> (Boolean) &mdash; Whether the archive will include an audio track\n  *     (<code>true</code>) or not (<code>false</code>). The default value is <code>true</code>\n  *     (an audio track is included). If you set both  <code>hasAudio</code> and\n  *     <code>hasVideo</code> to <code>false</code>, the call to the <code>startArchive()</code>\n  *     method results in an error.\n  *   </li>\n  *   <li>\n  *     <code>hasVideo</code> (Boolean) &mdash; Whether the archive will include a video track\n  *     (<code>true</code>) or (not <code>false</code>). The default value is <code>true</code>\n  *     (a video track is included). If you set both  <code>hasAudio</code> and\n  *     <code>hasVideo</code> to <code>false</code>, the call to the <code>startArchive()</code>\n  *     method results in an error.\n  *   </li>\n  *   <li>\n  *     <code>outputMode</code> (String) &mdash; Whether all streams in the archive are recorded\n  *     to a single file (\"composed\", the default) or to individual files (\"individual\").\n  *   </li>\n  *   <li>\n  *     <code>layout</code> (Object) &mdash; An object defining the initial layout options\n  *     for a composed archive. This object has three properties: <code>type</code>,\n  *     <code>stylesheet</code>, and <code>screenshareType</code>, which are each strings.\n  *     Set <code>type</code> to \"bestFit\",\n  *     \"pip\", \"verticalPresentation\", \"horizontalPresentation\", or \"custom\". Set the\n  *     <code>stylesheet</code> property if <code>type</code> is set to \"custom\", and\n  *     set it to the stylesheet defining the custom layout. For example, set the\n  *     <code>layout</code> object to <code>{ type: \"pip\" }</code> to set the initial layout\n  *     of the archive to picture-in-picture. Set the <code>screenshareType</code> property\n  *     to the layout type to use when there is a screen-sharing stream in the session\n  *     (This property is optional.) Note if you set the <code>screenshareType</code> property,\n  *     you must set the <code>type</code> property to \"bestFit\" and leave\n  *     the <code>stylesheet</code> property unset. For details, see\n  *     <a href=\"https://tokbox.com/developer/guides/archiving/layout-control.html\">Customizing\n  *     the video layout for composed archives</a>.\n  *   </li>\n  *   <li>\n  *     <code>resolution</code> (String) &mdash; For a composed archive, set this to the\n  *     resolution of the archive. Valid values are \"1920x1080\", \"1280x720\" or \"640x480\"\n  *     (the default).\n  *   </li>\n  *   <li>\n  *      <code>streamMode</code> (optional) &mdash; The stream mode for the archive. This can be\n  *      set to one of the the following:\n  *\n  *        <ul>\n  *          <li> \"auto\" &mdash; Streams included in the archive are selected automatically\n  *          (the default).</li>\n  *\n  *          <li> \"manual\" &mdash; Specify streams to be included based on calls to the\n  *          {@link OpenTok#addArchivetStream OpenTok.addArchiveStream()} and\n  *          {@link OpenTok#removeArchiveStream OpenTok.removeArchiveStream()} methods.</li>\n  *       </ul>\n  *   </li>\n  *   <li>\n  *     <code>multiArchiveTag</code> (String) &mdash; Set this to support recording\n  *     multiple archives for the same session simultaneously. Set this to a unique string\n  *     for each simultaneous archive of an ongoing session. You must also set this option\n  *     when manually starting an archive that is automatically archived. Note that the\n  *     <code>multiArchiveTag</code> value is not included in the response for\n  *     the methods to list archives and retrieve archive information. If you do not specify a\n  *     unique <code>multiArchiveTag</code> you can only record one archive at a time for a\n  *     given session.\n  *   </li>\n  *   <li>\n  *     <code>maxBitrate</code> (Number) &mdash; The maximum video bitrate for the archive,\n  *     in bits per second. This option is only valid for composed archives. Set the maximum\n  *     video bitrate to control the size of the composed archive. This maximum bitrate\n  *     applies to the video bitrate only. If the output archive has audio, those bits will be\n  *     excluded from the limit. This value is mutually exclusive with <code>quantizationParameter</code>\n  *   </li>\n   *   <li>\n   *     <code>quantizationParameter</code> (Number) &mdash;quantization parameter (QP) is an optional video encoding\n   *     value allowed for composed archiving, smaller values generate higher quality and larger archives, larger values\n   *     generate lower quality and smaller archives, QP uses variable bitrate (VBR). This value is mutally exclusive\n   *     with <code>maxBitrate</code>\n   *   </li>\n  * </ul>\n  *\n  * For more information on archiving and the archive file formats, see the\n  * <a href=\"https://tokbox.com/opentok/tutorials/archiving/\">OpenTok archiving</a>\n  * programming guide.\n  *\n  * @param callback {Function} The function to call upon completing the operation. Two arguments\n  * are passed to the function:\n  *\n  * <ul>\n  *\n  *   <li>\n  *      <code>error</code> &mdash; An error object (if the call to the method fails).\n  *   </li>\n  *\n  *   <li>\n  *       <code>archive</code> &mdash; The {@link Archive} object. This object includes properties\n  *       defining the archive, including the archive ID.\n  *   </li>\n  *\n  * </ul>\n  *\n  * @method #startArchive\n  * @memberof OpenTok\n  */\n\n  this.startArchive = archiving.startArchive.bind(null, this, apiConfig);\n\n  /**\n   * Stops an OpenTok archive that is being recorded.\n   * <p>\n   * Archives automatically stop recording after 120 minutes or when all clients have disconnected\n   * from the session being archived.\n   * <p>\n   * You cannot stop an archive that is not being recorded.\n   *\n   * @param archiveId {String} The archive ID of the archive you want to stop recording.\n   * @return The {@link Archive} object corresponding to the archive being STOPPED.\n   *\n   * @param callback {Function} The function to call upon completing the operation. Two arguments\n   * are passed to the function:\n   *\n   * <ul>\n   *\n   *   <li>\n   *      <code>error</code> &mdash; An error object (if the call to the method fails).\n   *   </li>\n   *\n   *   <li>\n   *       <code>archive</code> &mdash; The {@link Archive} object.\n   *   </li>\n   *\n   * </ul>\n   *\n   * @method #stopArchive\n   * @memberof OpenTok\n   */\n  this.stopArchive = archiving.stopArchive.bind(null, apiConfig);\n\n  /**\n   * Gets an {@link Archive} object for the given archive ID.\n   *\n   * @param archiveId {String} The archive ID.\n   *\n   * @param callback {Function} The function to call upon completing the operation. Two arguments\n   * are passed to the function:\n   * <ul>\n   *   <li><code>error</code> &mdash; An error object (if the call to the method fails). </li>\n   *   <li><code>archive</code> &mdash; The {@link Archive} object.</li>\n   * </ul>\n   *\n   * @method #getArchive\n   * @memberof OpenTok\n   */\n  this.getArchive = archiving.getArchive.bind(null, apiConfig);\n\n  /**\n   * Deletes an OpenTok archive.\n   * <p>\n   * You can only delete an archive which has a status of \"available\" or \"uploaded\". Deleting an\n   * archive removes its record from the list of archives. For an \"available\" archive, it also\n   * removes the archive file, making it unavailable for download.\n   *\n   * @param {String} archiveId The archive ID of the archive you want to delete.\n   *\n   * @param callback {Function} The function to call upon completing the operation. On successfully\n   * deleting the archive, the function is called with no arguments passed in. On failure, an error\n   * object is passed into the function.\n   *\n   * @method #deleteArchive\n   * @memberof OpenTok\n   */\n  this.deleteArchive = archiving.deleteArchive.bind(null, apiConfig);\n\n  /**\n   * Retrieves a List of {@link Archive} objects, representing archives that are both\n   * completed and in-progress, for your API key.\n   *\n   * @param options {Object} An options parameter with three properties:\n   *\n   * <ul>\n   *\n   *   <li>\n   *     <code>count</code> &mdash; The maximum number of archives to return. The default number of\n   *     archives returned is 50 (or fewer, if there are fewer than 50 archives). The method returns\n   *     a maximum of 1000 archives.\n   *   </li>\n   *\n   *   <li>\n   *     <code>offset</code> &mdash; The offset for the first archive to list (starting with the\n   *     first archive recorded as offset 0). 1 is the offset of the archive that started prior\n   *     to the most recent archive. This property is optional; the default is 0.\n   *   </li>\n   *\n   *   <li>\n   *     <code>sessionId</code> &mdash; Specify the ID of a session in order to retrieve archives\n   *     specifically for that session. This property is optional. When no session ID is specified,\n   *     then the method will return archives from any session created with your API key.\n   *   </li>\n   *\n   * </ul>\n   *\n   * <p>If you don't pass in an <code>options</code> argument,\n   * the method returns up to 1000 archives\n   * starting with the first archive recorded.\n   *\n   * @param callback {Function} The function to call upon completing the operation. Two arguments\n   * are passed to the function:\n   *\n   * <ul>\n   *\n   *   <li>\n   *      <code>error</code> &mdash; An error object (if the call to the method fails).\n   *   </li>\n   *\n   *   <li>\n   *       <code>archives</code> &mdash; An array of {@link Archive} objects.\n   *   </li>\n   *\n   * </ul>\n   *\n   * @method #listArchives\n   * @memberof OpenTok\n   */\n  this.listArchives = archiving.listArchives.bind(null, apiConfig);\n\n  /**\n  * Adds a stream to an archive that has the streamMode set to manual.\n  * You can call the method repeatedly with the same stream ID, to toggle\n  * the stream's audio or video in the archive.\n  *\n  * @param archiveId {String} The archive ID.\n  *\n  * @param streamId {String} The stream ID to add to archive.\n  *\n  * @param archiveOptions {Object} An object that has these properties:\n  *\n  * <ul>\n  *\n  *   <li>\n  *     <code>hasAudio</code> &mdash; Whether the composed archive should include the stream's audio\n  *    (true, the default) or not (false).\n  *   </li>\n  *\n  *   <li>\n  *     <code>hasVideo</code> &mdash; Whether the composed archive should include the stream's video\n  *    (true, the default) or not (false).\n  *   </li>\n  *\n  * </ul>\n  *\n  * @param callback {Function} The function to call upon completing the operation. One argument is\n  * passed to the function\n  *\n  * <ul>\n  *\n  *   <li>\n  *      <code>error</code> &mdash; An error object (if the call to the method fails).\n  *   </li>\n  *\n  * </ul>\n  *\n  * @method #addArchiveStream\n  * @memberof OpenTok\n  */\n  this.addArchiveStream = archiving.addArchiveStream.bind(null, apiConfig);\n\n  /**\n  * Removes a stream from a composed archive that has the streamMode set to manual.\n  *\n  * @param archiveId {String} The archive ID.\n  *\n  * @param streamId {String} The stream ID to remove from the archive.\n  *\n  * @param callback {Function} The function to call upon completing the operation. An error is\n  * passed into the function if the call fails.\n  *\n  * @method #removeArchiveStream\n  * @memberof OpenTok\n  */\n  this.removeArchiveStream = archiving.removeArchiveStream.bind(null, apiConfig);\n\n  /**\n   * Sets the layout type for a composed archive. For a description of layout types, see\n   * <a href=\"https://tokbox.com/developer/guides/archiving/layout-control.html\">Customizing\n   * the video layout for composed archives</a>.\n   *\n   * @param archiveId {String} The archive ID.\n   *\n   * @param type {String} The layout type. Set this to \"bestFit\", \"pip\", \"verticalPresentation\",\n   * \"horizontalPresentation\", \"focus\", or \"custom\". For a description of these layout types, see\n   * <a href=\"https://tokbox.com/developer/guides/archiving/layout-control.html\">Customizing\n   * the video layout for composed archives</a>.\n   *\n   * @param stylesheet {String} (Optional) The stylesheet for a custom layout. Set this parameter\n   * if you set <code>type</code> to <code>\"custom\"</code>. Otherwise, leave it undefined or set\n   * to null.\n   *\n   * @param screenshareType {String} (Optional) The layout type to use when\n   * there is a screen-sharing\n   * stream in the session. Note that to use this parameter, you must set the <code>type</code>\n   * parameter to \"bestFit\" and set the <code>stylesheet</code> parameter to <code>null</code>.\n   *\n   * @param callback {Function} The function to call upon completing the operation. Upon error,\n   * an <code>error</code> object is passed into the function. Upon success, the function is called\n   * with no error object passed in.\n   *\n   * @method #setArchiveLayout\n   * @memberof OpenTok\n   */\n  this.setArchiveLayout = function setArchiveLayout(\n    archiveId,\n    type,\n    stylesheet,\n    screenshareType,\n    callback\n  ) {\n    if (typeof archiveId !== 'string') {\n      return callback(new Error('Invalid arguments -- must provide an archiveId string.'));\n    }\n    if (typeof type !== 'string') {\n      return callback(new Error('Invalid arguments -- must provide a type string.'));\n    }\n    if (typeof stylesheet === 'function') {\n      if (callback) {\n        return callback(new Error('Invalid arguments -- stylesheet cannot be a function.'));\n      }\n      callback = stylesheet; // eslint-disable-line no-param-reassign\n    }\n    else if (stylesheet && typeof stylesheet !== 'string') {\n      return callback(new Error('Invalid arguments -- stylesheet must be a string.'));\n    }\n    if (typeof screenshareType === 'function') {\n      if (callback) {\n        return callback(new Error('Invalid arguments -- screenshareType cannot be a function.'));\n      }\n      callback = screenshareType; // eslint-disable-line no-param-reassign\n    }\n    else if (screenshareType && typeof screenshareType !== 'string') {\n      return callback(new Error('Invalid arguments -- screenshareType must be a string.'));\n    }\n    else if (screenshareType && type !== 'bestFit') {\n      return callback(new Error('Invalid arguments -- type must be set to \"bestFit\" if you set screenshareType.'));\n    }\n    if (typeof callback !== 'function') {\n      return callback(new Error('Invalid arguments -- must provide a callback function.'));\n    }\n    return this.client.setArchiveLayout(\n      {\n        archiveId: archiveId,\n        type: type,\n        stylesheet: stylesheet,\n        screenshareType: screenshareType\n      },\n      callback\n    );\n  };\n\n\n  /**\n   * Starts live captions for an OpenTok session.\n   * <p>\n   * The maximum allowed duration is 4 hours, after which the audio captioning will stop without\n   * any effect on the ongoing OpenTok Session. An event will be posted to your callback URL if\n   * provided when starting the captions.\n   * <p>\n   * Each OpenTok session supports only one audio captioning session.\n   *\n   * @param sessionId The session ID of the OpenTok session to archive.\n   *\n   * @param token A valid OpenTok token with role set to Moderator.\n   *\n   * @param options {Object} An optional options object with the following properties (each\n   * of which is optional):\n   * <p>\n   * <ul>\n   *   <li>\n   *     <code>languageCode</code> (String) &mdash; The BCP-47 code for a spoken language used on\n   *     this call. The default value is \"en-US\". The following language codes are supported:\n   *     \"en-AU\" (English, Australia), \"en-GB\" (Englsh, UK), \"es-US\" (English, US),\n   *     \"zh-CN” (Chinese, Simplified), \"fr-FR\" (French), \"fr-CA\" (French, Canadian),\n   *     \"de-DE\" (German), \"hi-IN\" (Hindi, Indian), \"it-IT\" (Italian), \"ja-JP\" (Japanese),\n   *     \"ko-KR\" (Korean), \"pt-BR\" (Portuguese, Brazilian), \"th-TH\" (Thai).\n   *   </li>\n   *   <li>\n   *     <code>maxDuration</code> (Integer) &mdash; The maximum duration for the audio captioning,\n   *     in seconds. The default value is 14,400 seconds (4 hours), the maximum duration allowed.\n   *     The minimum value for maxDuration is 300 (300 seconds, or 5 minutes).\n   *   </li>\n   *   <li>\n   *     <code>partialCaptions</code> (Boolean) &mdash; Whether to enable this to faster captioning\n   *     at the cost of some degree of inaccuracies. The default value is true.\n   *   </li>\n   * </ul>\n   *\n   * For more information on captions, see the\n   * <a href=\"https://tokbox.com/developer/rest/#starting-live-captions\">OpenTok captions</a>\n   * programming guide.\n   *\n   * @param callback {Function} The function to call upon completing the operation. Two arguments\n   * are passed to the function:\n   *\n   * <ul>\n   *   <li>\n   *      <code>error</code> &mdash; An error object (if the call to the method fails).\n   *   </li>\n   *\n   *   <li>\n   *       <code>captionID</code> &mdash; The id of the captions\n   *   </li>\n   *\n   * </ul>\n   *\n   * @method #startCaptions\n   * @memberof OpenTok\n   */\n\n  this.startCaptions = captions.startCaptions.bind(null, apiConfig);\n\n\n  /**\n   * Stops live captions for an OpenTok Session\n   *\n   * @param captionId The session ID of the OpenTok session to archive.\n   *\n   * </ul>\n   *\n   * For more information on captions, see the\n   * <a href=\"https://tokbox.com/developer/rest/#starting-live-captions\">OpenTok captions</a>\n   * programming guide.\n   *\n   * @param callback {Function} The function to call upon completing the operation. Two arguments\n   * are passed to the function:\n   *\n   * <ul>\n   *   <li>\n   *      <code>error</code> &mdash; An error object (if the call to the method fails).\n   *   </li>\n   *\n   *   <li>\n   *       <code>success</code> &mdash; True always\n   *   </li>\n   *\n   * </ul>\n   *\n   * @method #startCaptions\n   * @memberof OpenTok\n   */\n\n  this.stopCaptions = captions.stopCaptions.bind(null, apiConfig);\n\n\n  /**\n   * Retrieves a List of {@link Render} objects, representing any renders in the starting,\n   * started, stopped or failed state, for your API key.\n   *\n   * @param options {Object} An options parameter with three properties:\n   *\n   * <ul>\n   *\n   *   <li>\n   *     <code>count</code> &mdash; The maximum number of renders to return. The default number of\n   *     renders returned is 50 (or fewer, if there are fewer than 50 renders). The method returns\n   *     a maximum of 1000 renders.\n   *   </li>\n   *\n   *   <li>\n   *     <code>offset</code> &mdash; The offset for the first render to list (starting with the\n   *     first render recorded as offset 0). 1 is the offset of the render that started prior\n   *     to the most recent render. This property is optional; the default is 0.\n   *   </li>\n   *\n   *   <li>\n   *     <code>sessionId</code> &mdash; Specify the ID of a session in order to retrieve renders\n   *     specifically for that session. This property is optional. When no session ID is specified,\n   *     then the method will return renders from any session created with your API key.\n   *   </li>\n   *\n   * </ul>\n   *\n   * <p>If you don't pass in an <code>options</code> argument,\n   * the method returns up to 1000 renders, starting with the first render recorded.\n   *\n   * @param callback {Function} The function to call upon completing the operation. Two arguments\n   * are passed to the function:\n   *\n   * <ul>\n   *\n   *   <li>\n   *      <code>error</code> &mdash; An error object (if the call to the method fails).\n   *   </li>\n   *\n   *   <li>\n   *       <code>renders</code> &mdash; An array of {@link Render} objects.\n   *   </li>\n   *\n   * </ul>\n   *\n   * @method #listRenders\n   * @memberof OpenTok\n   */\n  this.listRenders = render.listRenders.bind(null, apiConfig);\n\n  /**\n   * Gets a {@link Render} object for the given render ID.\n   *\n   * @param renderId {String} The render ID.\n   *\n   * @param callback {Function} The function to call upon completing the operation. Two arguments\n   * are passed to the function:\n   * <ul>\n   *   <li><code>error</code> &mdash; An error object (if the call to the method fails). </li>\n   *   <li><code>render</code> &mdash; The {@link Render} object.</li>\n   * </ul>\n   *\n   * @method #getRender\n   * @memberof OpenTok\n   */\n  this.getRender = render.getRender.bind(null, apiConfig);\n\n  /**\n  * Starts an Experience Composer for an OpenTok session. The Experience Composer\n  * instance is represented as a Render object.\n  * For more information, see the\n  * <a href=\"https://tokbox.com/developer/guides/experience-composer/\">Experience Composer developer guide</a>.\n  * <p>\n  * Clients must be actively connected to the OpenTok session for you to successfully start\n  * rendering a session.\n  * <p>\n  *\n  * @param options {Object} An optional options object with the following properties (each\n  * of which is optional):\n  * <p>\n  * <ul>\n  *   <li>\n  *     <code>sessionId</code> (String) &mdash; The ID of a session (generated with the same\n  *    `APIKEY`as specified in the URL) which you wish to start rendering into\n  *   </li>\n  *   <li>\n  *     <code>token</code> (String) &mdash; A valid OpenTok token with a Publisher role and\n  *     (optionally) connection data to be associated with the output stream.\n  *   </li>\n  *\n  *   <li>\n  *     <code>url</code> (String) &mdash; A publically reachable URL controlled by the\n  *     customer and capable of generating the content to be rendered without user intervention.\n  *   </li>\n  *\n  *   <li>\n  *     <code>properties</code> (Object) &mdash; Initial configuration of Publisher properties for\n  *     the composed output stream.\n  *   </li>\n  *\n  *   <li>\n  *     <code>maxDuration</code> (Number) &mdash; The maximum time allowed for the Render, in\n  *     seconds. After this time, the Render will be stopped automatically, if it is still running.\n  *   </li>\n  *\n  *   <li>\n  *     <code>resolution</code> (String) &mdash; Resolution of the display area for the composition.\n  *   </li>\n  *\n  * </ul>\n  *\n  * @param callback {Function} The function to call upon completing the operation. Two arguments\n  * are passed to the function:\n  *\n  * <ul>\n  *\n  *   <li>\n  *      <code>error</code> &mdash; An error object (if the call to the method fails).\n  *   </li>\n  *\n  *   <li>\n  *       <code>render</code> &mdash; The {@link Render} object. This object includes properties\n  *       defining the render, including the render ID.\n  *   </li>\n  *\n  * </ul>\n  *\n  * @method #startRender\n  * @memberof OpenTok\n  */\n  this.startRender = render.startRender.bind(null, apiConfig);\n\n  /**\n   * Stops an Experience Composer that is being rendered.\n   *\n   * @param renderId {String} The ID of the render you want to stop rendering.\n   * @return The {@link Archive} object corresponding to the archive being STOPPED.\n   *\n   * @param callback {Function} The function to call upon completing the operation. Two arguments\n   * are passed to the function:\n   *\n   * <ul>\n   *\n   *   <li>\n   *      <code>error</code> &mdash; An error object (if the call to the method fails).\n   *   </li>\n   *\n   *   <li>\n   *       <code>render</code> &mdash; The {@link Render} object.\n   *   </li>\n   *\n   * </ul>\n   *\n   * @method #stopRender\n   * @memberof OpenTok\n   */\n  this.stopRender = render.stopRender.bind(null, apiConfig);\n\n  /**\n   * Starts a live streaming broadcast. See the\n   * <a href=\"https://tokbox.com/developer/guides/broadcast/live-streaming/\">live\n   * streaming broadcast</a> developer guide.\n   *\n   * @param {String} sessionId The ID of the session to broadcast.\n   *\n   * @param {Object} options An object with the following form:\n   *\n   * <pre><code>{\n   *    outputs: {\n   *      hls: {\n   *        dvr: false,\n   *        lowLatency: false,\n   *      },\n   *      rtmp: [{\n   *        id: \"foo\",\n   *        serverUrl: \"rtmp://myfooserver/myfooapp\",\n   *        streamName: \"myfoostream\"\n   *      },\n   *      {\n   *        id: \"bar\",\n   *        serverUrl: \"rtmp://mybarserver/mybarapp\",\n   *        streamName: \"mybarstream\"\n   *      }]\n   *    },\n   *    maxDuration: 5400,\n   *    resolution: \"640x480\",\n   *    layout: {\n   *      type: \"custom\",\n   *      stylesheet: \"the layout stylesheet (only used with type == custom)\",\n   *      screenshareType: \"the layout type to use when there is a screen-sharing stream (optional)\"\n   *    },\n   *    streamMode: \"manual\"\n   *  }\n   * </code></pre>\n   *\n   * <p>\n   * The <code>options</code> object includes the following properties:\n   *\n   * <ul>\n   *   <li>\n   *      <p>\n   *      <code>outputs</code> (required) &mdash; This object defines the types of\n   *      broadcast streams you want to start. You can include HLS, RTMP, or both\n   *      as broadcast streams. If you include RTMP streaming, you can specify up to five\n   *      target RTMP streams (or just one).\n   *      </p>\n   *      <p>\n   *      For HLS, include a single <code>hls</code> property in the outputs object. This object\n   *      includes the following optional properties:\n   *      <ul>\n   *       <li>\n   *        <code>dvr</code> (Boolean) — Whether to enable <a href=\"https://tokbox.com/developer/guides/broadcast/live-streaming/#dvr\">DVR functionality</a> — rewinding, pausing,\n   *        and resuming — in players that support it (<code>true</code>), or not\n   *        (<code>false</code>, the default). With DVR enabled, the HLS URL will include a\n   *        <code>?DVR</code> query string appended to the end.\n   *       </li>\n   *       <li>\n   *        <code>lowLatency</code> (Boolean) — Whether to enable <a href=\"https://tokbox.com/developer/guides/broadcast/live-streaming/#low-latency\">low-latency mode</a> for the HLS\n   *        stream. Some HLS players do not support low-latency mode. This feature is incompatible\n   *        with DVR mode HLS broadcasts.\n   *       </li>\n   *      </ul>\n   *      The HLS URL is returned in the <code>broadcastUrls</code> as the <code>hls</code>\n   *      property in the {@link Broadcast} object passed into the callback methods of the\n   *      {@link OpenTok#getBroadcast} and {@link OpenTok#listBroadcast} methods.\n   *      </p>\n   *      <p>\n   *      For each RTMP stream, specify <code>serverUrl</code> (the RTMP server URL),\n   *      <code>streamName</code> (the stream name, such as the YouTube Live stream name or\n   *      the Facebook stream key), and (optionally) <code>id</code> (a unique ID for the stream).\n   *      If you specify an ID, it will be included as the <code>id</code> property of the\n   *      {@link Broadcast} object passed into the callback methods of the\n   *      <code>startBroadcast()</code> method and the\n   *      {@link OpenTok#getBroadcast OpenTok.getBroadcast()} method. OpenTok streams\n   *      the session to each RTMP URL you specify. Note that OpenTok live streaming\n   *      supports RTMP and RTMPS.\n   *      </p>\n   *   </li>\n   *   <li>\n   *      <code>maxDuration</code> (optional) &mdash; The maximum duration for the broadcast, in\n   *      seconds. The broadcast will automatically stop when the maximum duration is reached.\n   *      You can set the maximum duration to a value from 60 (60 seconds) to 36000 (10 hours).\n   *      The default maximum duration is 4 hours (14,400 seconds).\n   *   </li>\n   *   <li>\n   *      <code>resolution</code> (optional) &mdash; The resolution of the broadcast: either\n   *      <code>\"640x480\"</code> (SD, the default), <code>\"1280x720\"</code> (HD) or\n   *      <code>\"1920x1080\"</code> (FHD).\n   *   </li>\n   *   </li>\n   *      <code>layout</code> (optional) &mdash; Specify this to assign the initial layout type for\n   *     the broadcast. This object has three properties: <code>type</code>,\n   *     <code>stylesheet</code>, and <code>screenshareType</code>, which are each strings.\n   *     Valid values for the <code>type</code> property are  <code>\"bestFit\"</code>\n   *     (best fit),  <code>\"custom\"</code> (custom),  <code>\"horizontalPresentation\"</code>\n   *     (horizontal presentation),  <code>\"pip\"</code> (picture-in-picture), and\n   *     <code>\"verticalPresentation\"</code> (vertical presentation)). If you specify\n   *     a <code>\"custom\"</code> layout type, set the <code>stylesheet</code> property of\n   *     the <code>layout</code> object to the stylesheet. (For other layout types, do not set\n   *     a <code>stylesheet</code> property.) If you do not specify an initial layout type,\n   *     the broadcast stream uses the Best Fit layout type. Set the <code>screenshareType</code>\n   *     property to the layout type to use when there is a screen-sharing stream in the session.\n   *     (This property is optional.) Note if you set the <code>screenshareType</code> property,\n   *     you must set the <code>type</code> property to \"bestFit\" and leave the\n   *     <code>stylesheet</code> property unset. For more information, see\n   *     <a href=\"https://tokbox.com/developer/guides/broadcast/live-streaming/#configuring-video-layout-for-opentok-live-streaming-broadcasts)\">Configuring\n   *     video layout for OpenTok live streaming broadcasts</a>.\n   *   </li>\n   *   <li>\n   *      <code>streamMode</code> (optional) &mdash; The stream mode for the broadcast. This can be\n   *      set to one of the the following:\n   *\n   *        <ul>\n   *          <li> \"auto\" &mdash; Streams included in the broadcast are selected automatically\n   *          (the default).</li>\n   *\n   *          <li> \"manual\" &mdash; Specify streams to be included based on calls to the\n   *          {@link OpenTok#addBroadcastStream OpenTok.addBroadcastStream()} and\n   *          {@link OpenTok#removeBroadcastStream OpenTok.removeBroadcastStream()} methods.</li>\n   *       </ul>\n   *   </li>\n   *   <li>\n   *        <code>multiBroadcastTag</code> (optional) &mdash; Set this to support multiple\n   *        broadcasts for the same session simultaneously. Set this to a unique string for\n   *        each simultaneous broadcast of an ongoing session.\n   *        Note that the <code>multiBroadcastTag</code> value is not included in the response\n   *        for the methods to list live streaming broadcasts and get information about a live\n   *        streaming broadcast.\n   *   </li>\n   * </ul>\n   *\n   * @param {Function} callback A callback method that takes two parameters:\n   * <code>error</code>, which is set to an Error object on error, and\n   * <code>broadcast</code>, which is set to a {@link Broadcast} object on success.\n   *\n   * @method #startBroadcast\n   * @memberof OpenTok\n   */\n  OpenTok.prototype.startBroadcast = function (sessionId, options, callback) {\n    var client = this.client;\n\n    if (typeof callback !== 'function') {\n      throw new errors.ArgumentError('No callback given to startBroadcast');\n    }\n\n    if (sessionId == null || sessionId.length === 0) {\n      callback(new errors.ArgumentError('No sessionId given to startBroadcast'));\n    }\n    else if (!options || typeof options !== 'object') {\n      callback(new errors.ArgumentError('No options given to startBroadcast'));\n    }\n    else {\n      options.sessionId = sessionId;\n      if (!options.streamMode) {\n        options.streamMode = 'auto';\n      }\n      if (options.outputs && options.outputs.hls) {\n        if (options.outputs.hls.dvr && options.outputs.hls.lowLatency) {\n          callback(new errors.ArgumentError('Cannot set both dvr and lowLatency on HLS'));\n          return;\n        }\n      }\n      client.startBroadcast(options, function (err, json) {\n        if (err) {\n          return callback(new Error('Failed to start broadcast. ' + err));\n        }\n        return callback(null, new Broadcast(client, json));\n      });\n    }\n  };\n\n  /**\n  * Adds a stream to a broadcast that has the streamMode set to manual.\n  * You can call the method repeatedly with the same stream ID, to toggle\n  * the stream's audio or video in the broadcast.\n  *\n  * @param broadcastId {String} The broadcast ID.\n  *\n  * @param streamId {String} The stream ID to add to broadcast.\n  *\n  * @param broadcastOptions {Object} An object that has these properties:\n  *\n  * <ul>\n  *\n  *   <li>\n  *     <code>hasAudio</code> &mdash; Whether the broadcast should include the stream's audio\n  *    (true, the default) or not (false).\n  *   </li>\n  *\n  *   <li>\n  *     <code>hasVideo</code> &mdash; Whether the broadcast should include the stream's video\n  *    (true, the default) or not (false).\n  *   </li>\n  *\n  * </ul>\n  *\n  * @param {Function} callback A callback method that takes two parameters:\n  * <code>error</code>, which is set to an Error object on error, and\n  * <code>broadcast</code>, which is set to a {@link Broadcast} object on success.\n  *\n  * @method #addBroadcastStream\n  * @memberof OpenTok\n  */\n  this.addBroadcastStream = function addBroadcastStream(\n    broadcastId,\n    streamId,\n    broadcastOptions,\n    callback\n  ) {\n    var client = this.client;\n    if (typeof broadcastOptions === 'function') {\n      callback = broadcastOptions;\n      broadcastOptions = {};\n    }\n    if (typeof callback !== 'function') {\n      throw (new errors.ArgumentError('No callback given to addBroadcastStream'));\n    }\n\n    if (broadcastId == null || broadcastId.length === 0) {\n      callback(new errors.ArgumentError('No broadcastId given to addBroadcastStream'));\n    }\n\n    if (streamId == null || streamId.length === 0) {\n      callback(new errors.ArgumentError('No streamId given to addBroadcastStream'));\n    }\n\n    broadcastOptions = {\n      addStream: streamId,\n      hasAudio: broadcastOptions.hasAudio || true,\n      hasVideo: broadcastOptions.hasVideo || true\n    };\n\n    client.patchBroadcast(broadcastId, broadcastOptions, callback);\n  };\n\n  /**\n  * Removes a stream from a broadcast that has the streamMode set to manual.\n  *\n  * @param broadcastId {String} The broadcast ID.\n  *\n  * @param streamId {String} The stream ID to remove from the broadcast.\n  *\n  * @param callback {Function} The function to call upon completing the operation. An error is\n  * passed into the function if the call fails.\n  *\n  * @method #removeBroadcastStream\n  * @memberof OpenTok\n  */\n  this.removeBroadcastStream = function removeBroadcastStream(broadcastId, streamId, callback) {\n    var client = this.client;\n\n    if (typeof callback !== 'function') {\n      throw new errors.ArgumentError('No callback given to removeBroadcastStream');\n    }\n    if (broadcastId == null || broadcastId.length === 0) {\n      callback(new errors.ArgumentError('No archiveId provided'));\n      return;\n    }\n    if (streamId == null || streamId.length === 0) {\n      callback(new errors.ArgumentError('No streamId provided'));\n      return;\n    }\n\n    client.patchBroadcast(broadcastId, { removeStream: streamId }, callback);\n  };\n\n  /**\n   * Stops a live streaming broadcast.\n   *\n   * @param {String} broadcastId The ID of the broadcast.\n   *\n   * @param {Function} callback A callback method that takes two parameters:\n   * <code>error</code>, which is set to an Error object on error, and\n   * <code>broadcast</code>, which is set to a {@link Broadcast} object on success.\n   *\n   * @method #stopBroadcast\n   * @memberof OpenTok\n   */\n  this.stopBroadcast = function stopBroadcast(broadcastId, callback) {\n    var client = this.client;\n    if (broadcastId === null || broadcastId.length === 0) {\n      callback(new errors.ArgumentError('No broadcast ID given'));\n      return;\n    }\n\n    if (typeof callback !== 'function') {\n      throw new errors.ArgumentError('No callback given to stopBroadcast');\n    }\n\n    client.stopBroadcast(broadcastId, function (err, json) {\n      if (err) return callback(new Error('Failed to stop broadcast. ' + err));\n      return callback(null, new Broadcast(client, json));\n    });\n  };\n\n  /**\n   * Returns information about a live streaming broadcast.\n   *\n   * @param {String} broadcastId The ID of the broadcast.\n   *\n   * @param {Function} callback A callback method that takes two parameters:\n   * <code>error</code>, which is set to an Error object on error, and\n   * <code>broadcast</code>, which is set to a {@link Broadcast} object on success.\n   *\n   * @method #getBroadcast\n   * @memberof OpenTok\n   */\n  this.getBroadcast = function getBroadcast(broadcastId, callback) {\n    var client = this.client;\n\n    if (broadcastId === null || broadcastId.length === 0) {\n      callback(new errors.ArgumentError('No broadcast ID given'));\n      return;\n    }\n\n    if (typeof callback !== 'function') {\n      throw new errors.ArgumentError('No callback given to getBroadcast');\n    }\n\n    client.getBroadcast(broadcastId, function (err, json) {\n      if (err) return callback(new Error('Failed to get broadcast. ' + err));\n      return callback(null, new Broadcast(client, json));\n    });\n  };\n\n  /**\n   * Retrieves a List of {@link Broadcast} objects, representing broadcasts that are both\n   * completed and in-progress, for your API key.\n   *\n   * @param options {Object} An options parameter with three properties:\n   *\n   * <ul>\n   *\n   *   <li>\n   *     <code>count</code> &mdash; The maximum number of broadcasts to return.\n   *     The default number of\n   *     broadcasts returned is 50 (or fewer, if there are fewer than 50 broadcasts).\n   *     The method returns a maximum of 1000 broadcasts.\n   *   </li>\n   *\n   *   <li>\n   *     <code>offset</code> &mdash; The offset for the first broadcast to list (starting with the\n   *     first broadcast recorded as offset 0). 1 is the offset of the broadcast that started prior\n   *     to the most recent broadcast. This property is optional; the default is 0.\n   *   </li>\n   *\n   *   <li>\n   *     <code>sessionId</code> &mdash; Specify the ID of a session in order to retrieve broadcasts\n   *     specifically for that session. This property is optional. When no session ID is specified,\n   *     then the method will return broadcasts from any session created with your API key.\n   *   </li>\n   *\n   * </ul>\n   *\n   * <p>If you don't pass in an <code>options</code> argument,\n   * the method returns up to 1000 broadcasts starting with the first broadcast recorded.\n   *\n   * @param callback {Function} The function to call upon completing the operation. Two arguments\n   * are passed to the function:\n   *\n   * <ul>\n   *\n   *   <li>\n   *      <code>error</code> &mdash; An error object (if the call to the method fails).\n   *   </li>\n   *\n   *   <li>\n   *       <code>broadcasts</code> &mdash; An array of {@link Broadcast} objects.\n   *   </li>\n   *\n   * </ul>\n   *\n   * @method #listBroadcasts\n   * @memberof OpenTok\n   */\n  this.listBroadcasts = function listBroadcasts(options, callback) {\n    var query = [];\n    var queryString = null;\n    if (typeof options === 'function') {\n      callback = options;\n      options = {};\n    }\n    if (typeof callback !== 'function') {\n      throw new errors.ArgumentError('No callback given to listBroadcasts');\n    }\n    if (options.offset) {\n      query.push('offset=' + parseInt(options.offset, 10));\n    }\n    if (options.count) {\n      query.push('count=' + parseInt(options.count, 10));\n    }\n    if (options.sessionId) {\n      query.push('sessionId=' + options.sessionId);\n    }\n    queryString = query.join('&');\n    return this.client.listBroadcasts(\n      queryString,\n      function cb(err, json, totalCount) {\n        if (err) {\n          return callback(err);\n        }\n        return callback(null, json, totalCount);\n      }\n    );\n  };\n\n  /**\n   * Sets (or updates) the layout of the broadcast. See\n   * <a href=\"https://tokbox.com/developer/guides/broadcast/live-streaming/#configuring-video-layout-for-opentok-live-streaming-broadcasts\">\n   * Configuring video layout for OpenTok live streaming broadcasts</a>.\n   *\n   * @param {String} broadcastId The ID of the broadcast.\n   *\n   * @param type {String} The layout type. Set this to \"bestFit\", \"pip\", \"verticalPresentation\",\n   * \"horizontalPresentation\", \"focus\", or \"custom\". For a description of these layout types, see\n   * <a href=https://tokbox.com/developer/guides/broadcast/live-streaming/#configuring-video-layout-for-opentok-live-streaming-broadcasts> Configuring\n   * layout for OpenTok live streaming broadcasts</a>.\n   *\n   * @param stylesheet {String} (Optional) The stylesheet for a custom layout. Set this\n   * parameter if you set <code>type</code> to \"custom\". Otherwise, leave it undefined or\n   * set to <code>null</code>.\n   *\n   * @param screenshareType {String} (Optional) The layout type to use when there is\n   * a screen-sharing stream in the session. Note that to use this parameter, you must set\n   * the <code>type</code> parameter to \"bestFit\" and set the <code>stylesheet</code>\n   * parameter to <code>null</code>.\n   *\n   * @param callback {Function} The function to call upon completing the operation. Upon error,\n   * an Error object is passed into the function. Upon success, the function is called\n   * with no Error object passed in.\n   *\n   * @method #setBroadcastLayout\n   * @memberof OpenTok\n   */\n  this.setBroadcastLayout = function setBroadcastLayout(\n    broadcastId,\n    type,\n    stylesheet,\n    screenshareType,\n    callback\n  ) {\n    if (typeof broadcastId !== 'string') {\n      return callback(new Error('Invalid arguments -- must provide an broadcastId string.'));\n    }\n    if (typeof type !== 'string') {\n      return callback(new Error('Invalid arguments -- must provide a type string.'));\n    }\n    if (typeof stylesheet === 'function') {\n      if (callback) {\n        return callback(new Error('Invalid arguments -- stylesheet cannot be a function.'));\n      }\n      callback = stylesheet; // eslint-disable-line no-param-reassign\n    }\n    else if (stylesheet && typeof stylesheet !== 'string') {\n      return callback(new Error('Invalid arguments -- stylesheet must be a string.'));\n    }\n    if (typeof screenshareType === 'function') {\n      if (callback) {\n        return callback(new Error('Invalid arguments -- screenshareType cannot be a function.'));\n      }\n      callback = screenshareType; // eslint-disable-line no-param-reassign\n    }\n    else if (screenshareType && typeof screenshareType !== 'string') {\n      return callback(new Error('Invalid arguments -- screenshareType must be a string.'));\n    }\n    else if (screenshareType && type !== 'bestFit') {\n      return callback(new Error('Invalid arguments -- type must be set to \"bestFit\" if you set screenshareType.'));\n    }\n    if (typeof callback !== 'function') {\n      return callback(new Error('Invalid arguments -- must provide a callback function.'));\n    }\n    return this.client.setBroadcastLayout(\n      {\n        broadcastId: broadcastId,\n        type: type,\n        stylesheet: stylesheet,\n        screenshareType: screenshareType\n      },\n      callback\n    );\n  };\n\n  /**\n  * Sends audio from a Vonage Video API session to a WebSocket.\n  * See the <a href=\"https://tokbox.com/developer/guides/audio-connector/\">Audio Connector</a>\n  * developer guide.\n  *\n  * @param sessionId {String} (required) The OpenTok session ID that includes the OpenTok streams you want to\n  * include in the WebSocket stream\n  *\n  * @param token {String} (required) The OpenTok token to be used for the Audio Streamer connection to the.\n  * OpenTok session. You can add token data to identify that the connection is the Audio Streamer\n  * endpoint or for other identifying data\n  *\n  * @param websocketUri {String} (required) A publicly reachable WebSocket URI to be used for the destination\n  * of the audio stream (such as \"wss://service.com/ws-endpoint\").\n  *\n  * @param options {Object} An optional options object with the following properties\n  * (all of which are optional):\n  * <p>\n  * <ul>\n  *   <li>\n  *     <code>streams</code> (Array) &mdash; An array of stream IDs for the OpenTok streams\n  *     you want to include in the WebSocket stream. If you omit this property, all streams\n  *     in the session will be included.\n  *   </li>\n  *   <li>\n  *     <code>headers</code> (Object) &mdash; An object of key-value pairs of headers to be\n  *     sent to your WebSocket server with each message, with a maximum length of 512 bytes.\n  *   </li>\n  * </ul>\n  *\n  * @param callback {Function} The function to call upon completing the operation. Upon error,\n  * an <code>error</code> object is passed in as the first parameter of the function.\n  * Upon success, the function is called with no error object passed in (as the first parameter)\n  * and the second parameter is an object with the following properties:\n  *\n  *   <ul>\n  *     <li>\n  *       <code>id</code> -- A unique ID identifying the Audio Streamer WebSocket connection.\n  *     </li>\n  *     <li>\n  *       <code>connectionId</code> -- The OpenTok connection ID for the Audio Streamer\n  *       WebSocket connection in the OpenTok session.\n  *     </li>\n  *   </ul>\n  *\n  * @method #websocketConnect\n  * @memberof OpenTok\n  */\n  this.websocketConnect = function websocketConnect(\n    sessionId,\n    token,\n    websocketUri,\n    options,\n    callback\n  ) {\n    var body;\n\n    if (typeof options === 'function') {\n      callback = options;\n      options = {};\n    }\n\n    options = options || {};\n\n    if (typeof callback !== 'function') {\n      throw new errors.ArgumentError('No callback given to websocketConnect');\n    }\n\n    if (sessionId == null || sessionId.length === 0) {\n      callback(new Error('No sessionId given to websocketConnect'));\n      return;\n    }\n\n    if (token == null || token.length === 0) {\n      callback(new Error('No token given to websocketConnect'));\n      return;\n    }\n\n    if (websocketUri == null || websocketUri.length === 0) {\n      callback(new Error('No websocketUri given to websocketConnect'));\n      return;\n    }\n\n    body = {\n      sessionId: sessionId,\n      token: token,\n      websocket: {\n        uri: websocketUri\n      }\n    };\n\n    if (_.isArray(options.streams)) {\n      body.websocket.streams = options.streams;\n    }\n\n    if (_.isObject(options.headers)) {\n      body.websocket.headers = options.headers;\n    }\n\n    if (options.bidirectional) {\n      body.websocket.bidirectional = options.bidirectional;\n    }\n\n    this.client.websocketConnect(body, function (err, json) {\n      if (err) return callback(new Error('Error connecting to websocket: ' + err.message));\n      return callback(null, json);\n    });\n  };\n\n  /**\n   * Sets the layout class list for streams in a session. Layout classes are used in\n   * the layout for composed archives and live streaming broadcasts. For more information, see\n   * <a href=\"https://tokbox.com/developer/guides/archiving/layout-control.html\">Customizing\n   * the video layout for composed archives</a> and\n   * <a href=\"https://tokbox.com/developer/guides/broadcast/live-streaming/#configuring-video-layout-for-opentok-live-streaming-broadcasts\">Configuring\n   * video layout for OpenTok live streaming broadcasts</a>.\n   *\n   * <p>\n   * You can set the initial layout class list for streams published by a client when you generate\n   * used by the client. See the {@link OpenTok#generateToken OpenTok.generateToken()} method.\n   *\n   * @param sessionId {String} The session ID of the session the streams belong to.\n   *\n   * @param classListArray {Array} (Optional) An array defining the class lists to apply to\n   * streams. Each element in the array is an object with two properties: <code>id</code> and\n   * <code>layoutClassList</code>. The <code>id</code> property is the stream ID (a String),\n   * and the <code>layoutClassList</code> is an array of class names (Strings) to apply to the\n   * stream. Set <code>layoutClassList</code> to an empty array to clear the layout class list for\n   * a stream. For example, this <code>streamClassArray</code> array sets the layout class list for\n   * three streams:\n   * <p>\n   * <pre>\n   * const classListArray = [\n   *   { id: '7b09ec3c-26f9-43d7-8197-f608f13d4fb6', layoutClassList: ['focus'] },\n   *   { id: '567bc941-6ea0-4c69-97fc-70a740b68976', layoutClassList: ['top'] },\n   *   { id: '307dc941-0450-4c09-975c-705740d08970', layoutClassList: ['bottom'] }\n   * ];\n   * </pre>\n   *\n   * @param callback {Function} The function to call upon completing the operation. Upon error,\n   * an <code>error</code> object is passed into the function. Upon success, the function is called\n   * with no error object passed in.\n   *\n   * @method #setStreamClassLists\n   * @memberof OpenTok\n   */\n  this.setStreamClassLists = function setStreamClassLists(\n    sessionId,\n    classListArray,\n    callback\n  ) {\n    var i;\n    var j;\n    var layoutObj;\n\n    if (typeof sessionId !== 'string') {\n      return callback(new Error('Invalid arguments -- must provide an sessionId string.'));\n    }\n    if (!Array.isArray(classListArray)) {\n      return callback(new Error('Invalid arguments -- must provide a streamClassArray array.'));\n    }\n\n    for (i = 0; i < classListArray.length; i += 1) {\n      layoutObj = classListArray[i];\n      if (typeof layoutObj.id !== 'string') {\n        return callback(new Error('Invalid arguments -- each element in the streamClassArray '\n              + 'must have an id string.'));\n      }\n      if (!Array.isArray(layoutObj.layoutClassList)) {\n        return callback(new Error('Invalid arguments -- each element in the streamClassArray '\n              + 'must have a layoutClassList array.'));\n      }\n      for (j = 0; j < layoutObj.layoutClassList.length; j += 1) {\n        if (typeof layoutObj.layoutClassList[j] !== 'string') {\n          return callback(new Error('Invalid arguments -- each element in the layoutClassList '\n                + 'array must be a string (defining class names).'));\n        }\n      }\n    }\n\n    if (typeof callback !== 'function') {\n      return callback(new Error('Invalid arguments -- must provide a callback function.'));\n    }\n\n    return this.client.setStreamClassLists(sessionId, classListArray, callback);\n  };\n\n  /**\n   * Sends a signal to all the connections in a session or to a specific one.\n   * <p>\n   * Clients must be actively connected to the OpenTok session for you to successfully send\n   * a signal to them.\n   * <p>\n   * For more information, see the\n   * <a href=\"https://www.tokbox.com/developer/guides/signaling\">OpenTok signaling</a>\n   * programming guide.\n   *\n   * @param sessionId The session ID of the OpenTok session where you want to send the signal.\n   *\n   * @param connectionId The connection ID of a client connected to the session. Leave\n   * this empty if you want to send a signal to all connections in the session.\n   *\n   * @param payload An object with optional <code>data</code> and <code>type</code> properties:\n   *\n   * <p>\n   *\n   * <ul>\n   *   <li>\n   *      <code>data</code> &mdash; The data to send. The limit to the length of data string\n   *      is 8kB. Do not set the data string to null or undefined.\n   *   </li>\n   *\n   *   <li>\n   *      <code>type</code> &mdash; The type of the signal. Clients can use the type to filter\n   *      signals. The maximum length of the type string is 128 characters.\n   *   </li>\n   * </ul>\n   *\n   * @param callback {Function} The callback function invoked when the call to the method\n   * succeeds or fails. If the call fails, an error object is passed into the callback function.\n   *\n   * @method #signal\n   * @memberof OpenTok\n   */\n  this.signal = signaling.signal.bind(null, apiConfig);\n\n  /**\n   * Disconnects a participant from an OpenTok session.\n   *\n   * This is the server-side equivalent to the\n   * <a href=\"https://www.tokbox.com/developer/guides/moderation/js/#force_disconnect\">\n   * forceDisconnect() method in OpenTok.js</a>\n   *\n   * @param sessionId The session ID for the OpenTok session that the client you want\n   * to disconnect is connected to.\n   *\n   * @param connectionId The connection ID of the client you want to disconnect.\n   *\n   * @param callback {Function} The function to call upon completing the operation. Two arguments\n   * are passed to the function:\n   *\n   * <ul>\n   *\n   *   <li>\n   *      <code>error</code> &mdash; An error object (if the call to the method fails).\n   *   </li>\n   *\n   * </ul>\n   *\n   * @method #forceDisconnect\n   * @memberof OpenTok\n   */\n  this.forceDisconnect = moderation.forceDisconnect.bind(null, apiConfig);\n\n  /**\n   * Gets info about a stream. The stream must be an active stream in an OpenTok session.\n   *\n   * @param sessionId {String} The session ID of the OpenTok session containing the stream.\n   *\n   * @param options {String} The stream ID.\n   *\n   * @param callback {Function} The function to call upon completing the operation. Two arguments\n   * are passed to the function:\n   *\n   * <ul>\n   *\n   *   <li>\n   *      <code>error</code> &mdash; An error object (if the call to the method fails). This is\n   *      set to null if there is no error. Calling this method results in an error if you pass in\n   *      an invalid stream ID or an invalid session ID.\n   *   </li>\n   *\n   *   <li>\n   *       <code>stream</code> &mdash; The {@link Stream} object. This object includes properties\n   *       defining the stream. This is undefined if there is an error.\n   *   </li>\n   *\n   * </ul>\n   *\n   * @method #getStream\n   * @memberof OpenTok\n   */\n  this.getStream = function getStream(sessionId, streamId, callback) {\n    if (!sessionId || typeof sessionId !== 'string') {\n      return callback(new Error('Invalid arguments -- must provide a sessionId string.'));\n    }\n    if (!streamId || typeof streamId !== 'string') {\n      return callback(new Error('Invalid arguments -- must provide a streamId string.'));\n    }\n    if (!callback || typeof callback !== 'function') {\n      return callback(new Error('Invalid arguments -- must provide a callback function.'));\n    }\n    return this.client.getStream(sessionId, streamId, function cb(err, json) {\n      if (err) {\n        return callback(err);\n      }\n      return callback(null, new Stream(json));\n    });\n  };\n\n  /**\n   * Send DTMF digits to all participants in an active OpenTok session or to a specific client\n   * connected to that session.\n   *\n   * @param sessionId The session ID corresponding to the session that will receive the DTMF string.\n   *\n   * @param connectionId The connection connection ID of the client you are sending the DTMF\n   * signal to. Leave this empty to send a DTMF signal to all clients connected to the session.\n   *\n   * @param digits This is the string of DTMF digits to send. This can include 0-9, '*', '#', and\n   * 'p'. A p indicates a pause of 500ms (if you need to add a delay in sending the digits).\n   *\n   * @param callback {Function} The function to call upon completing the operation. One argument\n   * is passed to the function:\n   *\n   * <ul>\n   *\n   *   <li>\n   *      <code>error</code> &mdash; An error object (if the call to the method fails). This is\n   *      set to null if there is no error.\n   *   </li>\n   *\n   * </ul>\n   *\n   * @method #playDTMF\n   * @memberof OpenTok\n   */\n\n  this.playDTMF = function playDTMF(sessionId, connectionId, digits, callback) {\n    if (!sessionId || typeof sessionId !== 'string') {\n      return callback(new Error('Invalid arguments -- must provide a sessionId string.'));\n    }\n    if (!!connectionId && typeof connectionId !== 'string') {\n      return callback(new Error('Invalid arguments -- connectionId must be a string.'));\n    }\n    if (!callback || typeof callback !== 'function') {\n      return callback(new Error('Invalid arguments -- must provide a callback function.'));\n    }\n    return this.client.playDTMF(\n      {\n        sessionId: sessionId,\n        connectionId: connectionId,\n        digits: digits\n      },\n      function cb(err) {\n        if (err) {\n          return callback(err);\n        }\n        return callback(null);\n      }\n    );\n  };\n\n  /**\n   * Retrieves a List of {@link Stream} objects, representing current streams in a session.\n   *\n   * @param sessionId {String} The session ID of the OpenTok session containing the streams.\n   *\n   * @param callback {Function} The function to call upon completing the operation. Two arguments\n   * are passed to the function:\n   *\n   * <ul>\n   *\n   *   <li>\n   *      <code>error</code> &mdash; An error object (if the call to the method fails). This is\n   *      set to null if there is no error. Calling this method results in an error if you pass in\n   *      an invalid session ID.\n   *   </li>\n   *\n   *   <li>\n   *       <code>streams</code> &mdash; An array of {@link Stream} objects. Each Stream object\n   *       includes properties defining the stream. This is undefined if there is an error.\n   *   </li>\n   *\n   * </ul>\n   *\n   * @method #listStreams\n   * @memberof OpenTok\n   */\n  this.listStreams = function listStreams(sessionId, callback) {\n    if (!sessionId || typeof sessionId !== 'string') {\n      return callback(new Error('Invalid arguments -- must provide a sessionId string.'));\n    }\n    if (!callback || typeof callback !== 'function') {\n      return callback(new Error('Invalid arguments -- must provide a callback function.'));\n    }\n    return this.client.listStreams(sessionId, function cb(err, json) {\n      if (err) {\n        return callback(err);\n      }\n      return callback(null, json);\n    });\n  };\n\n  /**\n   * Force a specific stream in a session to mute audio.\n   *\n   * @param sessionId {String} The session ID.\n   *\n   * @param streamId {String} The stream ID.\n   *\n   * @param callback {Function} The function to call upon completing the operation.\n   * One argument is passed to the function <code>error</code> &mdash; an error\n   * indicating the call failed. This is set to null if the call succeeds.\n   *\n   * @see {@link OpenTok#forceMuteAll OpenTok.forceMuteAll()}\n   *\n   * @method #forceMuteStream\n   * @memberof OpenTok\n   */\n\n  this.forceMuteStream = function forceMuteStream(\n    sessionId,\n    streamId,\n    callback\n  ) {\n    if (!sessionId || typeof sessionId !== 'string') {\n      return callback(new Error('Invalid arguments -- must provide a sessionId string.'));\n    }\n    if (!!streamId && typeof streamId !== 'string') {\n      return callback(new Error('Invalid arguments -- streamId must be a string.'));\n    }\n    if (!callback || typeof callback !== 'function') {\n      return callback(new Error('Invalid arguments -- must provide a callback function.'));\n    }\n    return this.client.forceMuteStream(\n      {\n        sessionId: sessionId,\n        streamId: streamId\n      },\n      function cb(err) {\n        if (err) {\n          return callback(err);\n        }\n        return callback(null);\n      }\n    );\n  };\n\n  /**\n   * Forces all streams (except for an optional array of streams) in a session\n   * to mute published audio.\n   * <p>\n   * In addition to existing streams, any streams that are published after the call\n   * to this method are published with audio muted. You can remove the mute state of\n   * a session by calling the {@link OpenTok#disableForceMute OpenTok.disableForceMute()} method.\n   *\n   * @param sessionId The session ID.\n   *\n   * @param opts An object that contains the following properties:\n   *\n   * <ul>\n   *   <li>\n   *     <code>excudedStreamIds</code> (Array of strings) &mdash; An array of\n   *     stream IDs to exlude from being muted. This is optional. If you do not\n   *     set this property, all arrays in the session will be muted.\n   *   </li>\n   * </ul>\n   *\n   * @param callback {Function} The function to call upon completing the operation.\n   * One argument is passed to the function <code>error</code> &mdash; an error\n   * indicating the call failed. This is set to null if the call succeeds.\n   *\n   * @see {@link OpenTok#disableForceMute OpenTok.disableForceMute()}\n   * @see {@link OpenTok#forceMuteStream OpenTok.forceMuteStream()}\n   *\n   * @method #forceMuteAll\n   * @memberof OpenTok\n   */\n\n  this.forceMuteAll = function forceMuteAll(sessionId, options, callback) {\n    if (!sessionId || typeof sessionId !== 'string') {\n      return callback(new Error('Invalid arguments -- must provide a sessionId string.'));\n    }\n\n    if (_.isFunction(options)) {\n      // shift arguments if the opts is left out\n      callback = options;\n      options = {};\n    }\n\n    if (options.excudedStreamIds && !_.isArray(options.excudedStreamIds)) {\n      return callback(new Error('Invalid arguments -- excudedStreamIds must be array.'));\n    }\n\n    if (!callback || typeof callback !== 'function') {\n      return callback(new Error('Invalid arguments -- must provide a callback function.'));\n    }\n\n    return this.client.forceMuteAll(\n      {\n        sessionId: sessionId,\n        options: options\n      },\n      function cb(err) {\n        if (err) {\n          return callback(err);\n        }\n        return callback(null);\n      }\n    );\n  };\n\n  /**\n   * Disables the active mute state of the session. After you call this method, new streams\n   * published to the session will no longer have audio muted.\n   * <p>\n   * After you call the {@link OpenTok#forceMuteAll OpenTok.forceMuteAll()} method,\n   * any streams published after the call are published with audio muted. When you call the\n   * <code>OpenTok.disableForceMute()</code> method, future streams published to the session\n   * are not muted (but any existing muted streams remain muted).\n   *\n   * @param sessionId The session ID.\n   *\n   * @param callback {Function} The function to call upon completing the operation.\n   * One argument is passed to the function <code>error</code> &mdash; an error\n   * indicating the call failed. This is set to null if the call succeeds.\n   *\n   * @method #disableForceMute\n   * @memberof OpenTok\n   */\n\n  this.disableForceMute = function disableForceMute(sessionId, callback) {\n    if (!sessionId || typeof sessionId !== 'string') {\n      return callback(new Error('Invalid arguments -- must provide a sessionId string.'));\n    }\n\n    if (!callback || typeof callback !== 'function') {\n      return callback(new Error('Invalid arguments -- must provide a callback function.'));\n    }\n\n    return this.client.disableForceMute(\n      {\n        sessionId: sessionId\n      },\n      function cb(err) {\n        if (err) {\n          return callback(err);\n        }\n        return callback(null);\n      }\n    );\n  };\n\n  this.registerCallback = callbacks.registerCallback.bind(null, apiConfig);\n\n  this.unregisterCallback = callbacks.unregisterCallback.bind(null, apiConfig);\n\n  this.listCallbacks = callbacks.listCallbacks.bind(null, apiConfig);\n};\n\n/**\n  * Dials a SIP gateway to input an audio-only stream into your OpenTok Session. Part of the SIP\n  * feature.\n  *\n  * @param sessionId The session ID corresponding to the session to which the user will connect.\n  *\n  * @param token The token for the session ID with which the SIP user will use to connect.\n  *\n  * @param sipUri The sip URI the SIP Interconnect feature will dial.\n  *\n  * @param options {Object} An optional options object with the following properties\n  * (all of which are optional):\n  * <p>\n  * <ul>\n  *   <li>\n  *     <code>headers</code> (Object) &mdash; Custom headers to be added to the SIP INVITE\n  *     request iniated from OpenTok to the third-party SIP platform.\n  *   </li>\n  *   <li>\n  *     <code>auth</code> (Object) &mdash; The credentials to be used for HTTP Digest authentication\n  *     in case this is required by the third-party SIP platform.\n  *   <ul>\n  *     <li> \"username\" -- The username to be used in the SIP INVITE.\n  *     <li> \"password\" -- The password to be used in the SIP INVITE.\n  *   </ul>\n  *   </li>\n  *   <li>\n  *     <code>secure</code> (Boolean) &mdash; Whether the SIP media streams should be transmitted\n  *     encrypted or not.\n  *   </li>\n  *   <li>\n  *     <code>from</code> (String) &mdash; The number or string that will be sent\n  *     to the final SIP number as the caller. It must be a string in the form of\n  *     <code>from@example.com</code>, where <code>from</code> can be a string or a number.\n  *     If <code>from</code> is set to a number (for example,\n  *     <code>\"14155550101@example.com\"</code>),\n  *     it will show up as the incoming number on PSTN phones.\n  *     If <code>from</code> is undefined or set to a string (for example,\n  *     <code>\"joe@example.com\"</code>),\n  *     <code>+00000000</code> will show up as the incoming number on PSTN phones.\n  *   </li>\n  *   <li>\n  *     <code>video</code> (Boolean) &mdash;  A Boolean flag that indicates whether the SIP call\n  *     will include video (<code>true</code>) or not (<code>false</code>, the default). With video\n  *     included, the SIP client's video is included in the OpenTok stream that is sent to\n  *     the OpenTok session. The SIP client will receive a dynamic composed video stream\n  *     of the published streams in the OpenTok session. This is a beta feature.\n  *   </li>\n  *   <li>\n  *     <code>observeForceMute</code> (optional) Whether the SIP end point observes\n  *     force mute action by other clients like moderators (<code>true</code>)\n  *     or not (<code>false</code>, the default). See\n  *     <a href=\"https://tokbox.com/developer/guides/moderation/#force_mute\">Muting\n  *     the audio of streams in a session</a>.\n  *   </li>\n  *   <li>\n  *     <code>streams</code> (optional) The stream IDs of the participants'\n  *     which will be subscribed by the SIP participant. If not provided, all\n  *     streams in session will be selected.\n  *   </li>\n  * </ul>\n  *\n  * @return A {@link SipInterconnect} object with the following properties:\n  *   <ul>\n  *     <li> <code>id</code> -- The unique conference ID of the SIP call</li>\n  *     <li> <code>connectionId</code> -- The connection ID of the audio-only stream\n  *       representing the SIP call</li>\n  *     <li> <code>streamId</code> -- The stream ID of the audio-only stream representing\n  *       the SIP call</li>\n  *   </ul>\n  */\nOpenTok.prototype.dial = function (sessionId, token, sipUri, options, callback) {\n  var self = this;\n  var body;\n\n  if (typeof options === 'function') {\n    callback = options;\n    options = {};\n  }\n  options = options || {};\n  if (typeof callback !== 'function') {\n    throw new errors.ArgumentError('No callback given to dial');\n  }\n  if (sessionId == null || sessionId.length === 0) {\n    callback(new errors.ArgumentError('No session ID given'));\n    return;\n  }\n  if (token == null || token.length === 0) {\n    callback(new errors.ArgumentError('No token given'));\n    return;\n  }\n  if (sipUri == null || sipUri.length === 0) {\n    callback(new errors.ArgumentError('No SIP URI given'));\n    return;\n  }\n  body = {\n    sessionId: sessionId,\n    token: token,\n    sip: {\n      uri: sipUri\n    }\n  };\n  if (_.isObject(options.headers) && !_.isArray(options.headers)) {\n    body.sip.headers = options.headers;\n  }\n  if (_.isObject(options.auth) && !_.isArray(options.auth)) {\n    body.sip.auth = options.auth;\n  }\n  if (options.secure) {\n    body.sip.secure = !!options.secure;\n  }\n\n  if (options.from) {\n    body.sip.from = String(options.from);\n  }\n\n  if (options.video) {\n    body.sip.video = !!options.video;\n  }\n\n  if (options.observeForceMute) {\n    body.sip.observeForceMute = !!options.observeForceMute;\n  }\n\n  if (options.streams) {\n    body.sip.streams = options.streams;\n  }\n\n  this.client.dial(body, function (err, json) {\n    if (err) return callback(new Error('Failed to dial endpoint. ' + err));\n    return callback(null, new SipInterconnect(self, json));\n  });\n};\n\n/**\n * Creates a new OpenTok session. The session is passed as {@link Session} object into the callback\n * function. The <code>sessionId</code> property is the session ID, which uniquely identifies\n * the session. On error, an Error object is passed into the callback function.\n * <p>\n * For example, when using the OpenTok.js library, use the session ID when calling the\n * <a href=\"http://tokbox.com/opentok/libraries/client/js/reference/OT.html#initSession\">\n * OT.initSession()</a> method (to initialize an OpenTok session).\n * <p>\n * OpenTok sessions do not expire. However, authentication tokens do expire (see the\n * generateToken(String, TokenOptions) method). Also note that sessions cannot\n * explicitly be destroyed.\n * <p>\n * A session ID string can be up to 255 characters long.\n *\n * You can also create a session using the\n * <a href=\"http://www.tokbox.com/opentok/api/#session_id_production\">OpenTok REST API</a>\n * or by logging in to your <a href=\"https://tokbox.com/account\">TokBox account</a>.\n *\n * @param   {Object} options\n * This object defines options for the session, including the following properties (both of which\n * are optional):\n *\n * <ul>\n *     <li><code>location</code> (String) &mdash;\n * An IP address that the OpenTok servers will use to situate the session in the global\n * OpenTok network. If you do not set a location hint, the OpenTok servers will be based on\n * the first client connecting to the session.\n * </li>\n *\n *     <li><code>e2ee</code> (Boolean) &mdash;\n * Determines whether to enable <a href=\"https://tokbox.com/developer/guides/end-to-end-encryption/\">\n`end-to-end encryption</a>\nfor the OpenTok session. Set to <code>\"true\"</code> or <code>\"false\"</code>.\n * </li>\n *\n *     <li><code>mediaMode</code> (String) &mdash;\n * Determines whether the session will transmit streams using the OpenTok Media Router\n * (<code>\"routed\"</code>) or not (<code>\"relayed\"</code>). By default, the setting is\n * <code>\"relayed\"</code>.\n * <p>\n * With the <code>mediaMode</code> parameter set to <code>\"relayed\"</code>, the session\n * will attempt to transmit streams directly between clients. If clients cannot connect due to\n * firewall restrictions, the session uses the OpenTok TURN server to relay audio-video\n * streams.\n * <p>\n * The <a href=\"https://tokbox.com/opentok/tutorials/create-session/#media-mode\" target=\"_top\">\n * OpenTok Media Router</a> provides the following benefits:\n *\n *      <li><code>archiveMode</code> (String) &mdash;\n * Whether the session is automatically archived (<code>\"always\"</code>) or not\n * (<code>\"manual\"</code>). By default, the setting is <code>\"manual\"</code>, and you must call the\n * <code>StartArchive()</code> method of the OpenTok object to start archiving. To archive the\n * session (either automatically or not), you must set the <code>mediaMode</code> parameter to\n * <code>\"routed\"</code>.\n *\n *     <li><code>archiveName</code> (String) &mdash; The name of the archives to be used in\n *     auto-archived sessions. The length of the archive name can be up to 80 chars.\n *     Due to encoding limitations the following special characters are translated to\n *     a colon (:) character: ~, -, _.</li>\n *\n *     <li><code>archiveResolution</code> (Enum) &mdash; The resolution of archives in an auto-archived session.\n *     Valid values are \"480x640\", \"640x480\", \"720x1280\", \"1280x720\", \"1080x1920\", and \"1920x1080\".\n *     </li>\n *\n * <ul>\n *   <li>The OpenTok Media Router can decrease bandwidth usage in multiparty sessions.\n *       (When the <code>mediaMode</code> parameter is set to <code>\"relayed\"</code>,\n *       each client must send a separate audio-video stream to each client subscribing to\n *       it.)</li>\n *   <li>The OpenTok Media Router can improve the quality of the user experience through\n *     <a href=\"https://tokbox.com/platform/fallback\" target=\"_top\">audio fallback and video\n *     recovery</a>. With these features, if a client's connectivity degrades to a degree that\n *     it does not support video for a stream it's subscribing to, the video is dropped on\n *     that client (without affecting other clients), and the client receives audio only.\n *     If the client's connectivity improves, the video returns.</li>\n *   <li>The OpenTok Media Router supports the\n *     <a href=\"https://tokbox.com/opentok/tutorials/archiving\" target=\"_top\">archiving</a>\n *     feature, which lets you record, save, and retrieve OpenTok sessions.</li>\n * </ul>\n * </li>\n * </ul>\n *\n * @param   {Function}   callback\n * The function that is called when the operation completes. This function is passed two arguments:\n *\n * <ul>\n *   <li>\n *      <code>error</code> &mdash; On failiure, this parameter is set to an Error object.\n *      Check the error message for details. On success, this is set to null.\n *   </li>\n *   <li>\n *      <code>session</code> &mdash; On sucess, this parameter is set to a {@link Session} object.\n *      The sessionId property of this object is session ID of the session. On error, this parameter\n *      is not set.\n *   </li>\n * </ul>\n */\nOpenTok.prototype.createSession = function (opts, callback) {\n  var backupOpts;\n  var self = this;\n  var mediaModeToParam;\n\n  if (_.isFunction(opts)) {\n    // shift arguments if the opts is left out\n    callback = opts;\n    opts = {};\n  }\n  else if (!_.isFunction(callback)) {\n    // one of the args has to be a function, or we bail\n    throw new Error('Invalid arguments when calling createSession, must provide a callback');\n  }\n\n  // whitelist the keys allowed\n  _.pick(\n    _.defaults(opts, { mediaMode: 'relayed', archiveMode: 'manual' }),\n    'mediaMode',\n    'archiveMode',\n    'location'\n  );\n  if (opts.mediaMode !== 'routed' && opts.mediaMode !== 'relayed') {\n    opts.mediaMode = 'relayed';\n  }\n  if (opts.archiveMode !== 'manual' && opts.archiveMode !== 'always') {\n    opts.archiveMode = 'manual';\n  }\n\n  if (opts.archiveMode === 'always' && opts.mediaMode !== 'routed') {\n    return process.nextTick(function () {\n      callback(new Error('A session with always archive mode must also have the routed media mode.'));\n    });\n  }\n  if ('location' in opts && !net.isIPv4(opts.location)) {\n    return process.nextTick(function () {\n      callback(new Error('Invalid arguments when calling createSession, location must be an '\n            + 'IPv4 address'));\n    });\n  }\n\n  // rename mediaMode -> p2p.preference\n  // store backup for use in constucting Session\n  backupOpts = _.clone(opts);\n  // avoid mutating passed in options\n  opts = _.clone(opts);\n  mediaModeToParam = {\n    routed: 'disabled',\n    relayed: 'enabled'\n  };\n  opts['p2p.preference'] = mediaModeToParam[opts.mediaMode];\n  delete opts.mediaMode;\n\n  return this.client.createSession(\n    opts,\n    function createSessionCallback(err, json) {\n      if (err) {\n        callback(new Error('Failed to createSession. ' + err));\n      }\n      else {\n        callback(null, new Session(self, json[0].session_id, backupOpts));\n      }\n    }\n  );\n};\n\n/**\n* Creates a token for connecting to an OpenTok session. In order to authenticate a user\n* connecting to an OpenTok session, the client passes a token when connecting to the session.\n* <p>\n* For testing, you can also generate a token by logging into your\n* <a href=\"https://tokbox.com/account\">TokBox account</a>.\n*\n* @param sessionId The session ID corresponding to the session to which the user will connect.\n*\n* @param options An object that defines options for the token (each of which is optional):\n*\n* <ul>\n*    <li><code>role</code> (String) &mdash; The role for the token. Each role defines a set of\n*      permissions granted to the token:\n*\n*        <ul>\n*           <li> <code>'subscriber'</code> &mdash; A subscriber can only subscribe to streams.</li>\n*\n*           <li> <code>'publisher'</code> &mdash; A publisher can publish streams, subscribe to\n*              streams, and signal. (This is the default value if you do not specify a role.)</li>\n*           <li> <code> 'publisheronly'</code> &mdash; A publisheronly can publish streams, but\n               cannot subscribe to streams.</li>\n*           <li> <code>'moderator'</code> &mdash; In addition to the privileges granted to a\n*              publisher, a moderator can perform moderation functions, such as forcing clients\n*              to disconnect, to stop publishing streams, or to mute audio in published streams.\n*              See the\n*              <a href=\"https://tokbox.com/developer/guides/moderation/\">Moderation developer guide</a>.</li>\n*        </ul>\n*\n*    </li>\n*\n*    <li><code>expireTime</code> (Number) &mdash; The expiration time for the token, in seconds\n*      since the UNIX epoch. The maximum expiration time is 30 days after the creation time. If\n*      a fractional number is specified, then it is rounded down to the nearest whole number.\n*      The default expiration time of 24 hours after the token creation time.\n*    </li>\n*\n*    <li><code>data</code> (String) &mdash; A string containing connection metadata describing the\n*      end-user.For example, you can pass the user ID, name, or other data describing the end-user.\n*      The length of the string is limited to 1000 characters. This data cannot be updated once it\n*      is set.\n*    </li>\n*\n*    <li><code>initialLayoutClassList</code> (Array) &mdash; An array of class names (strings)\n*      to be used as the initial layout classes for streams published by the client. Layout\n*      classes are used in customizing the layout of videos in\n*      <a href=\"https://tokbox.com/developer/guides/broadcast/live-streaming/\">live streaming\n*      broadcasts</a> and\n*      <a href=\"https://tokbox.com/developer/guides/archiving/layout-control.html\">composed\n*      archives</a>.\n*    </li>\n*\n* </ul>\n*\n* @param generateT1Token Connection tokens are now SHA-256 signed JWTs. Set this to <code>true</code> to create a token using the legacy T1 format. \n*\n* @return The token string.\n*/\n\nOpenTok.prototype.generateToken = function (sessionId, opts, generateT1Token = false) {\n  if (this.client?.c?.callVonage) {\n    const now = Math.round(new Date().getTime() / 1000);\n    const claims = {\n      scope: 'session.connect',\n      session_id: sessionId,\n      role: 'publisher',\n      initial_layout_class_list: '',\n      exp: opts?.expire_time || now + 86400,\n      sub: 'video',\n      acl: {\n        paths: {\n          '/session/**': {},\n        },\n      },\n    };\n\n    if (opts?.role) {\n      claims.role = opts.role;\n    }\n    if (opts?.data) {\n      claims.connection_data = opts.data;\n    }\n    if (opts?.initialLayoutClassList) {\n      claims.initial_layout_class_list\n        = opts.initialLayoutClassList.join(' ');\n    }\n\n    return tokenGenerate(\n      this.client.c.apiKey,\n      this.client.c.apiSecret,\n      claims,\n    )\n  }\n  var decoded;\n  var tokenData;\n  var now = Math.round(new Date().getTime() / 1000);\n\n  if (!opts) opts = {};\n  // avoid mutating passed in options\n  opts = _.clone(opts);\n\n  if (!_.isString(sessionId)) {\n    throw new Error('Token cannot be generated without a sessionId parameter');\n  }\n\n  // validate the sessionId belongs to the apiKey of this OpenTok instance\n  decoded = decodeSessionId(sessionId);\n  if (!decoded || decoded.apiKey !== this.apiKey) {\n    throw new Error('Token cannot be generated unless the session belongs to the API Key');\n  }\n\n  // combine defaults, opts, and whitelisted property names to create tokenData\n  if (_.isNumber(opts.expireTime) || _.isString(opts.expireTime)) {\n    // Automatic rounding to help out people who pass in a fractional expireTime\n    opts.expire_time = Math.round(opts.expireTime);\n  }\n  if (opts.data) {\n    opts.connection_data = opts.data;\n  }\n  if (_.isArray(opts.initialLayoutClassList)) {\n    opts.initial_layout_class_list = opts.initialLayoutClassList.join(' ');\n  }\n  else if (_.isString(opts.initialLayoutClassList)) {\n    opts.initial_layout_class_list = opts.initialLayoutClassList;\n  }\n  tokenData = _.pick(\n    _.defaults(opts, {\n      session_id: sessionId,\n      create_time: now,\n      expire_time: now + (60 * 60 * 24), // 1 day\n      nonce: Math.random(),\n      role: 'publisher',\n      initial_layout_class_list: '',\n      scope: 'session.connect'\n    }),\n    'session_id',\n    'create_time',\n    'nonce',\n    'role',\n    'expire_time',\n    'connection_data',\n    'initial_layout_class_list',\n    'scope'\n  );\n\n  // validate tokenData\n  if (!_.includes(['publisher', 'publisheronly', 'subscriber', 'moderator'], tokenData.role)) {\n    throw new Error('Invalid role for token generation: ' + tokenData.role);\n  }\n  if (!_.isNumber(tokenData.expire_time)) {\n    throw new Error('Invalid expireTime for token generation: ' + tokenData.expire_time);\n  }\n  if (tokenData.expire_time < now) {\n    throw new Error('Invalid expireTime for token generation, time cannot be in the past: '\n        + tokenData.expire_time\n        + ' < '\n        + now);\n  }\n  if (\n    tokenData.connection_data\n    && (tokenData.connection_data.length > 1024\n      || !_.isString(tokenData.connection_data))\n  ) {\n    throw new Error('Invalid data for token generation, must be a string with maximum length 1024');\n  }\n  if (\n    tokenData.initial_layout_class_list\n    && tokenData.initial_layout_class_list.length > 1024\n  ) {\n    throw new Error('Invalid initial layout class list for token generation, must have '\n        + 'concatenated length of less than 1024');\n  }\n\n  if (generateT1Token) {\n    return encodeToken(tokenData, this.apiKey, this.apiSecret);\n  }\n\n  return generateJwt(this.client.c, tokenData);\n};\n\n/*\n * decodes a sessionId into the metadata that it contains\n * @param     none\n * @returns   {string}    JWT\n */\nOpenTok.prototype.generateJwt = function () {\n  return generateJwt(this.client.c);\n};\n\n/*\n * handles the result of a session creation\n * @callback OpenTok~createSessionCallback\n * @param {?Error} err\n * @param {string} sessionId\n */\n\n/*\n * handles the result of a REST request\n * @callback OpenTok~doRequestCallback\n * @param {?Error} err\n * @param {string} responseXml\n */\n\n/*\n * is interested in an error, can be a super-type of OpenTok~createSessionCallback\n * @callback OpenTok~doRequestCallback\n * @param {?Error} err\n * @param {...*} arguments\n */\n\n/*\n *  @typedef SessionInfo\n *  @type {Object}\n *  @property {string} apiKey       The API Key that created the session\n *  @property {number} location     The location hint used when creating the session\n *  @property {Date}   create_time  The time at which the session was created\n */\n\n/*\n * External Interface\n */\n\nmodule.exports = OpenTok;\n\nfor (key in errors) {\n  if (Object.prototype.hasOwnProperty.call(errors, key)) {\n    OpenTok[key] = errors[key];\n  }\n}\n"]}