function connect(token, options) {
  if (typeof options === 'undefined') {
    options = {};
  }
  if (!isNonArrayObject(options)) {
    return CancelablePromise.reject(E.INVALID_TYPE('options', 'object'));
  }

  options = Object.assign({
    automaticSubscription: true,
    createLocalTracks: createLocalTracks,
    dominantSpeaker: false,
    enableDscp: false,
    environment: DEFAULT_ENVIRONMENT,
    eventListener: null,
    insights: true,
    LocalAudioTrack: LocalAudioTrack,
    LocalDataTrack: LocalDataTrack,
    LocalParticipant: LocalParticipant,
    LocalVideoTrack: LocalVideoTrack,
    Log: Log,
    MediaStreamTrack: MediaStreamTrack,
    logLevel: DEFAULT_LOG_LEVEL,
    maxAudioBitrate: null,
    maxVideoBitrate: null,
    name: null,
    networkMonitor: true,
    networkQuality: false,
    preferredAudioCodecs: [],
    preferredVideoCodecs: [],
    realm: DEFAULT_REALM,
    region: DEFAULT_REGION,
    signaling: SignalingV2
  }, filterObject(options));

  /* eslint new-cap:0 */
  var wsServer = WS_SERVER(options.environment, options.region);
  var eventObserver = new EventObserver(Date.now(), options.eventListener);
  options = Object.assign({ eventObserver: eventObserver, wsServer: wsServer }, options);

  var logLevels = buildLogLevels(options.logLevel);
  var logComponentName = '[connect #' + ++connectCalls + ']';

  var log = void 0;
  try {
    log = new options.Log('default', logComponentName, logLevels);
  } catch (error) {
    return CancelablePromise.reject(error);
  }
  options.log = log;

  // NOTE(mmalavalli): Remove the deprecated ConnectOptions properties with a warning.
  // The warning is displayed only for the first call to connect() per browser session.
  removeDeprecatedConnectOptionsPropsWithWarning(options, log);

  // NOTE(mroberts): Print the Safari warning once if the log-level is at least
  // "warn", i.e. neither "error" nor "off".
  // NOTE(mmalavalli): Print the Safari warning only for versions 12.0 and below.
  if (isSafariWithoutVP8Support && !didPrintSafariWarning && log.logLevel !== 'error' && log.logLevel !== 'off') {
    didPrintSafariWarning = true;
    log.warn(['Support for Safari 12.0 and below is limited because it does not support VP8.', 'This means you may experience codec issues in Group Rooms. You may also', 'experience codec issues in Peer-to-Peer (P2P) Rooms containing Android- or', 'iOS-based Participants who do not support H.264. However, P2P Rooms', 'with browser-based Participants should work. For more information, please', 'refer to this guide: https://www.twilio.com/docs/video/javascript-v2-developing-safari-11'].join(' '));
  }

  if (typeof token !== 'string') {
    return CancelablePromise.reject(E.INVALID_TYPE('token', 'string'));
  }

  // NOTE(mmalavalli): The Room "name" in "options" was being used
  // as the LocalTrack name in asLocalTrack(). So we pass a copy of
  // "options" without the "name".
  var localTrackOptions = Object.assign({}, options);
  delete localTrackOptions.name;

  if ('tracks' in options) {
    if (!Array.isArray(options.tracks)) {
      return CancelablePromise.reject(E.INVALID_TYPE('options.tracks', 'Array of LocalAudioTrack, LocalVideoTrack or MediaStreamTrack'));
    }
    try {
      options.tracks = options.tracks.map(function (track) {
        return asLocalTrack(track, localTrackOptions);
      });
    } catch (error) {
      return CancelablePromise.reject(error);
    }
  }

  var error = validateBandwidthProfile(options.bandwidthProfile);
  if (error) {
    return CancelablePromise.reject(error);
  }

  var Signaling = options.signaling;
  var signaling = new Signaling(options.wsServer, options);

  log.info('Connecting to a Room');
  log.debug('Options:', options);

  var encodingParameters = new EncodingParametersImpl({
    maxAudioBitrate: options.maxAudioBitrate,
    maxVideoBitrate: options.maxVideoBitrate
  });

  var preferredCodecs = {
    audio: options.preferredAudioCodecs,
    video: options.preferredVideoCodecs.map(normalizeVideoCodecSettings)
  };

  var networkQualityConfiguration = new NetworkQualityConfigurationImpl(isNonArrayObject(options.networkQuality) ? options.networkQuality : {});

  // Convert options.networkQuality to boolean to configure Media Signaling
  options.networkQuality = isNonArrayObject(options.networkQuality) || options.networkQuality;

  // Create a CancelableRoomPromise<Room> that resolves after these steps:
  // 1 - Get the LocalTracks.
  // 2 - Create the LocalParticipant using options.tracks.
  // 3 - Connect to rtc-room-service and create the RoomSignaling.
  // 4 - Create the Room and then resolve the CancelablePromise.
  var cancelableRoomPromise = createCancelableRoomPromise(getLocalTracks.bind(null, options), createLocalParticipant.bind(null, signaling, log, encodingParameters, networkQualityConfiguration, options), createRoomSignaling.bind(null, token, options, signaling, encodingParameters, preferredCodecs), createRoom.bind(null, options));

  cancelableRoomPromise.then(function (room) {
    log.info('Connected to Room:', room.toString());
    log.info('Room name:', room.name);
    log.debug('Room:', room);
    return room;
  }, function (error) {
    if (cancelableRoomPromise._isCanceled) {
      log.info('Attempt to connect to a Room was canceled');
    } else {
      log.info('Error while connecting to a Room:', error);
    }
  });

  return cancelableRoomPromise;
}
/**
 * Connect to a {@link Room}.
 *   <br><br>
 *   By default, this will automatically acquire an array containing a
 *   {@link LocalAudioTrack} and {@link LocalVideoTrack} before connecting to
 *   the {@link Room}. These will be stopped when you disconnect from the
 *   {@link Room}.
 *   <br><br>
 *   You can override the default behavior by specifying
 *   <code>options</code>. For example, rather than acquiring a
 *   {@link LocalAudioTrack} and {@link LocalVideoTrack} automatically, you can
 *   pass your own array which you can stop yourself. See {@link ConnectOptions}
 *   for more information.
 * @alias module:twilio-video.connect
 * @param {string} token - The Access Token string
 * @param {ConnectOptions} [options] - Options to override the default behavior
 * @returns {CancelablePromise<Room>}
 * @throws {RangeError}
 * @throws {TwilioError}
 * @throws {TypeError}
 * @example
 * var Video = require('twilio-video');
 * var token = getAccessToken();
 * Video.connect(token, {
 *   name: 'my-cool-room'
 * }).then(function(room) {
 *   room.on('participantConnected', function(participant) {
 *     console.log(participant.identity + ' has connected');
 *   });

 *   room.once('disconnected', function() {
 *     console.log('You left the Room:', room.name);
 *   });
 * }).catch(error => {
 *   console.log('Could not connect to the Room:', error.message);
 * });
 * @example
 * var Video = require('twilio-video');
 * var token = getAccessToken();
 *
 * // Connect with audio-only
 * Video.connect(token, {
 *   name: 'my-cool-room',
 *   audio: true
 * }).then(function(room) {
 *   room.on('participantConnected', function(participant) {
 *     console.log(participant.identity + ' has connected');
 *   });
 *
 *   room.once('disconnected', function() {
 *     console.log('You left the Room:', room.name);
 *   });
 * }).catch(error => {
 *   console.log('Could not connect to the Room:', error.message);
 * });
 * @example
 * var Video = require('twilio-video');
 * var token = getAccessToken();
 *
 * // Connect with media acquired using getUserMedia()
 * navigator.mediaDevices.getUserMedia({
 *   audio: true,
 *   video: true
 * }).then(function(mediaStream) {
 *   return Video.connect(token, {
 *     name: 'my-cool-room',
 *     tracks: mediaStream.getTracks()
 *   });
 * }).then(function(room) {
 *   room.on('participantConnected', function(participant) {
 *     console.log(participant.identity + ' has connected');
 *   });
 *
 *   room.once('disconnected', function() {
 *     console.log('You left the Room:', room.name);
 *   });
 * }).catch(error => {
 *   console.log('Could not connect to the Room:', error.message);
 * });
 * @example
 * var Video = require('twilio-video');
 * var token = getAccessToken();
 *
 * // Connect with custom names for LocalAudioTrack and LocalVideoTrack
 * Video.connect(token, {
 *   name: 'my-cool-room'
 *   audio: { name: 'microphone' },
 *   video: { name: 'camera' }
 * }).then(function(room) {
 *   room.localParticipants.trackPublications.forEach(function(publication) {
 *     console.log('The LocalTrack "' + publication.trackName + '" was successfully published');
 *   });
 * }).catch(error => {
 *   console.log('Could not connect to the Room:', error.message);
 * });
 */
