react-native-webrtc / react-native-incall-manager

Handling media-routes/sensors/events during a audio/video chat on React Native
ISC License
547 stars 191 forks source link

Playing video during a call in iOS #174

Closed Romick2005 closed 2 years ago

Romick2005 commented 2 years ago

We need need to play video during a webrtc call. To play a video we use react-native-video.

User story: When user press a button to play video, current webrtc video stream goes away and remote mp4 video file is played. After video finish webrtc connection should be restored. But the problem here that after restoring (show hide local and remotes streams) we loose microphone audio. That scenario works perfectly well on Android , but not for iOS. We discovered that when video is played react-native-video changes AVAudioSession sharedInstance category and mode: category: AVAudioSessionCategoryPlayback, audioMode = AVAudioSessionModeDefault, when internal values are: category: AVAudioSessionCategoryPlayAndRecord, audioMode = AVAudioSessionModeVideoChat, So after playing video we need to restore webrtc audio session.

What would be the best way to fix this? 1) On video end, invoke InCallManager.start that would have following checks: if _audioSessionInitialized then check if _audioSession.category != _incallAudioCategory then set audioSessionSetCategory: _incallAudioCategory and if audioSession.mode != _incallAudioMode then set audioSessionSetMode:_incallAudioMode 2) On video end, invoke InCallManager.setForceSpeakerphoneOn where on updateAudioRoute just set category if it is different than _incallAudioCategory 3) Create separate IncallManager method reInitAudioSession where explicitly set category and mode (_incallAudioCategory and _incallAudioMode), but that will also require some empty RCT_EXPORT_METHOD Android implementation.