Attach the AudioTrack to an existing HTMLMediaElement. The
+HTMLMediaElement could be an HTMLAudioElement or an HTMLVideoElement.
+
If the HTMLMediaElement's srcObject is not set to a MediaStream,
+this method sets it to a new MediaStream containing the AudioTrack's
+MediaStreamTrack; otherwise, it adds the MediaTrack's
+MediaStreamTrack to the existing MediaStream. Finally, if there are any other
+MediaStreamTracks of the same kind on the MediaStream, this method removes
+them.
Attach the AudioTrack to an HTMLMediaElement selected by
+document.querySelector. The HTMLMediaElement could be an
+HTMLAudioElement or an HTMLVideoElement.
+
If the HTMLMediaElement's srcObject is not set to a MediaStream,
+this method sets it to a new MediaStream containing the AudioTrack's
+MediaStreamTrack; otherwise, it adds the AudioTrack's
+MediaStreamTrack to the existing MediaStream. Finally, if there are any other
+MediaStreamTracks of the same kind on the MediaStream, this method removes
+them.
+
+
+
+
+
+
+
+
+
+
Parameters:
+
+
+
+
+
+
+
Name
+
+
+
Type
+
+
+
+
+
+
Description
+
+
+
+
+
+
+
+
+
selector
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
A query selector for the HTMLMediaElement to
+attach to
When a LocalAudioTrack is created
+with NoiseCancellationOptions, this property provides interface
+to enable or disable the noise cancellation at runtime.
Restart the LocalAudioTrack. This stops the existing MediaStreamTrack
+and creates a new MediaStreamTrack. If the LocalAudioTrack is being published
+to a Room, then all the RemoteParticipants will start receiving media
+from the newly created MediaStreamTrack. You can access the new MediaStreamTrack via
+the mediaStreamTrack property. If you want to listen to events on
+the MediaStreamTrack directly, please do so in the "started" event handler. Also,
+the LocalAudioTrack's ID is no longer guaranteed to be the same as the
+underlying MediaStreamTrack's ID.
+
+
+
+
+
+
+
+
+
+
Parameters:
+
+
+
+
+
+
+
Name
+
+
+
Type
+
+
+
Argument
+
+
+
+
+
Description
+
+
+
+
+
+
+
+
+
constraints
+
+
+
+
+
+MediaTrackConstraints
+
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
The optional MediaTrackConstraints
+for restarting the LocalAudioTrack; If not specified, then the current MediaTrackConstraints
+will be used; If {} (empty object) is specified, then the default MediaTrackConstraints
+will be used
Rejects with a TypeError if the LocalAudioTrack was not created
+using an one of createLocalAudioTrack, createLocalTracks or connect;
+Also rejects with the DOMException
+raised by getUserMedia when it fails
+
+
+
+
+
+
+ Type
+
+
+
+Promise.<void>
+
+
+
+
+
+
+
+
+
+
+
Example
+
+
const { connect, createLocalAudioTrack } = require('twilio-video');
+
+// Create a LocalAudioTrack that captures audio from a USB microphone.
+createLocalAudioTrack({ deviceId: 'usb-mic-id' }).then(function(localAudioTrack) {
+ return connect('token', {
+ name: 'my-cool-room',
+ tracks: [localAudioTrack]
+ });
+}).then(function(room) {
+ // Restart the LocalAudioTrack to capture audio from the default microphone.
+ const localAudioTrack = Array.from(room.localParticipant.audioTracks.values())[0].track;
+ return localAudioTrack.restart({ deviceId: 'default-mic-id' });
+});
+
+
+
+
+
+
+
+
+
+
stop()
+
+
+
+
+
+
+
+
Calls stop on the underlying MediaStreamTrack. If you choose to stop a
+LocalAudioTrack, you should unpublish it after stopping.
If non-null, this represents a time
+limit (in milliseconds) during which the LocalDataTrack will send
+or re-send data if not acknowledged on the underlying RTCDataChannel(s).
+
+
+
+
+
+
+
maxRetransmits
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+
+ <nullable>
+
+
+
+
+
+
+
If non-null, this represents the number
+of times the LocalDataTrack will resend data if not successfully
+delivered on the underlying RTCDataChannel(s).
+
+
+
+
+
+
+
ordered
+
+
+
+
+
+boolean
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
true if data on the LocalDataTrack is
+guaranteed to be sent in order.
+
+
+
+
+
+
+
reliable
+
+
+
+
+
+boolean
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
This is true if both
+maxPacketLifeTime and maxRetransmits are set to
+null. In other words, if this is true, there is no bound on packet lifetime
+or the number of times the LocalDataTrack will attempt to send
+data, ensuring "reliable" transmission.
Resolves with the corresponding
+LocalTrackPublication if successful; In a Large Group Room (Maximum
+Participants greater than 50), rejects with a ParticipantMaxTracksExceededError
+if either the total number of published Tracks in the Room exceeds 16, or the LocalTrack
+is part of a set of LocalTracks which along with the published Tracks exceeds 16.
Resolves with the corresponding
+LocalTrackPublication if successful; In a Large Group Room (Maximum
+Participants greater than 50), rejects with a ParticipantMaxTracksExceededError
+if the total number of published Tracks in the Room exceeds 16, or the LocalTrack
+is part of a set of LocalTracks which along with the published Tracks exceeds 16.
The LocalTracks
+to publish; for any MediaStreamTracks provided, if a corresponding
+LocalAudioTrack or LocalVideoTrack has not yet been
+published, this method will construct one
The resulting
+LocalTrackPublications if successful; In a Large Group Room (Maximum
+Participants greater than 50), rejects with a ParticipantMaxTracksExceededError
+if the total number of published Tracks in the Room exceeds 16, or the LocalTracks
+along with the published Tracks exceeds 16.
The LocalTrack
+to stop publishing; if a MediaStreamTrack is provided, this method
+looks up the corresponding LocalAudioTrack or
+LocalVideoTrack to stop publishing
The LocalTracks
+to stop publishing; for any MediaStreamTracks provided, this method looks
+up the corresponding LocalAudioTrack or LocalVideoTrack to
+stop publishing
A LocalTrack failed to publish. Check the error message for more
+information. In a Large Group Room (Maximum Participants greater than 50),
+this event is raised with a ParticipantMaxTracksExceededError either
+when attempting to publish the LocalTrack will exceed the Maximum Published
+Tracks limit of 16, or the LocalTrack is part of a set of LocalTracks
+which along with the published Tracks exceeds 16.
One of the LocalParticipant's LocalTrackPublications encountered a warning.
+This event is only raised if you enabled warnings using notifyWarnings in ConnectOptions.
One of the LocalParticipant's LocalTrackPublications cleared all warnings.
+This event is only raised if you enabled warnings using notifyWarnings in ConnectOptions.
Add a VideoProcessor to allow for custom processing of video frames belonging to a VideoTrack.
+Only Chrome supports this as of now. Calling this API from a non-supported browser will result in a log warning.
Enable or disable the LocalVideoTrack. This is effectively "unpause"
+or "pause". If a VideoProcessor is added,
+then processedTrack is enabled or disabled as well.
Restart the LocalVideoTrack. This stops the existing MediaStreamTrack
+and creates a new MediaStreamTrack. If the LocalVideoTrack is being published
+to a Room, then all the RemoteParticipants will start receiving media
+from the newly created MediaStreamTrack. You can access the new MediaStreamTrack via
+the mediaStreamTrack property. If you want to listen to events on
+the MediaStreamTrack directly, please do so in the "started" event handler. Also,
+the LocalVideoTrack's ID is no longer guaranteed to be the same as the
+underlying MediaStreamTrack's ID.
+
+
+
+
+
+
+
+
+
+
Parameters:
+
+
+
+
+
+
+
Name
+
+
+
Type
+
+
+
Argument
+
+
+
+
+
Description
+
+
+
+
+
+
+
+
+
constraints
+
+
+
+
+
+MediaTrackConstraints
+
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
The optional MediaTrackConstraints
+for restarting the LocalVideoTrack; If not specified, then the current MediaTrackConstraints
+will be used; If {} (empty object) is specified, then the default MediaTrackConstraints
+will be used
Rejects with a TypeError if the LocalVideoTrack was not created
+using an one of createLocalVideoTrack, createLocalTracks or connect;
+Also rejects with the DOMException
+raised by getUserMedia when it fails
+
+
+
+
+
+
+ Type
+
+
+
+Promise.<void>
+
+
+
+
+
+
+
+
+
+
+
Example
+
+
const { connect, createLocalVideoTrack } = require('twilio-video');
+
+// Create a LocalVideoTrack that captures video from the front-facing camera.
+createLocalVideoTrack({ facingMode: 'user' }).then(function(localVideoTrack) {
+ return connect('token', {
+ name: 'my-cool-room',
+ tracks: [localVideoTrack]
+ });
+}).then(function(room) {
+ // Restart the LocalVideoTrack to capture video from the back-facing camera.
+ const localVideoTrack = Array.from(room.localParticipant.videoTracks.values())[0].track;
+ return localVideoTrack.restart({ facingMode: 'environment' });
+});
+
+
+
+
+
+
+
+
+
+
stop()
+
+
+
+
+
+
+
+
Calls stop on the underlying MediaStreamTrack. If you choose to stop a
+LocalVideoTrack, you should unpublish it after stopping.
NoiseCancellation interface provides methods to control noise cancellation at runtime. This interface is exposed
+on LocalAudioTrack property noiseCancellation. It is available only when NoiseCancellationOptions are
+specified when creating a LocalAudioTrack, and the plugin is successfully loaded.
const { connect, createLocalAudioTrack } = require('twilio-video');
+
+// Create a LocalAudioTrack with Krisp noise cancellation enabled.
+const localAudioTrack = await createLocalAudioTrack({
+ noiseCancellationOptions: {
+ sdkAssetsPath: 'path/to/hosted/twilio/krisp/audio/plugin/1.0.0/dist',
+ vendor: 'krisp'
+ }
+});
+
+if (!localAudioTrack.noiseCancellation) {
+ // If the Krisp audio plugin fails to load, then a warning message will be logged
+ // in the browser console, and the "noiseCancellation" property will be set to null.
+ // You can still use the LocalAudioTrack to join a Room. However, it will use the
+ // browser's noise suppression instead of the Krisp noise cancellation. Make sure
+ // the "sdkAssetsPath" provided in "noiseCancellationOptions" points to the correct
+ // hosted path of the plugin assets.
+} else {
+ // Join a Room with the LocalAudioTrack.
+ const room = await connect('token', {
+ name: 'my-cool-room',
+ tracks: [localAudioTrack]
+ });
+
+ if (!localAudioTrack.noiseCancellation.isEnabled) {
+ // Krisp noise cancellation is permanently disabled in Peer-to-Peer and Go Rooms.
+ }
+}
+
+//
+// Enable/disable noise cancellation.
+// @param {boolean} enable - whether noise cancellation should be enabled
+//
+function setNoiseCancellation(enable) {
+ const { noiseCancellation } = localAudioTrack;
+ if (noiseCancellation) {
+ if (enable) {
+ // If enabled, then the LocalAudioTrack will use the Krisp noise
+ // cancellation instead of the browser's noise suppression.
+ noiseCancellation.enable();
+ } else {
+ // If disabled, then the LocalAudioTrack will use the browser's
+ // noise suppression instead of the Krisp noise cancellation.
+ noiseCancellation.disable();
+ }
+ }
+}
Raised whenever a Participant tries to publish a Track and the maximum number of published tracks allowed in the Room at the same time has been reached
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Properties:
+
+
+
+
+
+
+
+
Name
+
+
+
Type
+
+
+
+
+
+
Description
+
+
+
+
+
+
+
+
+
code
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+
53203
+
+
+
+
+
+
+
message
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
'The maximum number of published tracks allowed in the Room at the same time has been reached'
If non-null, this represents a time
+limit (in milliseconds) during which data will be transmitted or
+retransmitted if not acknowledged on the underlying RTCDataChannel.
+
+
+
+
+
+
+
maxRetransmits
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+
+ <nullable>
+
+
+
+
+
+
+
If non-null, this represents the number
+of times the data will be retransmitted if not successfully received on the
+underlying RTCDataChannel.
+
+
+
+
+
+
+
ordered
+
+
+
+
+
+boolean
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
true if data on the RemoteDataTrack can
+be received out-of-order.
This is true if both
+maxPacketLifeTime and maxRetransmits are set to
+null. In other words, if this is true, there is no bound on packet lifetime
+or the number of retransmits that will be attempted, ensuring "reliable"
+transmission.
function trackPublished(publication) {
+ console.log(`Track ${publication.trackSid} was published`);
+}
+
+room.on('participantConnected', participant => {
+ // Handle RemoteTracks published while connecting to the Room.
+ participant.trackPublications.forEach(trackPublished);
+
+ // Handle RemoteTracks published after connecting to the Room.
+ participant.on('trackPublished', trackPublished);
+});
Add a VideoProcessor to allow for custom processing of video frames belonging to a VideoTrack.
+When a Participant un-publishes and re-publishes a VideoTrack, a new RemoteVideoTrack is created and
+any VideoProcessors attached to the previous RemoteVideoTrack would have to be re-added again.
+Only Chrome supports this as of now. Calling this API from a non-supported browser will result in a log warning.
Set the RemoteVideoTrack's content preferences. This method is applicable only for the group rooms and only when connected with
+videoContentPreferencesMode in video bandwidth profile options set to 'manual'
the new subscribe Track.Priority;
+If null, then the subscribe Track.Priority is cleared, which
+means the Track.Priority set by the publisher is now the effective priority.
Request to switch off a RemoteVideoTrack, This method is applicable only for the group rooms and only when connected with
+clientTrackSwitchOffControl in video bandwidth profile options set to 'manual'
Request to switch on a RemoteVideoTrack, This method is applicable only for the group rooms and only when connected with
+clientTrackSwitchOffControl in video bandwidth profile options set to 'manual'
The Dominant Speaker in the Room changed. Either the Dominant Speaker
+is a new RemoteParticipant or the Dominant Speaker has been reset and
+is now null.
Your application is reconnecting to the Room. This happens when there
+is a disruption in your signaling connection and/or your media connection. When
+this event is emitted, the Room is in state "reconnecting". If reconnecting
+succeeds, the Room will emit a "reconnected" event.
A
+MediaConnectionError if your application is reconnecting due to a
+disruption in your media connection, or a SignalingConnectionDisconnectedError
+if your application is reconnecting due to a disruption in your signaling connection
function trackPublished(publication, participant) {
+ console.log(`RemoteParticipant ${participant.sid} published Track ${publication.trackSid}`);
+}
+
+// Handle RemoteTracks published after connecting to the Room.
+room.on('trackPublished', trackPublished);
+
+room.on('participantConnected', participant => {
+ // Handle RemoteTracks published while connecting to the Room.
+ participant.trackPublications.forEach(publication => trackPublished(publication, participant));
+});
One of the LocalParticipant's LocalTrackPublications in the Room encountered a warning.
+This event is only raised if you enabled warnings using notifyWarnings in ConnectOptions.
room.on('trackWarning', (name, publication, participant) => {
+ if (name === 'recording-media-lost') {
+ log(`LocalTrack ${publication.track.name} is not recording media.`,
+ name, publication, participant);
+
+ // Wait a reasonable amount of time to clear the warning.
+ const timer = setTimeout(() => {
+ // If the warning is not cleared, you can manually
+ // reconnect to the room, or show a dialog to the user
+ }, 5000);
+
+ room.once('trackWarningsCleared', (publication, participant) => {
+ log('LocalTrack warnings have cleared!',
+ publication, participant);
+ clearTimeout(timer);
+ });
+ }
+});
+
+
+
+
+
+
+
+
+
+
trackWarningsCleared
+
+
+
+
+
+
+
+
One of the LocalParticipant's LocalTrackPublications in the Room cleared all warnings.
+This event is only raised if you enabled warnings using notifyWarnings in ConnectOptions.
Add a VideoProcessor to allow for custom processing of video frames belonging to a VideoTrack.
+Only Chrome supports this as of now. Calling this API from a non-supported browser will result in a log warning.
Attach the VideoTrack to an existing HTMLMediaElement. The
+HTMLMediaElement could be an HTMLAudioElement or an HTMLVideoElement.
+
If the HTMLMediaElement's srcObject is not set to a MediaStream,
+this method sets it to a new MediaStream containing the VideoTrack's
+MediaStreamTrack; otherwise, it adds the MediaTrack's
+MediaStreamTrack to the existing MediaStream. Finally, if there are any other
+MediaStreamTracks of the same kind on the MediaStream, this method removes
+them.
Attach the VideoTrack to an HTMLMediaElement selected by
+document.querySelector. The HTMLMediaElement could be an
+HTMLAudioElement or an HTMLVideoElement.
+
If the HTMLMediaElement's srcObject is not set to a MediaStream,
+this method sets it to a new MediaStream containing the VideoTrack's
+MediaStreamTrack; otherwise, it adds the VideoTrack's
+MediaStreamTrack to the existing MediaStream. Finally, if there are any other
+MediaStreamTracks of the same kind on the MediaStream, this method removes
+them.
+
+
+
+
+
+
+
+
+
+
Parameters:
+
+
+
+
+
+
+
Name
+
+
+
Type
+
+
+
+
+
+
Description
+
+
+
+
+
+
+
+
+
selector
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
A query selector for the HTMLMediaElement to
+attach to
A LocalTrack failed to publish. Check the error message for more
+information. In a Large Group Room (Maximum Participants greater than 50),
+this event is raised with a ParticipantMaxTracksExceededError either
+when attempting to publish the LocalTrack will exceed the Maximum Published
+Tracks limit of 16, or the LocalTrack is part of a set of LocalTracks
+which along with the published Tracks exceeds 16.
One of the LocalParticipant's LocalTrackPublications encountered a warning.
+This event is only raised if you enabled warnings using notifyWarnings in ConnectOptions.
One of the LocalParticipant's LocalTrackPublications cleared all warnings.
+This event is only raised if you enabled warnings using notifyWarnings in ConnectOptions.
function trackPublished(publication) {
+ console.log(`Track ${publication.trackSid} was published`);
+}
+
+room.on('participantConnected', participant => {
+ // Handle RemoteTracks published while connecting to the Room.
+ participant.trackPublications.forEach(trackPublished);
+
+ // Handle RemoteTracks published after connecting to the Room.
+ participant.on('trackPublished', trackPublished);
+});
The Dominant Speaker in the Room changed. Either the Dominant Speaker
+is a new RemoteParticipant or the Dominant Speaker has been reset and
+is now null.
Your application is reconnecting to the Room. This happens when there
+is a disruption in your signaling connection and/or your media connection. When
+this event is emitted, the Room is in state "reconnecting". If reconnecting
+succeeds, the Room will emit a "reconnected" event.
A
+MediaConnectionError if your application is reconnecting due to a
+disruption in your media connection, or a SignalingConnectionDisconnectedError
+if your application is reconnecting due to a disruption in your signaling connection
function trackPublished(publication, participant) {
+ console.log(`RemoteParticipant ${participant.sid} published Track ${publication.trackSid}`);
+}
+
+// Handle RemoteTracks published after connecting to the Room.
+room.on('trackPublished', trackPublished);
+
+room.on('participantConnected', participant => {
+ // Handle RemoteTracks published while connecting to the Room.
+ participant.trackPublications.forEach(publication => trackPublished(publication, participant));
+});
One of the LocalParticipant's LocalTrackPublications in the Room encountered a warning.
+This event is only raised if you enabled warnings using notifyWarnings in ConnectOptions.
room.on('trackWarning', (name, publication, participant) => {
+ if (name === 'recording-media-lost') {
+ log(`LocalTrack ${publication.track.name} is not recording media.`,
+ name, publication, participant);
+
+ // Wait a reasonable amount of time to clear the warning.
+ const timer = setTimeout(() => {
+ // If the warning is not cleared, you can manually
+ // reconnect to the room, or show a dialog to the user
+ }, 5000);
+
+ room.once('trackWarningsCleared', (publication, participant) => {
+ log('LocalTrack warnings have cleared!',
+ publication, participant);
+ clearTimeout(timer);
+ });
+ }
+});
+
+
+
+
+
+
+
+
+
+
trackWarningsCleared
+
+
+
+
+
+
+
+
One of the LocalParticipant's LocalTrackPublications in the Room cleared all warnings.
+This event is only raised if you enabled warnings using notifyWarnings in ConnectOptions.
This mode is for use cases where all the subscribed RemoteVideoTracks are
+equally important. The bandwidth allocation algorithm will share the available
+downlink bandwidth equally among the subscribed RemoteVideoTracks, irrespective
+of their Track.Priority. In case of insufficient downlink bandwidth, the lower
+priority RemoteVideoTracks are switched off.
+
+
+
+
+
+
+
collaboration
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+ collaboration
+
+
+
+
+
This mode is for use cases where some RemoteVideoTracks are prioritized more than
+others. However, the lower priority RemoteVideoTracks still need to be visible.
+The bandwidth allocation algorithm will share the available downlink bandwidth proportional
+to the requested VideoRenderDimensions corresponding to their Track.Priority.
+In case of insufficient downlink bandwidth, the quality of higher priority RemoteVideoTracks
+may be degraded to avoid switching off lower priority RemoteVideoTracks.
+
+
+
+
+
+
+
presentation
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+ presentation
+
+
+
+
+
This mode is for use cases where some RemoteVideoTracks are deemed critical and must
+be preserved at any cost over the other RemoteVideoTracks. The bandwidth allocation
+algorithm will allocate as big a share of the available downlink bandwidth as it possibly
+can to the higher priority RemoteVideoTracks, and only then consider the lower priority
+RemoteVideoTracks. In case of insufficient downlink bandwidth, the lower priority
+RemoteVideoTracks are switched off in order to preserve the quality of the higher
+priority RemoteVideoTracks.
when set to auto, SDK uses the visibility of the video elements attached to the to the RemoteVideoTrack to decide.
+on turning tracks on or off. The track that are not attached to any video elements or not visible on the screen will be turned
+off automatically.
+
+
+
+
+
+
+
manual
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+ manual
+
+
+
+
+
When set to manual, application can use RemoteVideoTracks switchOff and switchOn apis to control turn the track on or off.
PreflightTest has successfully generated synthetic tracks
+
+
+
+
+
+
+
connected
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+ connected
+
+
+
+
+
PreflightTest has successfully connected to twilio server and obtained turn credentials
+
+
+
+
+
+
+
mediaSubscribed
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+ mediaSubscribed
+
+
+
+
+
SubscriberParticipant successfully subscribed to media tracks.
+
+
+
+
+
+
+
mediaStarted
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+ mediaStarted
+
+
+
+
+
Media flow was detected.
+
+
+
+
+
+
+
dtlsConnected
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+ dtlsConnected
+
+
+
+
+
Established DTLS connection. This is measured from RTCDtlsTransport connecting to connected state.
+On Safari, Support for measuring this is missing, this event will be not be emitted on Safari.
+
+
+
+
+
+
+
peerConnectionConnected
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+ peerConnectionConnected
+
+
+
+
+
Established a PeerConnection, This is measured from PeerConnection connecting to connected state.
+On Firefox, Support for measuring this is missing, this event will be not be emitted on Firefox.
+
+
+
+
+
+
+
iceConnected
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+ iceConnected
+
+
+
+
+
Established ICE connection. This is measured from ICE connection checking to connected state.
when set to auto, SDK uses the sizes of the video elements attached to the to the RemoteVideoTrack dynamically to
+decide the render dimensions. RemoteVideoTracks rendered in smaller video elements will be given smaller bandwidth allocation
+compared to the tracks rendered in large video elements.
+
+
+
+
+
+
+
manual
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+ manual
+
+
+
+
+
When set to manual, application can use RemoteVideoTrack#setContentPreference to set the
+desired render dimensions for the RemoteVideoTrack.
BandwidthProfileOptions allows you to configure how your available downlink
+bandwidth is shared among the RemoteTracks you have subscribed to in a Group Room.
Whether or not to
+get local audio with getUserMedia when tracks
+are not provided.
+
+
+
+
+
+
+
automaticSubscription
+
+
+
+
+
+boolean
+
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+ true
+
+
+
+
+
By default, you will subscribe
+to all RemoteTracks shared by other Participants in a Room. You can now override this
+behavior by setting this flag to false. It will make sure that you will
+not subscribe to any RemoteTrack in a Group or Small Group Room. Setting it to
+true, or not setting it at all preserves the default behavior. This
+flag does not have any effect in a Peer-to-Peer Room.
You can optionally configure
+how your available downlink bandwidth is shared among the RemoteTracks you have subscribed
+to in a Group Room. By default, bandwidth is shared equally among the RemoteTracks.
+This has no effect in Peer-to-Peer Rooms.
+
+
+
+
+
+
+
dominantSpeaker
+
+
+
+
+
+boolean
+
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+ false
+
+
+
+
+
Whether to enable the Dominant
+Speaker API or not. This only takes effect in Group Rooms.
+
+
+
+
+
+
+
dscpTagging
+
+
+
+
+
+boolean
+
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+ false
+
+
+
+
+
(deprecated: use "enableDscp" instead)
+DSCP tagging allows you to request enhanced QoS treatment for RTP media packets from any
+firewall that the client may be behind. Setting this option to true will
+request DSCP tagging for media packets on supported browsers (only Chrome supports this
+as of now). Audio packets will be sent with DSCP header value set to 0xb8 which corresponds
+to Expedited Forwarding (EF). Video packets will be sent with DSCP header value set to 0x88
+which corresponds to Assured Forwarding (AF41).
+
+
+
+
+
+
+
enableDscp
+
+
+
+
+
+boolean
+
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+ false
+
+
+
+
+
DSCP tagging allows you to request enhanced
+QoS treatment for RTP media packets from any firewall that the client may be behind.
+Setting this option to true will request DSCP tagging for media packets
+on supported browsers (only Chrome supports this as of now). Audio packets will be
+sent with DSCP header value set to 0xb8 which corresponds to Expedited Forwarding (EF).
+Video packets will be sent with DSCP header value set to 0x88 which corresponds to
+Assured Forwarding (AF41).
(deprecated: use Video.Logger
+you can listen to fine-grained events related to signaling and media that are
+not available in the public APIs. These events might be useful for your own reporting
+and diagnostics.
+
+
+
+
+
+
+
iceServers
+
+
+
+
+
+Array.<RTCIceServer>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Override the STUN and TURN
+servers used when connecting to Rooms
+
+
+
+
+
+
+
iceTransportPolicy
+
+
+
+
+
+RTCIceTransportPolicy
+
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+ "all"
+
+
+
+
+
Override the
+ICE transport policy to be one of "relay" or "all"
+
+
+
+
+
+
+
insights
+
+
+
+
+
+boolean
+
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+ true
+
+
+
+
+
Whether publishing events
+to the Insights gateway is enabled or not
+
+
+
+
+
+
+
maxAudioBitrate
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+ <nullable>
+
+
+
+
+
+
+
+ null
+
+
+
+
+
Max outgoing audio bitrate (bps);
+A null or a 0 value 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 codecs; Based on our tests, Chrome, Firefox and Safari
+support a bitrate range of 12000 bps to 256000 bps for Opus codec; This parameter
+has no effect on iSAC, PCMU and PCMA codecs
+
+
+
+
+
+
+
maxVideoBitrate
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+ <nullable>
+
+
+
+
+
+
+
+ null
+
+
+
+
+
Max outgoing video bitrate (bps);
+A null or 0 value 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 codecs; Based on our tests, Chrome, Firefox and Safari
+all seem to support an average bitrate range of 20000 bps (20 kbps) to
+8000000 bps (8 mbps) for a 720p VideoTrack
+This parameter must not be set when when preferredVideoCodecs is set to auto.
The SDK raises warning events when it
+detects certain conditions. You can implement callbacks on these events to act on them, or to alert
+the user of an issue. Subsequently, "warningsCleared" event is raised when conditions have returned
+to normal. You can listen to these events by specifying an array of warning. By default,
+this array is empty and no warning events will be raised.
+Possible values include recording-media-lost, which is raised when the media server
+has not detected any media on the published track that is being recorded in the past 30 seconds.
+This usually happens when there are network interruptions or when the track has stopped.
+This warning is raised by LocalTrackPublication, LocalParticipant, and Room object.
+
+
+
+
+
+
+
region
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+ 'gll'
+
+
+
+
+
Preferred signaling region; By default, you will be connected to the
+nearest signaling server determined by latency based routing. Setting a value other
+than gll bypasses routing and guarantees that signaling traffic will be
+terminated in the region that you prefer. Please refer to this table
+for the list of supported signaling regions.
Preferred video codecs; when set to 'VideoEncodingMode.Auto', SDK manages the video codec,
+by preferring VP8 simulcast in group rooms. It also enables adaptive simulcast, which allows SDK
+to turn off simulcast layers that are not needed for efficient bandwidth and CPU usage.
+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
+VideoCodecs property.
+See
+here for more information.
(deprecated: use Video.Logger instead.
+See examples for details)
+Set the default log verbosity
+of logging. Passing a LogLevel string will use the same
+level for all components. Pass a LogLevels to set specific log
+levels.
+
+
+
+
+
+
+
loggerName
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+ 'twilio-video'
+
+
+
+
+
The name of the logger. Use this name when accessing the logger used by the SDK.
+See examples for details.
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().
(deprecated: use Video.Logger instead.
+See examples for details)
+Set the default log verbosity
+of logging. Passing a LogLevel string will use the same
+level for all components. Pass a LogLevels to set specific log
+levels.
+
+
+
+
+
+
+
loggerName
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+ 'twilio-video'
+
+
+
+
+
The name of the logger. Use this name when accessing the logger used by the SDK.
+See examples for details.
(deprecated: use Video.Logger instead.
+See examples for details)
+Set the default log verbosity
+of logging. Passing a LogLevel string will use the same
+level for all components. Pass a LogLevels to set specific log
+levels.
+
+
+
+
+
+
+
loggerName
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+ 'twilio-video'
+
+
+
+
+
The name of the logger. Use this name when accessing the logger used by the SDK.
+See examples for details.
Max outgoing audio bitrate (bps);
+If not specified, retains the existing bitrate limit; A null or a
+0 value removes any previously set bitrate limit; This value is set
+as a hint for variable bitrate codecs, but will not take effect for fixed bitrate
+codecs; Based on our tests, Chrome, Firefox and Safari support a bitrate range of
+12000 bps to 256000 bps for Opus codec; This parameter has no effect on iSAC, PCMU
+and PCMA codecs
+
+
+
+
+
+
+
maxVideoBitrate
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+ <nullable>
+
+
+
+
+
+
+
Max outgoing video bitrate (bps);
+If not specified, retains the existing bitrate limit; A null or
+a 0 value removes any previously set bitrate limit; This value is
+set as a hint for variable bitrate codecs, but will not take effect for fixed
+bitrate codecs; Based on our tests, Chrome, Firefox and Safari all seem to support
+an average bitrate range of 20000 bps (20 kbps) to 8000000 bps (8 mbps) for a
+720p VideoTrack.
+Note: this limit is not applied for screen share tracks published on Chrome.
An EventListener allows you to listen to fine-grained EventListenerEvents related
+to signaling and media that are not available in the public APIs, which might be useful for your own
+reporting and diagnostics.
An EventListenerEvent provides context about an event raised by the SDK on the
+EventListener. Apart from the properties listed here, it may also include some
+event-specific data within an optional "payload" property. The different types of
+EventListenerEvents are listed below:
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.
+
+
+
+
+
+
+
maxRetransmits
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+ <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.
+
+
+
+
+
+
+
ordered
+
+
+
+
+
+boolean
+
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+ true
+
+
+
+
+
Set this to false to allow data on the
+LocalDataTrack to be sent out-of-order.
The priority with which the LocalTrack
+is to be published; In Group or Small Group Rooms, the appropriate bandwidth is
+allocated to the LocalTrack based on its Track.Priority; It has no
+effect in Peer-to-Peer Rooms; It defaults to "standard" when not provided
The priority with which the LocalTrack
+is to be published; In Group or Small Group Rooms, the appropriate bandwidth is
+allocated to the LocalTrack based on its Track.Priority; It has no
+effect in Peer-to-Peer Rooms; It defaults to "standard" when not provided
Enable/disable discontinuous transmission (DTX);
+If enabled all published LocalAudioTracks will reduce the outgoing bitrate
+to near-zero whenever speech is not detected, resulting in bandwidth and CPU savings;
+It defaults to true.
You may pass these options to module:twilio-video.testPreflight in order to override the
+default behavior.
+
+
+
+
+
Type:
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+
+
Properties:
+
+
+
+
+
+
+
+
Name
+
+
+
Type
+
+
+
Argument
+
+
+
+
Default
+
+
+
Description
+
+
+
+
+
+
+
+
+
region
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+ 'gll'
+
+
+
+
+
Preferred signaling region; By default, you will be connected to the
+nearest signaling server determined by latency based routing. Setting a value other
+than gll bypasses routing and guarantees that signaling traffic will be
+terminated in the region that you prefer. Please refer to this table
+for the list of supported signaling regions.
+
+
+
+
+
+
+
duration
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+ 10000
+
+
+
+
+
number of milliseconds to run test for.
+once connected test will run for this duration before generating the stats report.
Optional parameter to
+specify the minimum subscribe Track.Priority of the Dominant Speaker's RemoteVideoTracks.
+This means that the Dominant Speaker's RemoteVideoTracks that are published with
+lower Track.Priority will be subscribed to with the Track.Priority specified here.
+This has no effect on RemoteVideoTracks published with higher Track.Priority, which will
+still be subscribed to with with the same Track.Priority. If not specified, this defaults to "standard".
+This parameter only applies to a Group Room Participant when ConnectOptions.dominantSpeaker is set to true.
+
+
+
+
+
+
+
maxSubscriptionBitrate
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
+
+
Optional parameter to specify the maximum
+downlink video bandwidth in bits per second (bps). By default, there are no limits on
+the downlink video bandwidth.
Optional parameter that determines
+when to turn the RemoteVideoTrack on or off. When set to "auto", SDK will use the visibility of the
+attached elements to determine if the RemoteVideoTrack should be turned off or on. When the attached video elements become invisible the RemoteVideoTrack will
+be turned off, and when elements become visible they will be turned on. When set to "manual" you can turn the RemoteVideoTrack
+on and off using the api RemoteVideoTrack#switchOn and RemoteVideoTrack#switchOff respectively.
This Optional parameter configures
+the mode for specifying content preferences for the RemoteVideoTrack. When set to "auto" the
+SDK determines the render dimensions by inspecting the attached video elements. RemoteVideoTracks rendered in smaller video elements
+will receive a lower resolution stream compared to the video rendered in larger video elements. When set to "manual" you can set
+the dimensions programmatically by calling RemoteVideoTrack#setContentPreferences.
+
+
+
+
+
+
+
maxTracks
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+
+
+
(deprecated: use "clientTrackSwitchOffControl" instead). Optional
+parameter to specify the maximum number of visible RemoteVideoTracks, which will be selected based on
+Track.Priority and an N-Loudest policy. By default there are no limits on the number of visible RemoteVideoTracks.
+0 or a negative value will remove any limit on the maximum number of visible RemoteVideoTracks.
Optional parameter to specify how the RemoteVideoTracks'
+TrackPriority values are mapped to bandwidth allocation in Group Rooms. This defaults to "grid",
+which results in equal bandwidth share allocation to all RemoteVideoTracks.
A callback to receive input and output frame buffers for processing.
+The input frame buffer contains the original video frame which can be used for additional processing
+such as applying filters to it. The output frame buffer is used to receive the processed video frame
+before sending to the encoder or renderer.
+
Any exception raised (either synchronously or asynchronously) in processFrame will result in the frame being dropped.
+This callback has the following signature:
Optional parameter to specify the desired rendering dimensions of
+RemoteVideoTrack whose Track.Priority is "high". 0 or a negative value will result in the lowest
+possible resolution. This defaults to 1280 x 720 (HD).
Optional parameter to specify the desired rendering dimensions of
+RemoteVideoTrack whose Track.Priority is "low". 0 or a negative value will result in the lowest
+possible resolution. This defaults to 176 x 144 (QCIF).
Optional parameter to specify the desired rendering dimensions of
+RemoteVideoTrack whose Track.Priority is "standard". 0 or a negative value will result in the lowest
+possible resolution. This defaults to 640 x 480 (VGA).
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Deprecated:
+
+
+
+
VideoRenderDimensions allows you to specify the desired render dimensions of RemoteVideoTracks.
+You can specify 'auto' for this field - which is also default value - based on Track.Priority. The bandwidth allocation algorithm will distribute the available downlink bandwidth
+proportional to the requested render dimensions. This is just an input for calculating the bandwidth to be allocated
+and does not affect the actual resolution of the RemoteVideoTracks.
We want your feedback! Please feel free to open a GitHub issue for suggested improvements or feature requests. If you need technical support, contact help@twilio.com.
If you're loading twilio-video.js from sdk.twilio.com,
+you should also include the following script-src directive:
+
script-src https://sdk.twilio.com
+
+
If you are enabling Krisp Noise Cancellation for
+your local audio, and you are using the following default-src self directive, you should also add the
+unsafe-eval directive:
+
default-src self unsafe-eval
+
+
Keep in mind, you may need to merge these policy directives with your own if
+you're using other services.
+
Building
+
Fork and clone the repository. Then, install dependencies with
+
npm install
+
+
Then run the build script:
+
npm run build
+
+
The builds and docs will be placed in the dist/ directory.
+
Testing
+
Run unit tests with
+
npm run test:unit
+
+
Run integration tests with
+
ACCOUNT_SID=<Your account sid> \
+API_KEY_SID=<Your api key sid> \
+API_KEY_SECRET=<Your api key secret> \
+BROWSER=<Browser you'd like to use> \
+npm run test:integration
+
+
You can add these optional variables to control the integration test execution :
+
+
Topology : Decides which type of rooms to test against.
+
Debug : To get better source mapping, and the browser does not close after tests are run which allows you to easily step through code to debug.
+
Test Files : Allows you to limit the test to just one file.
A LocalTrack failed to publish. Check the error message for more
+information. In a Large Group Room (Maximum Participants greater than 50),
+this event is raised with a ParticipantMaxTracksExceededError either
+when attempting to publish the LocalTrack will exceed the Maximum Published
+Tracks limit of 16, or the LocalTrack is part of a set of LocalTracks
+which along with the published Tracks exceeds 16.
One of the LocalParticipant's LocalTrackPublications encountered a warning.
+This event is only raised if you enabled warnings using notifyWarnings in ConnectOptions.
One of the LocalParticipant's LocalTrackPublications cleared all warnings.
+This event is only raised if you enabled warnings using notifyWarnings in ConnectOptions.
function trackPublished(publication) {
+ console.log(`Track ${publication.trackSid} was published`);
+}
+
+room.on('participantConnected', participant => {
+ // Handle RemoteTracks published while connecting to the Room.
+ participant.trackPublications.forEach(trackPublished);
+
+ // Handle RemoteTracks published after connecting to the Room.
+ participant.on('trackPublished', trackPublished);
+});
The Dominant Speaker in the Room changed. Either the Dominant Speaker
+is a new RemoteParticipant or the Dominant Speaker has been reset and
+is now null.
Your application is reconnecting to the Room. This happens when there
+is a disruption in your signaling connection and/or your media connection. When
+this event is emitted, the Room is in state "reconnecting". If reconnecting
+succeeds, the Room will emit a "reconnected" event.
A
+MediaConnectionError if your application is reconnecting due to a
+disruption in your media connection, or a SignalingConnectionDisconnectedError
+if your application is reconnecting due to a disruption in your signaling connection
function trackPublished(publication, participant) {
+ console.log(`RemoteParticipant ${participant.sid} published Track ${publication.trackSid}`);
+}
+
+// Handle RemoteTracks published after connecting to the Room.
+room.on('trackPublished', trackPublished);
+
+room.on('participantConnected', participant => {
+ // Handle RemoteTracks published while connecting to the Room.
+ participant.trackPublications.forEach(publication => trackPublished(publication, participant));
+});
One of the LocalParticipant's LocalTrackPublications in the Room encountered a warning.
+This event is only raised if you enabled warnings using notifyWarnings in ConnectOptions.
room.on('trackWarning', (name, publication, participant) => {
+ if (name === 'recording-media-lost') {
+ log(`LocalTrack ${publication.track.name} is not recording media.`,
+ name, publication, participant);
+
+ // Wait a reasonable amount of time to clear the warning.
+ const timer = setTimeout(() => {
+ // If the warning is not cleared, you can manually
+ // reconnect to the room, or show a dialog to the user
+ }, 5000);
+
+ room.once('trackWarningsCleared', (publication, participant) => {
+ log('LocalTrack warnings have cleared!',
+ publication, participant);
+ clearTimeout(timer);
+ });
+ }
+});
+
+
+
+
+
+
+
+
+
+
trackWarningsCleared
+
+
+
+
+
+
+
+
One of the LocalParticipant's LocalTrackPublications in the Room cleared all warnings.
+This event is only raised if you enabled warnings using notifyWarnings in ConnectOptions.
true if the current browser is officially
+supported by twilio-video.js; In this context, "supported" means that
+twilio-video.js has been extensively tested with this browser; This
+table
+specifies the list of officially supported browsers.
+
+
+
+
+
+
+
Logger
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+
The loglevel
+module used by the SDK. Use this object to access the internal loggers and perform actions as defined by the
+loglevel APIs.
+See connect for examples.
+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.
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.publishTrack(localTrack);
+ });
+});
+
+
var Video = require('twilio-video');
+
+// Request the LocalAudioTrack with a custom name
+// and krisp noise cancellation
+Video.createLocalAudioTrack({
+ name: 'microphone',
+ noiseCancellationOptions: {
+ vendor: 'krisp',
+ sdkAssetsPath: '/twilio-krisp-audio-plugin/1.0.0/dist'
+ }
+});
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);
+ });
+});
+
+
var Video = require('twilio-video');
+var localTracks;
+
+// Pre-acquire tracks to display camera preview.
+Video.createLocalTracks().then(function(tracks) {
+ localTracks = tracks;
+ var localVideoTrack = localTracks.find(track => track.kind === 'video');
+ divContainer.appendChild(localVideoTrack.attach());
+})
+
+// Later, join the Room with the pre-acquired LocalTracks.
+Video.connect('token', {
+ name: 'my-cool-room',
+ tracks: localTracks
+});
+
+
+
+
+
+
+
+
+
+
<static> createLocalVideoTrack( [options])
+
+
+
+
+
+
+
+
Request a LocalVideoTrack. Note that on mobile browsers,
+the camera can be reserved by only one LocalVideoTrack at any given
+time. If you attempt to create a second LocalVideoTrack, video frames
+will no longer be supplied to the first LocalVideoTrack.
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.publishTrack(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'
+});
+
+
+
+
+
+
+
+
+
+
<static> runPreflight(token, options)
+
+
+
+
+
+
+
+
Run a preflight test. This method will start a test to check the quality of network connection.
A LocalTrack failed to publish. Check the error message for more
+information. In a Large Group Room (Maximum Participants greater than 50),
+this event is raised with a ParticipantMaxTracksExceededError either
+when attempting to publish the LocalTrack will exceed the Maximum Published
+Tracks limit of 16, or the LocalTrack is part of a set of LocalTracks
+which along with the published Tracks exceeds 16.
One of the LocalParticipant's LocalTrackPublications encountered a warning.
+This event is only raised if you enabled warnings using notifyWarnings in ConnectOptions.
One of the LocalParticipant's LocalTrackPublications cleared all warnings.
+This event is only raised if you enabled warnings using notifyWarnings in ConnectOptions.
function trackPublished(publication) {
+ console.log(`Track ${publication.trackSid} was published`);
+}
+
+room.on('participantConnected', participant => {
+ // Handle RemoteTracks published while connecting to the Room.
+ participant.trackPublications.forEach(trackPublished);
+
+ // Handle RemoteTracks published after connecting to the Room.
+ participant.on('trackPublished', trackPublished);
+});
The Dominant Speaker in the Room changed. Either the Dominant Speaker
+is a new RemoteParticipant or the Dominant Speaker has been reset and
+is now null.
Your application is reconnecting to the Room. This happens when there
+is a disruption in your signaling connection and/or your media connection. When
+this event is emitted, the Room is in state "reconnecting". If reconnecting
+succeeds, the Room will emit a "reconnected" event.
A
+MediaConnectionError if your application is reconnecting due to a
+disruption in your media connection, or a SignalingConnectionDisconnectedError
+if your application is reconnecting due to a disruption in your signaling connection
function trackPublished(publication, participant) {
+ console.log(`RemoteParticipant ${participant.sid} published Track ${publication.trackSid}`);
+}
+
+// Handle RemoteTracks published after connecting to the Room.
+room.on('trackPublished', trackPublished);
+
+room.on('participantConnected', participant => {
+ // Handle RemoteTracks published while connecting to the Room.
+ participant.trackPublications.forEach(publication => trackPublished(publication, participant));
+});
One of the LocalParticipant's LocalTrackPublications in the Room encountered a warning.
+This event is only raised if you enabled warnings using notifyWarnings in ConnectOptions.
room.on('trackWarning', (name, publication, participant) => {
+ if (name === 'recording-media-lost') {
+ log(`LocalTrack ${publication.track.name} is not recording media.`,
+ name, publication, participant);
+
+ // Wait a reasonable amount of time to clear the warning.
+ const timer = setTimeout(() => {
+ // If the warning is not cleared, you can manually
+ // reconnect to the room, or show a dialog to the user
+ }, 5000);
+
+ room.once('trackWarningsCleared', (publication, participant) => {
+ log('LocalTrack warnings have cleared!',
+ publication, participant);
+ clearTimeout(timer);
+ });
+ }
+});
+
+
+
+
+
+
+
+
+
+
trackWarningsCleared
+
+
+
+
+
+
+
+
One of the LocalParticipant's LocalTrackPublications in the Room cleared all warnings.
+This event is only raised if you enabled warnings using notifyWarnings in ConnectOptions.