Skip to main content
The 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

sid
Participant.Sid?
Server-assigned unique identifier
identity
Participant.Identity?
Unique identity of the participant
name
String?
Display name of the participant
metadata
String?
Custom metadata associated with the participant
attributes
[String: String]
Key-value attributes for the participant
permissions
ParticipantPermissions
Participant’s permissions (can publish, subscribe, etc.)
trackPublications
[Track.Sid: TrackPublication]
All track publications from this participant
audioTracks
[TrackPublication]
All audio track publications
videoTracks
[TrackPublication]
All video track publications

LocalParticipant-Specific

localAudioTracks
[LocalTrackPublication]
All local audio track publications
localVideoTracks
[LocalTrackPublication]
All local video track publications

Publishing Tracks

publish(audioTrack:options:)

Publishes a local audio track to the room.
audioTrack
LocalAudioTrack
required
The audio track to publish
options
AudioPublishOptions?
Publishing options (encoding, DTX, RED, etc.)
Returns: LocalTrackPublication - The publication for the published track Throws: Error if publishing fails
let audioTrack = LocalAudioTrack.createTrack()
try await room.localParticipant.publish(audioTrack: audioTrack)

publish(videoTrack:options:)

Publishes a local video track to the room.
videoTrack
LocalVideoTrack
required
The video track to publish
options
VideoPublishOptions?
Publishing options (encoding, simulcast, degradation preference, etc.)
Returns: LocalTrackPublication - The publication for the published track Throws: Error if publishing fails
let videoTrack = LocalVideoTrack.createCameraTrack()
try await room.localParticipant.publish(videoTrack: videoTrack)

unpublish(publication:notify:)

Unpublishes a previously published track.
publication
LocalTrackPublication
required
The publication to unpublish
notify
Bool
Whether to notify delegates (default: true)
Throws: Error if unpublishing fails
if let publication = room.localParticipant.getTrackPublication(source: .camera) as? LocalTrackPublication {
    try await room.localParticipant.unpublish(publication: publication)
}

Simplified Track Management

setCamera(enabled:captureOptions:publishOptions:)

Enable or disable the camera.
enabled
Bool
required
true to enable camera, false to disable
captureOptions
CameraCaptureOptions?
Camera capture settings (resolution, frame rate, position)
publishOptions
VideoPublishOptions?
Video publishing options
Returns: LocalTrackPublication? - The camera track publication, or nil if disabled
try await room.localParticipant.setCamera(enabled: true)

setMicrophone(enabled:captureOptions:publishOptions:)

Enable or disable the microphone.
enabled
Bool
required
true to enable microphone, false to disable
captureOptions
AudioCaptureOptions?
Audio capture settings
publishOptions
AudioPublishOptions?
Audio publishing options
Returns: LocalTrackPublication? - The microphone track publication, or nil if disabled
try await room.localParticipant.setMicrophone(enabled: true)

setScreenShare(enabled:)

Enable or disable screen sharing.
enabled
Bool
required
true to start screen sharing, false to stop
Returns: LocalTrackPublication? - 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.
try await room.localParticipant.setScreenShare(enabled: true)

Publishing Data

publish(data:options:)

Publish arbitrary data to other participants in the room.
data
Data
required
Binary data to send (max 15KB per packet)
options
DataPublishOptions?
Options for data publishing (reliable/lossy, destination identities, topic)
Throws: Error if publishing fails
let message = "Hello, room!".data(using: .utf8)!
try await room.localParticipant.publish(
    data: message,
    options: DataPublishOptions(reliable: true, topic: "chat")
)

Metadata and Attributes

set(metadata:)

Update the participant’s metadata.
metadata
String
required
New metadata string
Throws: Error if update fails Requires CanUpdateOwnMetadata permission in the JWT token.
try await room.localParticipant.set(metadata: "{\"status\": \"available\"}")

set(name:)

Update the participant’s display name.
name
String
required
New display name
Throws: Error if update fails Requires CanUpdateOwnMetadata permission in the JWT token.
try await room.localParticipant.set(name: "John Doe")

set(attributes:)

Update the participant’s attributes.
attributes
[String: String]
required
Dictionary of key-value attributes
Throws: Error if update fails
try await room.localParticipant.set(attributes: ["role": "moderator"])

Track Subscription Permissions

setTrackSubscriptionPermissions(allParticipantsAllowed:trackPermissions:)

Control who can subscribe to this participant’s tracks.
allParticipantsAllowed
Bool
required
If true, all participants can subscribe to all tracks (default)
trackPermissions
[ParticipantTrackPermission]
Fine-grained permissions per participant/track
Throws: Error if update fails
// Only allow specific participants to subscribe
try await room.localParticipant.setTrackSubscriptionPermissions(
    allParticipantsAllowed: false,
    trackPermissions: [
        ParticipantTrackPermission(
            participantIdentity: "user123",
            allTracksAllowed: true
        )
    ]
)

Usage Example

import LiveKit

class MyRoomManager {
    let room = Room()
    
    func joinAndPublish() async throws {
        try await room.connect(
            url: "wss://your-host.livekit.cloud",
            token: "your_jwt_token"
        )
        
        // Publish camera and microphone
        try await room.localParticipant.setCamera(enabled: true)
        try await room.localParticipant.setMicrophone(enabled: true)
        
        // Update metadata
        try await room.localParticipant.set(metadata: "{\"status\": \"active\"}")
        
        // Send a data message
        let data = "Hello!".data(using: .utf8)!
        try await room.localParticipant.publish(
            data: data,
            options: DataPublishOptions(reliable: true)
        )
    }
}

Helper Methods

isCameraEnabled()
Bool
Returns true if camera is currently enabled and unmuted
isMicrophoneEnabled()
Bool
Returns true if microphone is currently enabled and unmuted
isScreenShareEnabled()
Bool
Returns true if screen share is currently active

See Also

Build docs developers (and LLMs) love