livekit / client-sdk-swift

LiveKit Swift Client SDK. Easily build live audio or video experiences into your mobile app, game or website.
https://livekit.io
Apache License 2.0
173 stars 84 forks source link

AudioSession switches to the Speaker after connection to the room #391

Open artemkrachulov opened 1 month ago

artemkrachulov commented 1 month ago

We're building an application where iOS Voip is combined with LiveKit. We have all configured modes, categories, and options for the AudioSession depending on the type of the call: video or audio. The issue comes when the user connects to the room:

When a new call is reported and CXProvider activates an audio session, AudioSession audio routes are configured correctly: Audio - Receiver Video - Speaker After connection to the room audio switches to the Speaker, but should stay Receiver as initially.

Do we have a default audio and mic configuration, where we can join the room with the required options? Example: Build-in Audio / Microphone On / Video off for video calls and Speaker Audio / Microphone On / Video on for video calls?

SDK Version 2.0.8

iOS/macOS Version Version 14.5 (23F79)

artemkrachulov commented 1 month ago

As a temporary solution, I have followed configuration after connection to the room:

Task {
    let _ = try await roomContext.connect(url, token.token)

    try await roomContext.setMicrophone(enabled: true)

    if self.isVideo {
        try await roomContext.setCamera(enabled: true)
    } else {
        // Switch audio back to Receiver
        AudioManager.shared.isSpeakerOutputPreferred = false
    }
}

But still, maybe we can avoid this unnecessary jumping from Receiver-Speaker-Receiver.