|
@@ -18,6 +18,29 @@
|
18
|
18
|
import CallKit
|
19
|
19
|
import Foundation
|
20
|
20
|
|
|
21
|
+public protocol CXProviderProtocol: class {
|
|
22
|
+ var configuration: CXProviderConfiguration { get set }
|
|
23
|
+ func setDelegate(_ delegate: CXProviderDelegate?, queue: DispatchQueue?)
|
|
24
|
+ func reportNewIncomingCall(with UUID: UUID, update: CXCallUpdate, completion: @escaping (Error?) -> Void)
|
|
25
|
+ func reportCall(with UUID: UUID, updated update: CXCallUpdate)
|
|
26
|
+ func reportCall(with UUID: UUID, endedAt dateEnded: Date?, reason endedReason: CXCallEndedReason)
|
|
27
|
+ func reportOutgoingCall(with UUID: UUID, startedConnectingAt dateStartedConnecting: Date?)
|
|
28
|
+ func reportOutgoingCall(with UUID: UUID, connectedAt dateConnected: Date?)
|
|
29
|
+ func invalidate()
|
|
30
|
+}
|
|
31
|
+
|
|
32
|
+public protocol CXCallControllerProtocol: class {
|
|
33
|
+ var calls: [CXCall] { get }
|
|
34
|
+ func request(_ transaction: CXTransaction, completion: @escaping (Error?) -> Swift.Void)
|
|
35
|
+}
|
|
36
|
+
|
|
37
|
+extension CXProvider: CXProviderProtocol {}
|
|
38
|
+extension CXCallController: CXCallControllerProtocol {
|
|
39
|
+ public var calls: [CXCall] {
|
|
40
|
+ return callObserver.calls
|
|
41
|
+ }
|
|
42
|
+}
|
|
43
|
+
|
21
|
44
|
/// JitsiMeet CallKit proxy
|
22
|
45
|
// NOTE: The methods this class exposes are meant to be called in the UI thread.
|
23
|
46
|
// All delegate methods called by JMCallKitEmitter will be called in the UI thread.
|
|
@@ -26,11 +49,17 @@ import Foundation
|
26
|
49
|
private override init() {}
|
27
|
50
|
|
28
|
51
|
// MARK: - CallKit proxy
|
|
52
|
+
|
|
53
|
+ public static var callKitProvider: CXProviderProtocol?
|
|
54
|
+ public static var callKitCallController: CXCallControllerProtocol?
|
29
|
55
|
|
30
|
|
- private static var provider: CXProvider = {
|
31
|
|
- let configuration = CXProviderConfiguration(localizedName: "")
|
32
|
|
- return CXProvider(configuration: configuration)
|
33
|
|
- }()
|
|
56
|
+ private static var provider: CXProviderProtocol {
|
|
57
|
+ callKitProvider ?? defaultProvider
|
|
58
|
+ }
|
|
59
|
+
|
|
60
|
+ private static var callController: CXCallControllerProtocol {
|
|
61
|
+ callKitCallController ?? defaultCallController
|
|
62
|
+ }
|
34
|
63
|
|
35
|
64
|
private static var providerConfiguration: CXProviderConfiguration? {
|
36
|
65
|
didSet {
|
|
@@ -39,10 +68,15 @@ import Foundation
|
39
|
68
|
provider.setDelegate(emitter, queue: nil)
|
40
|
69
|
}
|
41
|
70
|
}
|
42
|
|
-
|
43
|
|
- private static let callController: CXCallController = {
|
|
71
|
+
|
|
72
|
+ private static let defaultCallController: CXCallController = {
|
44
|
73
|
return CXCallController()
|
45
|
74
|
}()
|
|
75
|
+
|
|
76
|
+ private static var defaultProvider: CXProvider = {
|
|
77
|
+ let configuration = CXProviderConfiguration(localizedName: "")
|
|
78
|
+ return CXProvider(configuration: configuration)
|
|
79
|
+ }()
|
46
|
80
|
|
47
|
81
|
private static let emitter: JMCallKitEmitter = {
|
48
|
82
|
return JMCallKitEmitter()
|
|
@@ -52,10 +86,16 @@ import Foundation
|
52
|
86
|
/// Defaults to enabled, set to false when you don't want to use CallKit.
|
53
|
87
|
@objc public static var enabled: Bool = true {
|
54
|
88
|
didSet {
|
55
|
|
- provider.invalidate()
|
|
89
|
+ if callKitProvider == nil {
|
|
90
|
+ provider.invalidate()
|
|
91
|
+ }
|
|
92
|
+
|
56
|
93
|
if enabled {
|
57
|
|
- guard isProviderConfigured() else { return; }
|
58
|
|
- provider = CXProvider(configuration: providerConfiguration!)
|
|
94
|
+ guard isProviderConfigured() else { return }
|
|
95
|
+ if callKitProvider == nil {
|
|
96
|
+ defaultProvider = CXProvider(configuration: providerConfiguration!)
|
|
97
|
+ }
|
|
98
|
+
|
59
|
99
|
provider.setDelegate(emitter, queue: nil)
|
60
|
100
|
} else {
|
61
|
101
|
provider.setDelegate(nil, queue: nil)
|
|
@@ -92,19 +132,18 @@ import Foundation
|
92
|
132
|
}
|
93
|
133
|
|
94
|
134
|
@objc public static func hasActiveCallForUUID(_ callUUID: String) -> Bool {
|
95
|
|
- let activeCallForUUID = callController.callObserver.calls.first {
|
|
135
|
+ let activeCallForUUID = callController.calls.first {
|
96
|
136
|
$0.uuid == UUID(uuidString: callUUID)
|
97
|
137
|
}
|
98
|
138
|
guard activeCallForUUID != nil else { return false }
|
99
|
139
|
return true
|
100
|
140
|
}
|
101
|
141
|
|
102
|
|
- @objc public static func reportNewIncomingCall(
|
103
|
|
- UUID: UUID,
|
104
|
|
- handle: String?,
|
105
|
|
- displayName: String?,
|
106
|
|
- hasVideo: Bool,
|
107
|
|
- completion: @escaping (Error?) -> Void) {
|
|
142
|
+ @objc public static func reportNewIncomingCall(UUID: UUID,
|
|
143
|
+ handle: String?,
|
|
144
|
+ displayName: String?,
|
|
145
|
+ hasVideo: Bool,
|
|
146
|
+ completion: @escaping (Error?) -> Void) {
|
108
|
147
|
guard enabled else { return }
|
109
|
148
|
|
110
|
149
|
let callUpdate = makeCXUpdate(handle: handle,
|
|
@@ -132,7 +171,6 @@ import Foundation
|
132
|
171
|
endedAt dateEnded: Date?,
|
133
|
172
|
reason endedReason: CXCallEndedReason) {
|
134
|
173
|
guard enabled else { return }
|
135
|
|
-
|
136
|
174
|
provider.reportCall(with: UUID,
|
137
|
175
|
endedAt: dateEnded,
|
138
|
176
|
reason: endedReason)
|
|
@@ -142,7 +180,6 @@ import Foundation
|
142
|
180
|
with UUID: UUID,
|
143
|
181
|
startedConnectingAt dateStartedConnecting: Date?) {
|
144
|
182
|
guard enabled else { return }
|
145
|
|
-
|
146
|
183
|
provider.reportOutgoingCall(with: UUID,
|
147
|
184
|
startedConnectingAt: dateStartedConnecting)
|
148
|
185
|
}
|