Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions NextcloudTalk/Calls/NCCallController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)")

Expand Down
Loading