Connect to a  Room.

By default, this will automatically acquire an array containing a
LocalAudioTrack and  LocalVideoTrack before connecting to
the  Room. These will be stopped when you disconnect from the
Room.

You can override the default behavior by specifying
options. For example, rather than acquiring a
LocalAudioTrack and  LocalVideoTrack automatically, you can
pass your own array which you can stop yourself. See  ConnectOptions
for more information.












Connect to a Room . By default this will automatically acquire an array containing a LocalAudioTrack and LocalVideoTrack before connecting to the Room . These will be stopped when you disconnect from the Room . You can override the default behavior by specifying options . For example rather than acquiring a LocalAudioTrack and LocalVideoTrack automatically you can pass your own array which you can stop yourself . See ConnectOptions for more information .
function connect(token, options) {
  if (typeof options === 'undefined') {
    options = {};
  }
  if (!isNonArrayObject(options)) {
    return CancelablePromise.reject(E.INVALID_TYPE('options', 'object'));
  }
  options = Object.assign({
    automaticSubscription: true,
    createLocalTracks: createLocalTracks,
    dominantSpeaker: false,
    enableDscp: false,
    environment: DEFAULT_ENVIRONMENT,
    eventListener: null,
    insights: true,
    LocalAudioTrack: LocalAudioTrack,
    LocalDataTrack: LocalDataTrack,
    LocalParticipant: LocalParticipant,
    LocalVideoTrack: LocalVideoTrack,
    Log: Log,
    MediaStreamTrack: MediaStreamTrack,
    logLevel: DEFAULT_LOG_LEVEL,
    maxAudioBitrate: null,
    maxVideoBitrate: null,
    name: null,
    networkMonitor: true,
    networkQuality: false,
    preferredAudioCodecs: [],
    preferredVideoCodecs: [],
    realm: DEFAULT_REALM,
    region: DEFAULT_REGION,
    signaling: SignalingV2
  }, filterObject(options));
  var wsServer = WS_SERVER(options.environment, options.region);
  var eventObserver = new EventObserver(Date.now(), options.eventListener);
  options = Object.assign({ eventObserver: eventObserver, wsServer: wsServer }, options);
  var logLevels = buildLogLevels(options.logLevel);
  var logComponentName = '[connect #' + ++connectCalls + ']';
  var log = void 0;
  try {
    log = new options.Log('default', logComponentName, logLevels);
  } catch (error) {
    return CancelablePromise.reject(error);
  }
  options.log = log;
  removeDeprecatedConnectOptionsPropsWithWarning(options, log);
  if (isSafariWithoutVP8Support && !didPrintSafariWarning && log.logLevel !== 'error' && log.logLevel !== 'off') {
    didPrintSafariWarning = true;
    log.warn(['Support for Safari 12.0 and below is limited because it does not support VP8.', 'This means you may experience codec issues in Group Rooms. You may also', 'experience codec issues in Peer-to-Peer (P2P) Rooms containing Android- or', 'iOS-based Participants who do not support H.264. However, P2P Rooms', 'with browser-based Participants should work. For more information, please', 'refer to this guide: https://www.twilio.com/docs/video/javascript-v2-developing-safari-11'].join(' '));
  }
  if (typeof token !== 'string') {
    return CancelablePromise.reject(E.INVALID_TYPE('token', 'string'));
  }
  var localTrackOptions = Object.assign({}, options);
  delete localTrackOptions.name;
  if ('tracks' in options) {
    if (!Array.isArray(options.tracks)) {
      return CancelablePromise.reject(E.INVALID_TYPE('options.tracks', 'Array of LocalAudioTrack, LocalVideoTrack or MediaStreamTrack'));
    }
    try {
      options.tracks = options.tracks.map(function (track) {
        return asLocalTrack(track, localTrackOptions);
      });
    } catch (error) {
      return CancelablePromise.reject(error);
    }
  }
  var error = validateBandwidthProfile(options.bandwidthProfile);
  if (error) {
    return CancelablePromise.reject(error);
  }
  var Signaling = options.signaling;
  var signaling = new Signaling(options.wsServer, options);
  log.info('Connecting to a Room');
  log.debug('Options:', options);
  var encodingParameters = new EncodingParametersImpl({
    maxAudioBitrate: options.maxAudioBitrate,
    maxVideoBitrate: options.maxVideoBitrate
  });
  var preferredCodecs = {
    audio: options.preferredAudioCodecs,
    video: options.preferredVideoCodecs.map(normalizeVideoCodecSettings)
  };
  var networkQualityConfiguration = new NetworkQualityConfigurationImpl(isNonArrayObject(options.networkQuality) ? options.networkQuality : {});
  options.networkQuality = isNonArrayObject(options.networkQuality) || options.networkQuality;
  var cancelableRoomPromise = createCancelableRoomPromise(getLocalTracks.bind(null, options), createLocalParticipant.bind(null, signaling, log, encodingParameters, networkQualityConfiguration, options), createRoomSignaling.bind(null, token, options, signaling, encodingParameters, preferredCodecs), createRoom.bind(null, options));
  cancelableRoomPromise.then(function (room) {
    log.info('Connected to Room:', room.toString());
    log.info('Room name:', room.name);
    log.debug('Room:', room);
    return room;
  }, function (error) {
    if (cancelableRoomPromise._isCanceled) {
      log.info('Attempt to connect to a Room was canceled');
    } else {
      log.info('Error while connecting to a Room:', error);
    }
  });
  return cancelableRoomPromise;
}
function connect ( token , options ) { if ( typeof options === 'undefined' ) { options = { } ; } if ( ! isNonArrayObject ( options ) ) { return CancelablePromise . reject ( E . INVALID_TYPE ( 'options' , 'object' ) ) ; } options = Object . assign ( { automaticSubscription : true , createLocalTracks : createLocalTracks , dominantSpeaker : false , enableDscp : false , environment : DEFAULT_ENVIRONMENT , eventListener : null , insights : true , LocalAudioTrack : LocalAudioTrack , LocalDataTrack : LocalDataTrack , LocalParticipant : LocalParticipant , LocalVideoTrack : LocalVideoTrack , Log : Log , MediaStreamTrack : MediaStreamTrack , logLevel : DEFAULT_LOG_LEVEL , maxAudioBitrate : null , maxVideoBitrate : null , name : null , networkMonitor : true , networkQuality : false , preferredAudioCodecs : [ ] , preferredVideoCodecs : [ ] , realm : DEFAULT_REALM , region : DEFAULT_REGION , signaling : SignalingV2 } , filterObject ( options ) ) ; var wsServer = WS_SERVER ( options . environment , options . region ) ; var eventObserver = new EventObserver ( Date . now ( ) , options . eventListener ) ; options = Object . assign ( { eventObserver : eventObserver , wsServer : wsServer } , options ) ; var logLevels = buildLogLevels ( options . logLevel ) ; var logComponentName = '[connect #' + ++ connectCalls + ']' ; var log = void 0 ; try { log = new options . Log ( 'default' , logComponentName , logLevels ) ; } catch ( error ) { return CancelablePromise . reject ( error ) ; } options . log = log ; removeDeprecatedConnectOptionsPropsWithWarning ( options , log ) ; if ( isSafariWithoutVP8Support && ! didPrintSafariWarning && log . logLevel !== 'error' && log . logLevel !== 'off' ) { didPrintSafariWarning = true ; log . warn ( [ 'Support for Safari 12.0 and below is limited because it does not support VP8.' , 'This means you may experience codec issues in Group Rooms. You may also' , 'experience codec issues in Peer-to-Peer (P2P) Rooms containing Android- or' , 'iOS-based Participants who do not support H.264. However, P2P Rooms' , 'with browser-based Participants should work. For more information, please' , 'refer to this guide: https://www.twilio.com/docs/video/javascript-v2-developing-safari-11' ] . join ( ' ' ) ) ; } if ( typeof token !== 'string' ) { return CancelablePromise . reject ( E . INVALID_TYPE ( 'token' , 'string' ) ) ; } var localTrackOptions = Object . assign ( { } , options ) ; delete localTrackOptions . name ; if ( 'tracks' in options ) { if ( ! Array . isArray ( options . tracks ) ) { return CancelablePromise . reject ( E . INVALID_TYPE ( 'options.tracks' , 'Array of LocalAudioTrack, LocalVideoTrack or MediaStreamTrack' ) ) ; } try { options . tracks = options . tracks . map ( function ( track ) { return asLocalTrack ( track , localTrackOptions ) ; } ) ; } catch ( error ) { return CancelablePromise . reject ( error ) ; } } var error = validateBandwidthProfile ( options . bandwidthProfile ) ; if ( error ) { return CancelablePromise . reject ( error ) ; } var Signaling = options . signaling ; var signaling = new Signaling ( options . wsServer , options ) ; log . info ( 'Connecting to a Room' ) ; log . debug ( 'Options:' , options ) ; var encodingParameters = new EncodingParametersImpl ( { maxAudioBitrate : options . maxAudioBitrate , maxVideoBitrate : options . maxVideoBitrate } ) ; var preferredCodecs = { audio : options . preferredAudioCodecs , video : options . preferredVideoCodecs . map ( normalizeVideoCodecSettings ) } ; var networkQualityConfiguration = new NetworkQualityConfigurationImpl ( isNonArrayObject ( options . networkQuality ) ? options . networkQuality : { } ) ; options . networkQuality = isNonArrayObject ( options . networkQuality ) || options . networkQuality ; var cancelableRoomPromise = createCancelableRoomPromise ( getLocalTracks . bind ( null , options ) , createLocalParticipant . bind ( null , signaling , log , encodingParameters , networkQualityConfiguration , options ) , createRoomSignaling . bind ( null , token , options , signaling , encodingParameters , preferredCodecs ) , createRoom . bind ( null , options ) ) ; cancelableRoomPromise . then ( function ( room ) { log . info ( 'Connected to Room:' , room . toString ( ) ) ; log . info ( 'Room name:' , room . name ) ; log . debug ( 'Room:' , room ) ; return room ; } , function ( error ) { if ( cancelableRoomPromise . _isCanceled ) { log . info ( 'Attempt to connect to a Room was canceled' ) ; } else { log . info ( 'Error while connecting to a Room:' , error ) ; } } ) ; return cancelableRoomPromise ; }
Connect to a {@link Room}.
Connect to a { @link Room } .
/* eslint new-cap:0 */ // NOTE(mmalavalli): Remove the deprecated ConnectOptions properties with a warning. // The warning is displayed only for the first call to connect() per browser session. // NOTE(mroberts): Print the Safari warning once if the log-level is at least // "warn", i.e. neither "error" nor "off". // NOTE(mmalavalli): Print the Safari warning only for versions 12.0 and below. // NOTE(mmalavalli): The Room "name" in "options" was being used // as the LocalTrack name in asLocalTrack(). So we pass a copy of // "options" without the "name". // Convert options.networkQuality to boolean to configure Media Signaling // Create a CancelableRoomPromise<Room> that resolves after these steps: // 1 - Get the LocalTracks. // 2 - Create the LocalParticipant using options.tracks. // 3 - Connect to rtc-room-service and create the RoomSignaling. // 4 - Create the Room and then resolve the CancelablePromise.