Restore audio session after it is inactivated. Fixes #11

This commit is contained in:
Tiago Jacobs 2022-05-16 19:19:45 -03:00
parent 06c88b4059
commit b3988243c8
2 changed files with 33 additions and 6 deletions

View File

@ -1,12 +1,12 @@
PODS:
- bigbluebutton-mobile-sdk (0.1.16):
- bigbluebutton-mobile-sdk (0.1.18):
- bigbluebutton-mobile-sdk-common
- React-Core
- WebRTC-lib
- bigbluebutton-mobile-sdk-broadcast-upload-extension (0.1.16):
- bigbluebutton-mobile-sdk-broadcast-upload-extension (0.1.18):
- bigbluebutton-mobile-sdk-common
- WebRTC-lib
- bigbluebutton-mobile-sdk-common (0.1.16):
- bigbluebutton-mobile-sdk-common (0.1.18):
- WebRTC-lib
- boost-for-react-native (1.63.0)
- DoubleConversion (1.1.6)
@ -361,9 +361,9 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/yoga"
SPEC CHECKSUMS:
bigbluebutton-mobile-sdk: c22205a921c38e43d5c5ec2c8f47d890db5e189e
bigbluebutton-mobile-sdk-broadcast-upload-extension: 702331796aa06d3cac9fc202cb20888b3e3a57eb
bigbluebutton-mobile-sdk-common: 287c9acc965d00e72d71a0d2b020fa8e483e7a11
bigbluebutton-mobile-sdk: 9bf75ac3644dba36c7f696218a08d132bb10d847
bigbluebutton-mobile-sdk-broadcast-upload-extension: 36b8ba6058fab3e37b1f002c285a501647dd2c64
bigbluebutton-mobile-sdk-common: ff6095f82f81817271f7dede86b5d5356b6311e8
boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c
DoubleConversion: cde416483dac037923206447da6e1454df403714
FBLazyVector: 3bb422f41b18121b71783a905c10e58606f7dc3e

View File

@ -38,6 +38,8 @@ open class AudioWebRTCClient: NSObject {
private var videoCapturer: RTCVideoCapturer?
private var localVideoTrack: RTCVideoTrack?
private var isRatioDefined:Bool=false
private var isActiveObserver1:NSKeyValueObservation?
@available(*, unavailable)
override init() {
@ -105,6 +107,7 @@ open class AudioWebRTCClient: NSObject {
private func configureAudioSession() {
self.rtcAudioSession.lockForConfiguration()
do {
try self.rtcAudioSession.setCategory(AVAudioSession.Category.playAndRecord.rawValue)
try self.rtcAudioSession.setMode(AVAudioSession.Mode.voiceChat.rawValue)
@ -112,6 +115,13 @@ open class AudioWebRTCClient: NSObject {
debugPrint("Error changing AVAudioSession category: \(error)")
}
self.rtcAudioSession.unlockForConfiguration()
self.isActiveObserver1 = self.rtcAudioSession.observe(\.isActive, options: [.new]) { (defaults, change) in
if(!self.rtcAudioSession.isActive) {
self.logger.info("isActive changed to false, restoring it");
self.restoreAudioSession()
}
}
}
private func createMediaSenders() {
@ -232,6 +242,7 @@ extension AudioWebRTCClient {
self.rtcAudioSession.lockForConfiguration()
do {
try self.rtcAudioSession.setCategory(AVAudioSession.Category.playAndRecord.rawValue)
try self.rtcAudioSession.setMode(AVAudioSession.Mode.voiceChat.rawValue)
try self.rtcAudioSession.overrideOutputAudioPort(.none)
} catch let error {
debugPrint("Error setting AVAudioSession category: \(error)")
@ -259,6 +270,22 @@ extension AudioWebRTCClient {
}
}
public func restoreAudioSession() {
self.audioQueue.async { [weak self] in
guard let self = self else {
return
}
do {
self.rtcAudioSession.lockForConfiguration()
try RTCAudioSession.sharedInstance().setActive(true)
self.rtcAudioSession.unlockForConfiguration()
} catch let error {
debugPrint("Couldn't restore isActive: \(error)")
}
}
}
private func setAudioEnabled(_ isEnabled: Bool) {
setTrackEnabled(RTCAudioTrack.self, isEnabled: isEnabled)
}