steep-balloon-41261
07/31/2023, 2:52 PMmagnificent-art-43333
07/31/2023, 2:54 PMbored-monitor-77074
07/31/2023, 3:37 PMdo {
try audioSession.setCategory(.playback, mode: .default, options: [
.allowBluetoothA2DP,
.mixWithOthers,
])
} catch {
}
AudioManager.shared.customConfigureAudioSessionFunc = { newState, oldState in
// Gets called when a new track gets published
// Happens when a Local or Remote Participant first joines the call and unmutes
DispatchQueue.main.async {
let configuration = RTCAudioSessionConfiguration.webRTC()
if [.localOnly, .localAndRemote].contains(newState.trackState) && ![.localOnly, .localAndRemote].contains(oldState.trackState) {
configuration.categoryOptions = [
.allowBluetooth,
.mixWithOthers,
]
configuration.category = AVAudioSession.Category.playAndRecord.rawValue
configuration.mode = AVAudioSession.Mode.videoChat.rawValue
} else {
// If this is on, music is always ducked when some other participant is unmuted
configuration.categoryOptions = [
.allowBluetoothA2DP,
.mixWithOthers,
]
configuration.category = AVAudioSession.Category.playback.rawValue
configuration.mode = AVAudioSession.Mode.default.rawValue
}
}
}
private func setMute(_ value: Bool) {
guard let localParticipant = room.localParticipant else {
log.error("LocalParticipant doesn't exist")
return
}
guard !microphoneTrackState.isBusy else {
log.warning("microphoneTrack is .busy")
return
}
DispatchQueue.main.async {
self.microphoneTrackState = .busy(isPublishing: !self.microphoneTrackState.isPublished)
}
localParticipant.setMicrophone(enabled: value).then { publication in
guard let publication = publication else { return }
DispatchQueue.main.async {
self.microphoneTrackState = .published(publication)
if publication.muted {
_ = localParticipant.unpublish(publication: publication)
}
self.log.verbose("Microphone is now \(publication.muted ? "Muted" : "NOT Muted")")
}
}.catch { error in
DispatchQueue.main.async {
self.microphoneTrackState = .notPublished(error: error)
}
self.log.verbose("Failed to publish microphone, error: \(error)")
}
}bored-monitor-77074
08/01/2023, 1:00 PMbored-monitor-77074
08/03/2023, 11:02 AM