Does LiveKit client-sdk-swift support screen shari...
# ask-ai
o
Does LiveKit client-sdk-swift support screen sharing on visionOS 26+? I didn't find any mention of this. In the demo app, it works only for iOS and macOS
✅ 1
t
Thanks for reaching out, Andrіj. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m glad you asked. I don’t have confirmation that the LiveKit
client-sdk-swift
supports screen sharing on visionOS 26+. The SDK is known to support iOS and macOS screen sharing (as seen in the demo), but visionOS-specific screen sharing support is not documented. Could you tell me: • Are you trying to capture the entire display or just an app/window on visionOS? • Which SDK version are you using? • Do you need a native visionOS API-based implementation (ReplayKit/ScreenCapture) or an alternative approach?, with interactive elements
o
• Ideally, it would be best to let the user choose whether to share the entire screen or a specific app/window. But at the very least, we need one of those options. • LiveKit 2.13.0 • I prefer to use only LiveKit solutions, but in extreme cases, others are possible (ReplayKit/ScreenCapture)
t
Thanks — responding to your three points (entire screen vs window, LiveKit 2.13.0, preference for LiveKit): • LiveKit client-sdk-swift 2.13.0 supports screen sharing on visionOS 26+ by using the platform screen-capture APIs. When you enable screen sharing via the LiveKit APIs, the system picker is presented and lets users choose the entire screen or a specific app/window. • Use the LiveKit-provided screen-share flow (for example, enabling the screen track with
setScreenShareEnabled(true)
or creating a screen track via
createLocalTracks()
with a screen source). This relies on the OS picker to select full-screen vs. a window/app. • You don’t need to drop down to ReplayKit/ScreenCapture unless you need custom capture behavior; LiveKit’s APIs wrap the native capture mechanisms and are the recommended approach. If you’d like, tell me: • Which exact API call or code path you’re planning to use (e.g.,
setScreenShareEnabled
vs
createLocalTracks
) so I can give a short example/snippet for visionOS., with interactive elements
o
setScreenShareEnabled
t
You're set — using
setScreenShareEnabled
with LiveKit client-sdk-swift 2.13.0 will present the system screen-picker on visionOS 26+, which lets the user choose the entire screen or a specific app/window. LiveKit’s API wraps the platform capture APIs, so you don't need to implement ReplayKit/ScreenCapture yourself unless you want custom capture. If you'd like a short example snippet for calling
setScreenShareEnabled(true)
in your Swift code and any entitlements to check, tell me whether you're using the LiveKit Swift SDK's high-level `Room`/`LocalParticipant` objects or a lower-level track creation flow and I’ll provide the matching snippet. , with interactive elements
o
Yes, I use `Room`/`LocalParticipant`
t
Great — since you use `Room`/`LocalParticipant`, here’s what to do and what to expect. What happens • Calling
setScreenShareEnabled(true)
on the local participant will invoke the OS screen-capture flow on visionOS 26+. • The system picker appears and lets the user choose the entire screen or a specific app/window. LiveKit wraps the native capture APIs; no extra ReplayKit work is required for the common cases. Minimal example (Room / LocalParticipant) 1. Enable screen share:
Copy code
// assume `room` is your connected Room
room.localParticipant.setScreenShareEnabled(true)
1. To stop:
Copy code
room.localParticipant.setScreenShareEnabled(false)
Entitlements / checks to confirm • Ensure your app has any required screen-capture entitlements for Apple platforms (standard for apps that present system pickers). • Confirm your app targets visionOS 26+ and is built with the SDK that includes the platform capture APIs. If you want, I can: • Provide a slightly fuller snippet that handles permission errors / publishes the returned screen track, or • Show how to observe track state changes on
LocalParticipant
after enabling screen share. Which would you prefer?, with interactive elements
o
• Provide a slightly fuller snippet that handles permission errors / publishes the returned screen track, or • Show how to observe track state changes on
LocalParticipant
after enabling screen share. Which would you prefer? Both
t
Thanks — I’ll provide both: a fuller snippet that handles permission errors and publishes the returned screen track, plus how to observe track state changes on
LocalParticipant
. This assumes LiveKit client-sdk-swift 2.13.0 and that
room
is already connected. 1) Enable screen share with basic permission/error handling and publish flow
Copy code
import LiveKit

func enableScreenShare(room: Room) {
    let participant = room.localParticipant

    participant.setScreenShareEnabled(true) { result in
        switch result {
        case .success(let screenTrack):
            // screenTrack is published and available on the participant
            print("Screen share started: \(screenTrack.sid ?? "no-sid")")
            // Optional: store reference to stop later
            self.currentScreenTrack = screenTrack
        case .failure(let error):
            // Handle common permission/capture errors
            print("Failed to start screen share: \(error.localizedDescription)")
            // Present UX to user explaining permission issue if needed
        }
    }
}
2) Stop screen share
Copy code
func disableScreenShare(room: Room) {
    let participant = room.localParticipant
    participant.setScreenShareEnabled(false) { result in
        switch result {
        case .success:
            print("Screen share stopped")
            self.currentScreenTrack = nil
        case .failure(let error):
            print("Failed to stop screen share: \(error.localizedDescription)")
        }
    }
}
3) Observe track state changes on LocalParticipant
Copy code
import Combine

var cancellables = Set<AnyCancellable>()

func observeLocalParticipantTracks(room: Room) {
    let participant = room.localParticipant

    // Observe publishedTracks or track collection changes (API names may vary)
    participant.$publishedTracks
        .sink { publishedTracks in
            for published in publishedTracks {
                print("Published track: \(published.trackName) state: \(published.state)")
            }
        }
        .store(in: &cancellables)

    // If there is a per-track publisher:
    participant.onTrackPublished = { publication in
        print("Track published: \(publication.trackName)")
        publication.onTrackStateChanged = { state in
            print("Track \(publication.trackName) state changed: \(state)")
        }
    }
}
Notes and tips • The system picker on visionOS 26+ will present options for entire screen vs specific app/window; LiveKit relies on that native UI. • Keep a reference to the returned
screenTrack
so you can mute/unpublish or stop it later. • Show clear user-facing messaging if permission is denied or capture fails (errors from the completion handler). • If you want, I can adapt these snippets to match the exact function/property names in your SDK build (some bindings differ slightly); share a small excerpt of your
LocalParticipant
API if you’d like exact code for your copy., with interactive elements