Members
-
AudioCodec :string
-
Names of the supported audio codecs.
Type:
- string
Properties:
Name Type Default Description isacstring isac opusstring opus PCMAstring PCMA PCMUstring PCMU -
VideoCodec :string
-
Names of the supported video codecs.
Type:
- string
Properties:
Name Type Default Description H264string H264 VP8string VP8 VP9string VP9
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. These will be stopped when you disconnect from the Room.
You can override the default behavior by specifyingoptions. 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.Parameters:
Name Type Argument Description tokenstring The Access Token string
optionsConnectOptions <optional>
Options to override the default behavior
Throws:
-
RangeError
-
TypeError
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); }); });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'); }); }); -
-
createLocalAudioTrack( [options])
-
Request a LocalAudioTrack.
Parameters:
Name Type Argument Description optionsCreateLocalTrackOptions <optional>
Options for requesting a LocalAudioTrack
Returns:
- Type
- Promise.<LocalAudioTrack>
Examples
var Video = require('twilio-video'); // Connect to the Room with just video Video.connect('my-token', { name: 'my-cool-room', video: true }).then(function(room) { // Add audio after connecting to the Room Video.createLocalAudioTrack().then(function(localTrack) { room.localParticipant.addTrack(localTrack); }); });var Video = require('twilio-video'); // Request the default LocalAudioTrack with a custom name Video.createLocalAudioTrack({ name: 'microphone' }).then(function(localTrack) { console.log(localTrack.name); // 'microphone' }); -
createLocalTracks( [options])
-
Request LocalTracks. By default, it requests a LocalAudioTrack and a LocalVideoTrack.
Parameters:
Name Type Argument Description optionsCreateLocalTracksOptions <optional>
Returns:
- Type
- Promise.<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-cool-room', tracks: localTracks }); });var Video = require('twilio-video'); // Request the audio and video tracks with custom names Video.createLocalTracks({ audio: { name: 'microphone' }, video: { name: 'camera' } }).then(function(localTracks) { localTracks.forEach(function(localTrack) { console.log(localTrack.name); }); }); -
createLocalVideoTrack( [options])
-
Request a LocalVideoTrack.
Parameters:
Name Type Argument Description optionsCreateLocalTrackOptions <optional>
Options for requesting a LocalVideoTrack
Returns:
- Type
- Promise.<LocalVideoTrack>
Examples
var Video = require('twilio-video'); // Connect to the Room with just audio Video.connect('my-token', { name: 'my-cool-room', audio: true }).then(function(room) { // Add video after connecting to the Room Video.createLocalVideoTrack().then(function(localTrack) { room.localParticipant.addTrack(localTrack); }); });var Video = require('twilio-video'); // Request the default LocalVideoTrack with a custom name Video.createLocalVideoTrack({ name: 'camera' }).then(function(localTrack) { console.log(localTrack.name); // 'camera' });
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 audioboolean | CreateLocalTrackOptions <optional>
true Whether or not to get local audio with
getUserMediawhentracksare not provided.iceServersArray.<RTCIceServer> Override the STUN and TURN servers used when connecting to Rooms
iceTransportPolicyRTCIceTransportPolicy <optional>
"all" Override the ICE transport policy to be one of "relay" or "all"
insightsboolean <optional>
true Whether publishing events to the Insights gateway is enabled or not
maxAudioBitratenumber <optional>
<nullable>
null Max outgoing audio bitrate (bps); A
nullvalue does not set any bitrate limit; This value is set as a hint for variable bitrate codecs, but will not take effect for fixed bitrate codecsmaxVideoBitratenumber <optional>
<nullable>
null Max outgoing video bitrate (bps); A
nullvalue does not set any bitrate limit; This value is set as a hint for variable bitrate codecs, but will not take effect for fixed bitrate codecsnamestring <optional>
<nullable>
null Set to connect to a Room by name
preferredAudioCodecsArray.<AudioCodec> <optional>
[] Preferred audio codecs; An empty array preserves the current audio codec preference order.
preferredVideoCodecsArray.<(VideoCodec|VideoCodecSettings)> <optional>
[] Preferred video codecs; An empty array preserves the current video codec preference order. If you want to set a preferred video codec on a Group Room, you will need to create the Room using the REST API and set the
VideoCodecsproperty. See here for more information.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.
tracksArray.<(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().videoboolean | CreateLocalTrackOptions <optional>
true Whether or not to get local video with
getUserMediawhentracksare not provided. -
CreateLocalTrackOptions
-
Create LocalTrack options.
Type:
- MediaTrackConstraints
Properties:
Name Type Argument Description logLevelLogLevel | LogLevels namestring <optional>
The LocalTrack's name; by default, it is set to the LocalTrack's ID.
-
CreateLocalTracksOptions
-
createLocalTracks options
Type:
- object
Properties:
Name Type Argument Default Description audioboolean | CreateLocalTrackOptions <optional>
true Whether or not to get local audio with
getUserMediawhentracksare not provided.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.
videoboolean | CreateLocalTrackOptions <optional>
true Whether or not to get local video with
getUserMediawhentracksare not provided. -
DataTrack
-
A DataTrack is a LocalDataTrack or RemoteDataTrack.
Type:
-
EncodingParameters
-
Outgoing media encoding parameters.
Type:
- object
Properties:
Name Type Argument Description maxAudioBitratenumber <optional>
<nullable>
Max outgoing audio bitrate (bps); If not specified, retains the existing bitrate limit; A
nullvalue removes any previously set bitrate limitmaxVideoBitratenumber <optional>
<nullable>
Max outgoing video bitrate (bps); If not specified, retains the existing bitrate limit; A
nullvalue removes any previously set bitrate limit -
LocalDataTrackOptions
-
LocalDataTrack options
Type:
Properties:
Name Type Argument Default Description maxPacketLifeTimenumber <optional>
<nullable>
null Set this to limit the time (in milliseconds) during which the LocalDataTrack will send or re-send data if not successfully delivered on the underlying RTCDataChannel(s). It is an error to specify both this and
maxRetransmits.maxRetransmitsnumber <optional>
<nullable>
null Set this to limit the number of times the LocalDataTrack will send or re-send data if not acknowledged on the underlying RTCDataChannel(s). It is an error to specify both this and
maxPacketLifeTime.orderedboolean <optional>
true Set this to false to allow data on the LocalDataTrack to be sent out-of-order.
-
LocalTrack
-
A LocalTrack is a LocalAudioTrack, LocalVideoTrack, or LocalDataTrack.
Type:
-
LocalTrackOptions
-
LocalTrack options
Type:
- object
Properties:
Name Type Argument Description logLevelLogLevel | LogLevels Log level for 'media' modules
namestring <optional>
The LocalTrack's name; by default, it is set to the LocalTrack's ID.
-
LocalTrackPublicationOptions
-
LocalTrackPublication options
Type:
- object
Properties:
Name Type Description logLevelLogLevel | LogLevels Log level for 'media' modules
-
LogLevels
-
You may pass these levels to ConnectOptions to override log levels for individual components.
Type:
- object
Properties:
Name Type Argument Default Description defaultLogLevel <optional>
'warn' Log level for 'default' modules.
mediaLogLevel <optional>
'warn' Log level for 'media' modules.
signalingLogLevel <optional>
'warn' Log level for 'signaling' modules.
webrtcLogLevel <optional>
'warn' Log level for 'webrtc' modules.
-
RemoteTrack
-
A RemoteTrack is a RemoteAudioTrack, RemoteVideoTrack, or RemoteDataTrack.
Type:
-
VideoCodecSettings
-
Video codec settings.
Type:
- object
Properties:
Name Type Description codecVideoCodec Video codec name
-
VP8CodecSettings
-
VP8 codec settings.
Type:
Properties:
Name Type Argument Default Description nameVideoCodec "VP8"
simulcastboolean <optional>
false Enable/disable VP8 simulcast; if enabled, Twilio's Video SDK will send three video streams of different qualities