LocalParticipant class represents the current user in a LiveKit room. It provides methods for publishing audio/video tracks, sending data, and managing local media sources.
Overview
LocalParticipant extends Participant and is accessed via room.localParticipant. It handles publishing local tracks (camera, microphone, screen share) and sending data to other participants.
Properties
Inherited from Participant
Server-assigned unique identifier
Unique identity of the participant
Display name of the participant
Custom metadata associated with the participant
Key-value attributes for the participant
Participant’s permissions (can publish, subscribe, etc.)
All track publications from this participant
All audio track publications
All video track publications
LocalParticipant-Specific
All local audio track publications
All local video track publications
Publishing Tracks
publish(audioTrack:options:)
Publishes a local audio track to the room.The audio track to publish
Publishing options (encoding, DTX, RED, etc.)
LocalTrackPublication - The publication for the published track
Throws: Error if publishing fails
publish(videoTrack:options:)
Publishes a local video track to the room.The video track to publish
Publishing options (encoding, simulcast, degradation preference, etc.)
LocalTrackPublication - The publication for the published track
Throws: Error if publishing fails
unpublish(publication:notify:)
Unpublishes a previously published track.The publication to unpublish
Whether to notify delegates (default:
true)Simplified Track Management
setCamera(enabled:captureOptions:publishOptions:)
Enable or disable the camera.true to enable camera, false to disableCamera capture settings (resolution, frame rate, position)
Video publishing options
LocalTrackPublication? - The camera track publication, or nil if disabled
setMicrophone(enabled:captureOptions:publishOptions:)
Enable or disable the microphone.true to enable microphone, false to disableAudio capture settings
Audio publishing options
LocalTrackPublication? - The microphone track publication, or nil if disabled
setScreenShare(enabled:)
Enable or disable screen sharing.true to start screen sharing, false to stopLocalTrackPublication? - The screen share track publication, or nil if disabled
On iOS, this uses InAppScreenCapturer for in-app screen capture. For system-wide screen sharing, use a Broadcast Upload Extension.
On macOS, this captures the main display using MacOSScreenCapturer.
Publishing Data
publish(data:options:)
Publish arbitrary data to other participants in the room.Binary data to send (max 15KB per packet)
Options for data publishing (reliable/lossy, destination identities, topic)
Metadata and Attributes
set(metadata:)
Update the participant’s metadata.New metadata string
CanUpdateOwnMetadata permission in the JWT token.
set(name:)
Update the participant’s display name.New display name
CanUpdateOwnMetadata permission in the JWT token.
set(attributes:)
Update the participant’s attributes.Dictionary of key-value attributes
Track Subscription Permissions
setTrackSubscriptionPermissions(allParticipantsAllowed:trackPermissions:)
Control who can subscribe to this participant’s tracks.If
true, all participants can subscribe to all tracks (default)Fine-grained permissions per participant/track
Usage Example
Helper Methods
Returns
true if camera is currently enabled and unmutedReturns
true if microphone is currently enabled and unmutedReturns
true if screen share is currently active