diff --git a/NextcloudTalk/Calls/NCCallController.swift b/NextcloudTalk/Calls/NCCallController.swift index 06b4e33e2..3060d1a4e 100644 --- a/NextcloudTalk/Calls/NCCallController.swift +++ b/NextcloudTalk/Calls/NCCallController.swift @@ -204,20 +204,28 @@ internal class NCCallController: NSObject, NCPeerConnectionDelegate, NCSignaling // Make sure the signaling controller has retrieved the settings before joining a call self.signalingController.updateSignalingSettings { _ in - let authStatus = AVCaptureDevice.authorizationStatus(for: .video) - - if !self.isAudioOnly, authStatus == .notDetermined { - AVCaptureDevice.requestAccess(for: .video) { _ in + // The permissions must be answered before creating the local media, otherwise the tracks + // are skipped because the authorization status is still undetermined + self.requestAccessIfNeeded(for: .audio, onlyWhen: self.room.canPublishAudio) { + self.requestAccessIfNeeded(for: .video, onlyWhen: !self.isAudioOnly && self.room.canPublishVideo) { self.createLocalMedia() self.joinCall() } - } else { - self.createLocalMedia() - self.joinCall() } } } + private func requestAccessIfNeeded(for mediaType: AVMediaType, onlyWhen shouldRequest: Bool, completionBlock: @escaping () -> Void) { + guard shouldRequest, AVCaptureDevice.authorizationStatus(for: mediaType) == .notDetermined else { + completionBlock() + return + } + + AVCaptureDevice.requestAccess(for: mediaType) { _ in + completionBlock() + } + } + public func joinCall() { NCLog.log("Join call in NCCallController for token \(self.room.token)")