Global

Methods


connect(token [, options])

Connect to a Room.

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

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

Parameters:
Name Type Argument Description
token string

The Access Token string

options ConnectOptions <optional>

Options to override the default behavior

Throws:
Returns:
Type
CancelablePromise.<Room>
Examples
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);
  });
});
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);
  });
});
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);
  });
});

createLocalAudioTrack( [options])

Request a LocalAudioTrack.

Parameters:
Name Type Argument Description
options CreateLocalTrackOptions <optional>

Options for requesting a LocalAudioTrack

Returns:
Type
Promise.<LocalAudioTrack>
Example
var Video = require('twilio-video');

// Connect to the Room with just video
Video.connect('my-token', {
  name: 'my-room-name',
  video: true
}).then(function(room) {
  // Add audio after connecting to the Room
  Video.createLocalAudioTrack().then(function(localTrack) {
    room.localParticipant.addTrack(localTrack);
  });
});

createLocalTracks( [options])

Request LocalTracks. By default, it requests a LocalAudioTrack and a LocalVideoTrack.

Parameters:
Name Type Argument Description
options CreateLocalTracksOptions <optional>
Returns:
Type
Array.<LocalTrack>
Examples
var Video = require('twilio-video');
// Request audio and video tracks
Video.createLocalTracks().then(function(localTracks) {
  var localMediaContainer = document.getElementById('local-media-container-id');
  localTracks.forEach(function(track) {
    localMediaContainer.appendChild(track.attach());
  });
});
var Video = require('twilio-video');
// Request just the default audio track
Video.createLocalTracks({ audio: true }).then(function(localTracks) {
  return Video.connect('my-token', {
    name: 'my-room-name',
    tracks: localTracks
  });
});

createLocalVideoTrack( [options])

Request a LocalVideoTrack.

Parameters:
Name Type Argument Description
options CreateLocalTrackOptions <optional>

Options for requesting a LocalVideoTrack

Returns:
Type
Promise.<LocalVideoTrack>
Example
var Video = require('twilio-video');

// Connect to the Room with just audio
Video.connect('my-token', {
  name: 'my-room-name',
  audio: true
}).then(function(room) {
  // Add video after connecting to the Room
  Video.createLocalVideoTrack().then(function(localTrack) {
    room.localParticipant.addTrack(localTrack);
  });
});

Type Definitions


AudioLevel

The maximum absolute amplitude of a set of audio samples in the range of 0 to 32767 inclusive.

Type:
  • number

ConnectOptions

You may pass these options to connect in order to override the default behavior.

Type:
  • object
Properties:
Name Type Argument Default Description
audio boolean <optional>
true

Whether or not to get local audio with getUserMedia when tracks are not provided.

iceServers Array.<RTCIceServer>

Override the STUN and TURN servers used by the Client when connecting to Rooms

iceTransportPolicy RTCIceTransportPolicy <optional>
"all"

Override the ICE transport policy to be one of "relay" or "all"

name string <optional>
<nullable>
null

Set to connect to a Room by name

logLevel LogLevel | LogLevels <optional>
'warn'

Set the log verbosity of logging to console. Passing a LogLevel string will use the same level for all components. Pass a LogLevels to set specific log levels.

tracks Array.<(LocalTrack|MediaStreamTrack)> <optional>

The LocalTracks or MediaStreamTracks with which to join the Room. These tracks can be obtained either by calling createLocalTracks, or by constructing them from the MediaStream obtained by calling getUserMedia().

video boolean <optional>
true

Whether or not to get local video with getUserMedia when tracks are not provided.


CreateLocalTrackOptions

Create LocalTrack options.

Type:
  • MediaTrackConstraints
Properties:
Name Type Description
logLevel LogLevel | LogLevels

CreateLocalTracksOptions

Type:
  • object
Properties:
Name Type Argument Default Description
audio boolean <optional>
true

Whether or not to get local audio with getUserMedia when tracks are not provided.

logLevel LogLevel | LogLevels <optional>
'warn'

Set the log verbosity of logging to console. Passing a LogLevel string will use the same level for all components. Pass a LogLevels to set specific log levels.

video boolean <optional>
true

Whether or not to get local video with getUserMedia when tracks are not provided.


LocalTrackOptions

LocalTrack options

Type:
  • object
Properties:
Name Type Description
logLevel LogLevel | LogLevels

Log level for 'media' modules


LogLevel

Levels for logging verbosity.

Type:
  • String

LogLevels

You may pass these levels to ConnectOptions to override log levels for individual components.

Type:
  • object
Properties:
Name Type Argument Default Description
default LogLevel <optional>
'warn'

Log level for 'default' modules.

media LogLevel <optional>
'warn'

Log level for 'media' modules.

signaling LogLevel <optional>
'warn'

Log level for 'signaling' modules.

webrtc LogLevel <optional>
'warn'

Log level for 'webrtc' modules.