Class: Client

Client

Construct a Client to start creating and connecting to Rooms with other Participants.


new Twilio.Video.Client(initialToken [, options])

Constructs a new Client with an Access Token string.

Parameters:
Name Type Argument Description
initialToken string

The Client's Access Token string

options Client.ConstructorOptions <optional>

Options to override the constructor's default behavior

Properties:
Name Type Description
token string

The current Access Token

rooms Map.<Room.SID, Room>

The Rooms this Client is participating in

Fires:

Methods


connect( [options])

Connect to a Room.

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

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

Parameters:
Name Type Argument Default Description
options Client.ConnectOptions <optional>
{audio:true,video:true}

Options to override the default behavior

Returns:
Type
CancelablePromise.<Room>
Examples
var initialToken = getAccessToken();
var client = new Twilio.Video.Client(initialToken);

client.connect({ to: my-cool-room' }).then(function(room) {
  room.on('participantConnected', function(participant) {
    console.log(participant.identity + ' has connected');
  });
});
var initialToken = getAccessToken();
var client = new Twilio.Video.Client(initialToken);

var localMedia = new Twilio.Video.LocalMedia();

// Connect with audio-only
localMedia.addMicrophone().then(function() {
  return client.connect({ to: 'my-cool-room', localMedia: localMedia });
}).then(function(room) {
  // Our LocalParticipant reuses the LocalMedia we passed in.
  room.localParticipant.media === localMedia; // true

  room.on('participantConnected', function(participant) {
    console.log(participant.identity + ' has connected');
  });

  // Make sure to stop localMedia
  room.once('disconnected', function() {
    localMedia.stop();
  });
});

setLogLevel(logLevel)

Set log levels for Client

Parameters:
Name Type Description
logLevel LogLevels | LogLevel

New log level(s)

Returns:

this

Type
Client

updateToken(newToken)

Replace the Client's currently active token with a new token.

Parameters:
Name Type Description
newToken string

The new token to use to authenticate this Client.

Returns:
Type
Promise.<this>
Example
var initialToken = getAccessToken();
var client = new Twilio.Video.Client(initialToken);

getAccessToken().then(function(newToken) {
  return client.updateToken(newToken);
}).then(function() {
  console.info('Successfully updated with new token');
}, function(reason) {
  console.error('Error while updating token: ' + reason);
});

Type Definitions


ConnectOptions

You may pass these options to Client#connect to override the default behavior.

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

Whether or not to get local audio with getUserMedia when neither localMedia nor localStream are 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"

localMedia LocalMedia <optional>
<nullable>
null

Set to reuse an existing LocalMedia object when creating the Room

localStream MediaStream <optional>
<nullable>
null

Set to reuse an existing MediaStream when creating the Room

to string <optional>
<nullable>
null

Set to connect to a Room by name

video boolean <optional>
<nullable>
true

Whether or not to get local video with getUserMedia when neither localMedia nor localStream are provided


ConstructorOptions

You may pass these options to Client's constructor to override its default behavior.

Type:
  • object
Properties:
Name Type Argument Default Description
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"

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.

Events


error

Your Client has run into an error.

Parameters:
Name Type Description
error Error

The Error

Example
var initialToken = getAccessToken();
var client = new Twilio.Video.Client(initialToken);

client.on('error', function(error) {
 console.error(error);
});