Hello! We are migrating from Vapi to Livekit and a...
# sdk-native
b
Hello! We are migrating from Vapi to Livekit and all has worked great, but I'm having an issue in our react native (Expo) app on iOS device. We are using expo-video to show a looping video while the RTC call is happening. But somehow that is clashing, 80% of the time the microphone doesn't seem to get activated, the agent can't hear anything. If I remove the video it all works fine. I've tried all different audio modes (mixWithOthers) etc, but can't figure out what's happening. I've googled around but not found anything on this topic, is there anyone here who has any ideas to fix or troubleshoot? 🙏 (Starting the video playback before the call seems to work, although flaky)
r
Sorry I don't really know much about Expo. I asked AI and got this. Hopefully it can help YMMV: You're experiencing an audio session conflict between expo-video and LiveKit's React Native SDK on iOS when running concurrent video playback and RTC calls. The Core Issue The problem stems from iOS's
AVAudioSession
management, where both expo-video and LiveKit are competing for audio session control. LiveKitReactNativeModule.swift:29-35 LiveKit automatically configures the audio session for
playAndRecord
category with specific options, but expo-video may be interfering with this configuration. LiveKit's Audio Session Management LiveKit's iOS implementation automatically manages the audio session through several mechanisms: 1. Default Configuration: LiveKitReactNativeModule.swift:29-35 The SDK sets up
playAndRecord
category with options for Bluetooth, AirPlay, and speaker routing. 2. Dynamic Category Enforcement: index.tsx:46-61 When
getUserMedia
is called for audio, LiveKit automatically switches to
playAndRecord
category. 3. Custom Audio Configuration: LiveKitReactNativeModule.swift:120-179 You can override audio settings using
setAppleAudioConfiguration
, including the
mixWithOthers
option you mentioned. Recommended Solutions 1. Use
mixWithOthers
Audio Category Option Configure LiveKit to allow audio mixing with other apps: LiveKitReactNativeModule.swift:138-139
Copy code
import { AudioSession } from '@livekit/react-native';  
  
await AudioSession.setAppleAudioConfiguration({  
  audioCategoryOptions: ['mixWithOthers', 'allowBluetooth', 'allowBluetoothA2DP', 'defaultToSpeaker']  
});
2. Coordinate Audio Session Timing Since you mentioned starting video playback before the call works (though flaky), try this sequence: 1. Start expo-video playback first 2. Configure LiveKit's audio session with
mixWithOthers
3. Then start the LiveKit audio session 3. Use iOS Audio Management Hook For more sophisticated audio session management, consider using the
useIOSAudioManagement
hook: RoomPage.tsx:30 This hook automatically adjusts audio configuration based on track states and can help coordinate with other audio sources. Additional Troubleshooting 1. Check Audio Session State: Monitor when audio session changes occur by adding logging around your expo-video and LiveKit initialization. 2. Test Category Options: Try different combinations of
audioCategoryOptions
in
setAppleAudioConfiguration
to find the optimal configuration for your use case. 3. Consider Audio Interruption Handling: iOS may be treating the competing audio sessions as interruptions, causing the microphone to deactivate. Notes The issue is specific to iOS due to its strict
AVAudioSession
management. README.md:156-161 LiveKit automatically manages the audio session and switches between
playback
and
playAndRecord
categories based on local stream publishing. The
mixWithOthers
category option should allow both expo-video and LiveKit to coexist, but timing and configuration order matter significantly on iOS.
b
Hey! Thanks for your reply, me and Claude got to the same conclusion, but I still haven't found anything that works. But I will continue testing, thanks!