LocalParticipant
Summary
LocalParticipant represents the local user of the room.Properties
audioTracks
Map of track sid => all published audio tracks
identity
Participant's assigned identity (retrieved from the JWT token).
Type
string
isSpeaking
True if the participant is currently speaking
Type
boolean
isSpeakingLevel
The current audio level estimate of a speaker between 0 and 1.0, 1 being loudest,
0 being softest.
Remarks
This member is only updated when the order of loudest speakers changes.Type
number
lastSpokeAt
optional
Date when participant last spoke
Date when participant last spoke
Type
Date
metadata
optional
Participant's metadata.
Participant's metadata.
Type
string
name
optional
Participant's assigned display name (retrieved from the JWT token).
Participant's assigned display name (retrieved from the JWT token).
Type
string
permissions
optional
Participant's permissions.
Participant's permissions.
Type
ParticipantPermission
sid
Server assigned unique id
Type
string
tracks
Map of track sid => all published tracks
videoTracks
Map of track sid => all published video tracks
Accessors
connectionQuality
Returns the current connection quality of the participant.
Type
ConnectionQuality
isCameraEnabled
True if the participant has enabled their camera.
Type
boolean
isMicrophoneEnabled
True if the participant has enabled their microphone.
Type
boolean
isScreenShareEnabled
True if the participant is currently sharing their screen.
Type
boolean
joinedAt
Date when the participant joined the room.
Type
undefined
| Date
Methods
createScreenTracks
Creates a screen capture tracks with getDisplayMedia().
A LocalVideoTrack is always created and returned.
Signature
createScreenTracks(options?: ScreenShareCaptureOptions)
Name | Type | Description |
---|---|---|
options optional | ScreenShareCaptureOptions |
Remarks
If { audio: true }
, and the browser supports audio capture, a LocalAudioTrack is also created.createTracks
Create local camera and/or microphone tracks
Signature
createTracks(options?: CreateLocalTracksOptions)
Name | Type | Description |
---|---|---|
options optional | CreateLocalTracksOptions |
enableCameraAndMicrophone
Publish both camera and microphone at the same time. This is useful for
displaying a single Permission Dialog box to the end user.
Signature
enableCameraAndMicrophone()
Returns
Promise
<void
>getPosition
Returns the position of the participant.
Signature
getPosition()
Returns
Vector3D
💡
This is not the position of the AudioListener. And will be (0,0,0) if
the position has not been set.
getTracks
Returns a list of all tracks published by the participant.
Signature
getTracks()
Returns
TrackPublication[]
publishData
Publish a new data payload to the room. Data will be forwarded to each
participant in the room if the destination field in publishOptions is empty
Signature
publishData(data: Uint8Array, kind: DataPacket_Kind, publishOptions?: DataPublishOptions)
Name | Type | Description |
---|---|---|
data | Uint8Array | Uint8Array of the payload. To send string data, use TextEncoder.encode |
kind | DataPacket_Kind | whether to send this as reliable or lossy. For data that you need delivery guarantee (such as chat messages), use Reliable. |
For data that should arrive as quickly as possible, but you are ok with dropped | ||
packets, use Lossy. | ||
publishOptions optional | DataPublishOptions | optionally specify a topic and destination |
Returns
Promise
<void
>publishTrack
Publish a new track to the room
Signature
publishTrack(track: MediaStreamTrack | LocalTrack, options?: TrackPublishOptions)
Name | Type | Description |
---|---|---|
track | MediaStreamTrack | LocalTrack | |
options optional | TrackPublishOptions |
setCameraEnabled
Enable or disable a participant's camera track.
If a track has already published, it'll mute or unmute the track.
Resolves with a
LocalTrackPublication
instance if successful and undefined
otherwiseSignature
setCameraEnabled(enabled: boolean, options?: VideoCaptureOptions, publishOptions?: TrackPublishOptions)
Name | Type | Description |
---|---|---|
enabled | boolean | |
options optional | VideoCaptureOptions | |
publishOptions optional | TrackPublishOptions |
Returns
Promise
<undefined | LocalTrackPublication
>setMetadata
Sets and updates the metadata of the local participant.
Note: this requires
CanUpdateOwnMetadata
permission encoded in the token.Signature
setMetadata(metadata: string)
Name | Type | Description |
---|---|---|
metadata | string |
Returns
void
setMicrophoneEnabled
Enable or disable a participant's microphone track.
If a track has already published, it'll mute or unmute the track.
Resolves with a
LocalTrackPublication
instance if successful and undefined
otherwiseSignature
setMicrophoneEnabled(enabled: boolean, options?: AudioCaptureOptions, publishOptions?: TrackPublishOptions)
Name | Type | Description |
---|---|---|
enabled | boolean | |
options optional | AudioCaptureOptions | |
publishOptions optional | TrackPublishOptions |
Returns
Promise
<undefined | LocalTrackPublication
>💡
The first time microphone access is requested, this methods tries to resume the
audio context. It must therefore be called from a user action handler (e.g. click handler)
in order to succeed.
setName
Sets and updates the name of the local participant.
Note: this requires
CanUpdateOwnMetadata
permission encoded in the token.Signature
setName(name: string)
Name | Type | Description |
---|---|---|
name | string |
Returns
void
setPosition
Sets the position of the local participant.
Signature
setPosition(x: number, y: number, z: number)
Name | Type | Description |
---|---|---|
x | number | x-coordinate |
y | number | y-coordinate |
z | number | z-coordinate |
Returns
void
Remarks
This position is broadcasted to other participants in the room if
the PositionSync feature is enabled (see positionSync).Note, this will not set the position of the AudioListener as it may
differ from the position of the participant. To set the position of the
AudioListener, use setPosition.
setScreenShareEnabled
Start or stop sharing a participant's screen
Resolves with a
LocalTrackPublication
instance if successful and undefined
otherwiseSignature
setScreenShareEnabled(enabled: boolean, options?: ScreenShareCaptureOptions, publishOptions?: TrackPublishOptions)
Name | Type | Description |
---|---|---|
enabled | boolean | |
options optional | ScreenShareCaptureOptions | |
publishOptions optional | TrackPublishOptions |
Returns
Promise
<undefined | LocalTrackPublication
>setTrackSubscriptionPermissions
Control who can subscribe to LocalParticipant's published tracks.
By default, all participants can subscribe. This allows fine-grained control over
who is able to subscribe at a participant and track level.
Note: if access is given at a track-level (i.e. both [allParticipantsAllowed] and
[ParticipantTrackPermission.allTracksAllowed] are false), any newer published tracks
will not grant permissions to any participants and will require a subsequent
permissions update to allow subscription.
Signature
setTrackSubscriptionPermissions(allParticipantsAllowed: boolean, participantTrackPermissions: ParticipantTrackPermission[])
Name | Type | Description |
---|---|---|
allParticipantsAllowed | boolean | Allows all participants to subscribe all tracks. Takes precedence over participantTrackPermissions if set to true. |
By default this is set to true. | ||
participantTrackPermissions | ParticipantTrackPermission[] | Full list of individual permissions per participant/track. Any omitted participants will not receive any permissions. |
Returns
void
unpublishTrack
Unpublish a track from the room
Signature
unpublishTrack(track: MediaStreamTrack | LocalTrack, stopOnUnpublish?: boolean)
Name | Type | Description |
---|---|---|
track | MediaStreamTrack | LocalTrack | The track to unpublish. |
stopOnUnpublish optional | boolean | Whether to stop the track after unpublishing. |
Returns
Promise
<undefined | LocalTrackPublication
> Promise resolving in the publication that was unpublished or undefined.
if no publication was found.unpublishTracks
Unpublish several tracks at once.
Signature
unpublishTracks(tracks: MediaStreamTrack[] | LocalTrack[])
Name | Type | Description |
---|---|---|
tracks | MediaStreamTrack[] | LocalTrack[] |