11import { t } from 'i18next' ;
2+ import { Audio , InterruptionModeIOS } from 'expo-av' ;
23import { Headphones , Mic , MicOff , PhoneOff , Settings } from 'lucide-react-native' ;
34import { useColorScheme } from 'nativewind' ;
45import React , { useCallback , useEffect , useRef , useState } from 'react' ;
@@ -146,6 +147,45 @@ export const LiveKitBottomSheet = () => {
146147 }
147148 } , [ isConnected , currentRoomInfo ] ) ;
148149
150+ // Audio Routing Logic
151+ useEffect ( ( ) => {
152+ const updateAudioRouting = async ( ) => {
153+ if ( ! selectedAudioDevices . speaker ) return ;
154+
155+ try {
156+ const speaker = selectedAudioDevices . speaker ;
157+ console . log ( 'Updating audio routing for:' , speaker . type ) ;
158+
159+ if ( speaker . type === 'speaker' ) {
160+ // Force Speakerphone
161+ await Audio . setAudioModeAsync ( {
162+ allowsRecordingIOS : true ,
163+ staysActiveInBackground : true ,
164+ playsInSilentModeIOS : true ,
165+ shouldDuckAndroid : true ,
166+ playThroughEarpieceAndroid : false , // This forces speaker on Android
167+ interruptionModeIOS : InterruptionModeIOS . DoNotMix ,
168+ } ) ;
169+ } else {
170+ // Default (Earpiece) or Bluetooth
171+ // For Bluetooth to work, we usually just need to NOT force speaker.
172+ await Audio . setAudioModeAsync ( {
173+ allowsRecordingIOS : true ,
174+ staysActiveInBackground : true ,
175+ playsInSilentModeIOS : true ,
176+ shouldDuckAndroid : true ,
177+ playThroughEarpieceAndroid : true , // This allows earpiece/bluetooth
178+ interruptionModeIOS : InterruptionModeIOS . DoNotMix ,
179+ } ) ;
180+ }
181+ } catch ( error ) {
182+ console . error ( 'Failed to update audio routing:' , error ) ;
183+ }
184+ } ;
185+
186+ updateAudioRouting ( ) ;
187+ } , [ selectedAudioDevices . speaker ] ) ;
188+
149189 const handleRoomSelect = useCallback (
150190 ( room : DepartmentVoiceChannelResultData ) => {
151191 connectToRoom ( room , room . Token ) ;
@@ -303,7 +343,7 @@ export const LiveKitBottomSheet = () => {
303343 < View className = "w-full p-4" >
304344 < HStack className = "mb-4 items-center justify-between" >
305345 < Text className = "text-xl font-bold" > { t ( 'livekit.title' ) } </ Text >
306- { currentView === BottomSheetView . CONNECTED && (
346+ { currentView !== BottomSheetView . AUDIO_SETTINGS && (
307347 < TouchableOpacity onPress = { handleShowAudioSettings } testID = "header-audio-settings-button" >
308348 < Headphones size = { 20 } color = "#6B7280" />
309349 </ TouchableOpacity >
@@ -323,7 +363,7 @@ const styles = StyleSheet.create({
323363 content : {
324364 flex : 1 ,
325365 width : '100%' ,
326- paddingHorizontal : 16 ,
366+ paddingHorizontal : 8 ,
327367 } ,
328368 roomList : {
329369 flex : 1 ,
@@ -334,6 +374,7 @@ const styles = StyleSheet.create({
334374 controls : {
335375 flexDirection : 'row' ,
336376 justifyContent : 'space-around' ,
377+ width : '100%' ,
337378 marginTop : 16 ,
338379 } ,
339380 controlButton : {
0 commit comments