Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/livekit/client-sdk-swift/llms.txt

Use this file to discover all available pages before exploring further.

The LiveKit Swift SDK provides simple methods to enable and configure camera and microphone tracks for local participants.

Enable Camera

Use setCamera(enabled:) to publish or unpublish the camera track:
try await room.localParticipant.setCamera(enabled: true)
To disable the camera:
try await room.localParticipant.setCamera(enabled: false)

Camera Capture Options

Configure camera capture settings using CameraCaptureOptions:
let captureOptions = CameraCaptureOptions(
    dimensions: .h1080_169,
    fps: 30
)

try await room.localParticipant.setCamera(
    enabled: true,
    captureOptions: captureOptions
)

Camera Publish Options

Control how the camera track is published using VideoPublishOptions:
let publishOptions = VideoPublishOptions(
    encoding: VideoEncoding(
        maxBitrate: 3_000_000,
        maxFps: 30
    )
)

try await room.localParticipant.setCamera(
    enabled: true,
    publishOptions: publishOptions
)

Enable Microphone

Use setMicrophone(enabled:) to publish or unpublish the microphone track:
try await room.localParticipant.setMicrophone(enabled: true)
To disable the microphone:
try await room.localParticipant.setMicrophone(enabled: false)

Audio Capture Options

Configure audio capture using AudioCaptureOptions:
let captureOptions = AudioCaptureOptions(
    echoCancellation: true,
    noiseSuppression: true
)

try await room.localParticipant.setMicrophone(
    enabled: true,
    captureOptions: captureOptions
)

Audio Publish Options

Control how audio is published using AudioPublishOptions:
let publishOptions = AudioPublishOptions(
    encoding: .presetMusic,  // Or .presetSpeech
    dtx: true,               // Discontinuous transmission
    red: true                // Redundant encoding
)

try await room.localParticipant.setMicrophone(
    enabled: true,
    publishOptions: publishOptions
)

Setting Default Options

Set default capture and publish options when creating a room:
let roomOptions = RoomOptions(
    defaultCameraCaptureOptions: CameraCaptureOptions(
        dimensions: .h720_169,
        fps: 30
    ),
    defaultAudioCaptureOptions: AudioCaptureOptions(),
    defaultVideoPublishOptions: VideoPublishOptions(),
    defaultAudioPublishOptions: AudioPublishOptions()
)

let room = Room(roomOptions: roomOptions)

Mute and Unmute

For camera and microphone tracks, calling setCamera(enabled: false) or setMicrophone(enabled: false) will mute the track without unpublishing it:
// Mute microphone (keeps track published)
try await room.localParticipant.setMicrophone(enabled: false)

// Unmute microphone
try await room.localParticipant.setMicrophone(enabled: true)
You can also use the track publication to mute/unmute:
if let publication = room.localParticipant.getTrackPublication(source: .microphone) as? LocalTrackPublication {
    try await publication.mute()
    try await publication.unmute()
}

Advanced: Manual Track Publishing

For more control, create and publish tracks manually:
// Create camera track
let cameraTrack = LocalVideoTrack.createCameraTrack(
    options: CameraCaptureOptions(dimensions: .h1080_169)
)

// Publish the track
try await room.localParticipant.publish(videoTrack: cameraTrack)

// Create microphone track
let microphoneTrack = LocalAudioTrack.createTrack()

// Publish the track
try await room.localParticipant.publish(audioTrack: microphoneTrack)

Checking Track State

Check if camera or microphone is currently enabled:
// Check if camera is enabled
let isCameraEnabled = room.localParticipant.isCameraEnabled()

// Check if microphone is enabled  
let isMicrophoneEnabled = room.localParticipant.isMicrophoneEnabled()

See Also

  • LocalParticipant.swift:322 (setCamera(enabled:captureOptions:publishOptions:))
  • LocalParticipant.swift:334 (setMicrophone(enabled:captureOptions:publishOptions:))