-
Notifications
You must be signed in to change notification settings - Fork 6
/
IncomingCallViewController.swift
67 lines (58 loc) · 2.32 KB
/
IncomingCallViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* Copyright (c) 2011-2020, Zingaya, Inc. All rights reserved.
*/
import UIKit
final class IncomingCallViewController: UIViewController, ErrorHandling {
override var supportedInterfaceOrientations: UIInterfaceOrientationMask { .portrait }
@IBOutlet private var incomingCallView: DefaultIncomingCallView!
var callManager: CallManager! // DI
var storyAssembler: StoryAssembler! // DI
override func viewDidLoad() {
super.viewDidLoad()
if let wrapper = callManager.managedCallWrapper {
incomingCallView.displayName = wrapper.displayName ?? wrapper.callee
}
incomingCallView.declineHandler = { [weak self] in
Log.d("Call declined from incomingCall view")
do {
try self?.callManager.rejectCall()
} catch (let error) {
self?.dismiss(animated: true)
Log.e(error.localizedDescription)
}
}
incomingCallView.acceptHandler = { [weak self] in
Log.d("Call accepted from incomingCall view")
PermissionsHelper.requestRecordPermissions(includingVideo: true) { error in
if let error = error {
self?.handleError(error)
return
}
if let self = self {
self.navigationController?.setViewControllers(
[self.storyAssembler.call],
animated: true
)
}
}
}
callManager.callObserver = { [weak self] call in
guard let self = self else { return }
if case .ended (let reason) = call.state {
if case .disconnected = reason {
self.dismiss(animated: true)
}
if case .failed (let message) = reason {
self.navigationController?.setViewControllers(
[self.storyAssembler.callFailed(
callee: call.callee,
displayName: call.displayName ?? call.callee,
reason: message)
],
animated: true
)
}
}
}
}
}