Class: LocalParticipant

LocalParticipant

A LocalParticipant represents the local Participant in a Room.

Extends

Methods


publishTrack(localTrack [, options])

Publishes a LocalTrack to the Room.

Parameters:
Name Type Argument Description
localTrack LocalTrack

The LocalTrack to publish

options LocalTrackPublishOptions <optional>

The LocalTrackPublishOptions for publishing the LocalTrack

Throws:
  • TypeError
  • RangeError
Returns:
Type
Promise.<LocalTrackPublication>
Example
var Video = require('twilio-video');

Video.connect(token, {
  name: 'my-cool-room',
  audio: true
}).then(function(room) {
  return Video.createLocalVideoTrack({
    name: 'camera'
  }).then(function(localVideoTrack) {
    return room.localParticipant.publishTrack(localVideoTrack, {
      priority: 'high'
    });
  });
}).then(function(publication) {
  console.log('The LocalTrack "' + publication.trackName
    + '" was successfully published with priority "'
    * publication.priority + '"');
});
  

publishTrack(mediaStreamTrack [, options])

Publishes a MediaStreamTrack to the Room.

Parameters:
Name Type Argument Description
mediaStreamTrack MediaStreamTrack

The MediaStreamTrack to publish; if a corresponding LocalAudioTrack or LocalVideoTrack has not yet been published, this method will construct one

options MediaStreamTrackPublishOptions <optional>

The options for publishing the MediaStreamTrack

Throws:
  • TypeError
  • RangeError
Returns:
Type
Promise.<LocalTrackPublication>
Example
var Video = require('twilio-video');

Video.connect(token, {
  name: 'my-cool-room',
  audio: true
}).then(function(room) {
  return navigator.mediaDevices.getUserMedia({
    video: true
  }).then(function(mediaStream) {
    var mediaStreamTrack = mediaStream.getTracks()[0];
    return room.localParticipant.publishTrack(mediaStreamTrack, {
      name: 'camera',
      priority: 'high'
    });
  });
}).then(function(publication) {
  console.log('The LocalTrack "' + publication.trackName
    + '" was successfully published with priority "'
    * publication.priority + '"');
});

publishTracks(tracks)

Publishes multiple LocalTracks to the Room.

Parameters:
Name Type Description
tracks Array.<(LocalTrack|MediaStreamTrack)>

The LocalTracks to publish; for any MediaStreamTracks provided, if a corresponding LocalAudioTrack or LocalVideoTrack has not yet been published, this method will construct one

Throws:
TypeError
Returns:
Type
Promise.<Array.<LocalTrackPublication>>

setNetworkQualityConfiguration(networkQualityConfiguration)

Sets the NetworkQualityVerbosity for the LocalParticipant and RemoteParticipants. It does nothing if Network Quality is not enabled while calling connect.

Parameters:
Name Type Description
networkQualityConfiguration NetworkQualityConfiguration

The new NetworkQualityConfiguration; If either or both of the local and remote NetworkQualityVerbosity values are absent, then the corresponding existing values are retained

Returns:
Type
this
Examples
// Update verbosity levels for both LocalParticipant and RemoteParticipants
localParticipant.setNetworkQualityConfiguration({
  local: 1,
  remote: 2
});
// Update verbosity level for only the LocalParticipant
localParticipant.setNetworkQualityConfiguration({
  local: 1
});
 
// Update verbosity level for only the RemoteParticipants
localParticipant.setNetworkQualityConfiguration({
  remote: 2
});

setParameters( [encodingParameters])

Parameters:
Name Type Argument Description
encodingParameters EncodingParameters <optional>
<nullable>

The new EncodingParameters; If null, then the bitrate limits are removed; If not specified, then the existing bitrate limits are preserved

Throws:
TypeError
Returns:
Type
this

unpublishTrack(track)

Stops publishing a LocalTrack to the Room.

Parameters:
Name Type Description
track LocalTrack | MediaStreamTrack

The LocalTrack to stop publishing; if a MediaStreamTrack is provided, this method looks up the corresponding LocalAudioTrack or LocalVideoTrack to stop publishing

Throws:
TypeError
Returns:
Type
LocalTrackPublication

unpublishTracks(tracks)

Stops publishing multiple LocalTracks to the Room.

Parameters:
Name Type Description
tracks Array.<(LocalTrack|MediaStreamTrack)>

The LocalTracks to stop publishing; for any MediaStreamTracks provided, this method looks up the corresponding LocalAudioTrack or LocalVideoTrack to stop publishing

Throws:
TypeError
Returns:
Type
Array.<LocalTrackPublication>

Events


disconnected

The Participant has disconnected.

Parameters:
Name Type Description
participant Participant

The Participant that disconnected.

Inherited From:
Overrides:

networkQualityLevelChanged

Parameters:
Name Type Argument Description
networkQualityLevel NetworkQualityLevel

The new NetworkQualityLevel

networkQualityStats NetworkQualityStats <nullable>

The NetworkQualityStats based on which NetworkQualityLevel is calculated, if any

Inherited From:
Overrides:

reconnected

The LocalParticipant has reconnected to the Room after a signaling connection disruption.

Overrides:

reconnecting

The LocalParticipant is reconnecting to the Room after a signaling connection disruption.

Overrides:

trackDimensionsChanged

One of the LocalParticipant's LocalVideoTrack's dimensions changed.

Parameters:
Name Type Description
track LocalVideoTrack

The LocalVideoTrack whose dimensions changed

Overrides:

trackDisabled

A LocalTrack was disabled by the LocalParticipant.

Parameters:
Name Type Description
track LocalTrack

The LocalTrack that was disabled


trackEnabled

A LocalTrack was enabled by the LocalParticipant.

Parameters:
Name Type Description
track LocalTrack

The LocalTrack that was enabled


trackPublicationFailed

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.

Parameters:
Name Type Description
error TwilioError

A TwilioError explaining why publication failed

localTrack LocalTrack

The LocalTrack that failed to publish


trackPublished

A LocalTrack was successfully published.

Parameters:
Name Type Description
publication LocalTrackPublication

The resulting LocalTrackPublication for the published LocalTrack


trackStarted

One of the LocalParticipant's LocalTracks started.

Parameters:
Name Type Description
track LocalTrack

The LocalTrack that started

Overrides:

trackStopped

One of the LocalParticipant's LocalTracks stopped, either because LocalTrack#stop was called or because the underlying MediaStreamTrack ended).

Parameters:
Name Type Description
track LocalTrack

The LocalTrack that stopped