Skip to content

Request microphone permission in foreground before enabling recording.#1047

Open
silviudeac wants to merge 1 commit into
livekit:mainfrom
silviudeac:fix-foreground-mic-permission
Open

Request microphone permission in foreground before enabling recording.#1047
silviudeac wants to merge 1 commit into
livekit:mainfrom
silviudeac:fix-foreground-mic-permission

Conversation

@silviudeac

Copy link
Copy Markdown

This is the SDK-side follow-up to webrtc-sdk/webrtc#204. That change makes the WebRTC Audio Device Module (ADM) stop implicitly requesting microphone permission — the blocking request that hangs a worker thread when the app is woken in the background (#815) — and replaces it with a passive authorized-check. With the ADM no longer prompting, the SDK now does it: LocalParticipant proactively requests access at its async mic-enable path, but only while the app is foregrounded so the system dialog can actually appear.

The two are meant to land together — #204 removes the hang, this PR restores the prompt.

What changed

  • LiveKit+DeviceHelpers.swift — new LiveKitSDK.ensureDeviceAccessIfForegrounded(for:): requests access only when the app is .active, reusing the existing non-blocking ensureDeviceAccess(for:). A no-op on non-active / non-UIKit contexts.
  • LocalParticipant.set(source:enabled:) — in the .microphone create branch, before LocalAudioTrack.createTrack(...):
if AVCaptureDevice.authorizationStatus(for: .audio) == .notDetermined {
    _ = await LiveKitSDK.ensureDeviceAccessIfForegrounded(for: [.audio])
}

Only .notDetermined triggers a request; backgrounded/extension contexts never prompt; muting/unmuting an existing track is untouched. No change to existing API signatures.

Refs #815 (full fix together with webrtc-sdk/webrtc#204).

When mic permission is `.notDetermined`, request access at the async mic-enable path (`LocalParticipant.set(source:enabled:)`), but only while the app is foregrounded so the system dialog can appear.
This restores the prompt the WebRTC ADM no longer performs implicitly, without blocking a worker thread (livekit#815).
The foreground gate lives in a reusable `LiveKitSDK.ensureDeviceAccessIfForegrounded(for:)` helper alongside `ensureDeviceAccess`.
@CLAassistant

CLAassistant commented Jun 22, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants