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:
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 specifyingoptions. 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 optionsClient.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 logLevelLogLevels | 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 newTokenstring 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 audioboolean <optional>
<nullable>
true Whether or not to get local audio with
getUserMediawhen neitherlocalMedianorlocalStreamare providediceServersArray.<RTCIceServer> Override the STUN and TURN servers used by the Client when connecting to Rooms
iceTransportPolicyRTCIceTransportPolicy <optional>
"all" Override the ICE transport policy to be one of "relay" or "all"
localMediaLocalMedia <optional>
<nullable>
null Set to reuse an existing LocalMedia object when creating the Room
localStreamMediaStream <optional>
<nullable>
null Set to reuse an existing
MediaStreamwhen creating the Roomtostring <optional>
<nullable>
null Set to connect to a Room by name
videoboolean <optional>
<nullable>
true Whether or not to get local video with
getUserMediawhen neitherlocalMedianorlocalStreamare provided -
ConstructorOptions
-
You may pass these options to Client's constructor to override its default behavior.
Type:
- object
Properties:
Name Type Argument Default Description iceServersArray.<RTCIceServer> Override the STUN and TURN servers used by the Client when connecting to Rooms
iceTransportPolicyRTCIceTransportPolicy <optional>
"all" Override the ICE transport policy to be one of "relay" or "all"
logLevelLogLevel | 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 errorError The Error
Example
var initialToken = getAccessToken(); var client = new Twilio.Video.Client(initialToken); client.on('error', function(error) { console.error(error); });