|
|
@@ -1,6 +1,5 @@
|
|
1
|
1
|
/*
|
|
2
|
|
- * Copyright @ 2019-present 8x8, Inc.
|
|
3
|
|
- * Copyright @ 2018-2019 Atlassian Pty Ltd
|
|
|
2
|
+ * Copyright @ 2018-present 8x8, Inc.
|
|
4
|
3
|
*
|
|
5
|
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
5
|
* you may not use this file except in compliance with the License.
|
|
|
@@ -18,7 +17,7 @@
|
|
18
|
17
|
import CallKit
|
|
19
|
18
|
import Foundation
|
|
20
|
19
|
|
|
21
|
|
-public protocol CXProviderProtocol: class {
|
|
|
20
|
+public protocol CXProviderProtocol: AnyObject {
|
|
22
|
21
|
var configuration: CXProviderConfiguration { get set }
|
|
23
|
22
|
func setDelegate(_ delegate: CXProviderDelegate?, queue: DispatchQueue?)
|
|
24
|
23
|
func reportNewIncomingCall(with UUID: UUID, update: CXCallUpdate, completion: @escaping (Error?) -> Void)
|
|
|
@@ -29,7 +28,7 @@ public protocol CXProviderProtocol: class {
|
|
29
|
28
|
func invalidate()
|
|
30
|
29
|
}
|
|
31
|
30
|
|
|
32
|
|
-public protocol CXCallControllerProtocol: class {
|
|
|
31
|
+public protocol CXCallControllerProtocol: AnyObject {
|
|
33
|
32
|
var calls: [CXCall] { get }
|
|
34
|
33
|
func request(_ transaction: CXTransaction, completion: @escaping (Error?) -> Swift.Void)
|
|
35
|
34
|
}
|
|
|
@@ -53,7 +52,9 @@ extension CXCallController: CXCallControllerProtocol {
|
|
53
|
52
|
public static var callKitProvider: CXProviderProtocol?
|
|
54
|
53
|
public static var callKitCallController: CXCallControllerProtocol?
|
|
55
|
54
|
|
|
56
|
|
- private static var provider: CXProviderProtocol {
|
|
|
55
|
+ private static var defaultProvider: CXProvider?
|
|
|
56
|
+
|
|
|
57
|
+ private static var provider: CXProviderProtocol? {
|
|
57
|
58
|
callKitProvider ?? defaultProvider
|
|
58
|
59
|
}
|
|
59
|
60
|
|
|
|
@@ -64,8 +65,8 @@ extension CXCallController: CXCallControllerProtocol {
|
|
64
|
65
|
private static var providerConfiguration: CXProviderConfiguration? {
|
|
65
|
66
|
didSet {
|
|
66
|
67
|
guard let configuration = providerConfiguration else { return }
|
|
67
|
|
- provider.configuration = configuration
|
|
68
|
|
- provider.setDelegate(emitter, queue: nil)
|
|
|
68
|
+ provider?.configuration = configuration
|
|
|
69
|
+ provider?.setDelegate(emitter, queue: nil)
|
|
69
|
70
|
}
|
|
70
|
71
|
}
|
|
71
|
72
|
|
|
|
@@ -73,32 +74,27 @@ extension CXCallController: CXCallControllerProtocol {
|
|
73
|
74
|
return CXCallController()
|
|
74
|
75
|
}()
|
|
75
|
76
|
|
|
76
|
|
- private static var defaultProvider: CXProvider = {
|
|
77
|
|
- let configuration = CXProviderConfiguration(localizedName: "")
|
|
78
|
|
- return CXProvider(configuration: configuration)
|
|
79
|
|
- }()
|
|
80
|
|
-
|
|
81
|
77
|
private static let emitter: JMCallKitEmitter = {
|
|
82
|
78
|
return JMCallKitEmitter()
|
|
83
|
79
|
}()
|
|
84
|
80
|
|
|
85
|
81
|
/// Enables the proxy in between CallKit and the consumers of the SDK.
|
|
86
|
|
- /// Defaults to enabled, set to false when you don't want to use CallKit.
|
|
87
|
|
- @objc public static var enabled: Bool = true {
|
|
|
82
|
+ /// Defaults to disabled. Set to true when you want to use CallKit.
|
|
|
83
|
+ @objc public static var enabled: Bool = false {
|
|
88
|
84
|
didSet {
|
|
89
|
85
|
if callKitProvider == nil {
|
|
90
|
|
- provider.invalidate()
|
|
|
86
|
+ provider?.invalidate()
|
|
91
|
87
|
}
|
|
92
|
88
|
|
|
93
|
89
|
if enabled {
|
|
94
|
|
- guard isProviderConfigured() else { return }
|
|
|
90
|
+ let configuration = providerConfiguration ?? CXProviderConfiguration(localizedName: "")
|
|
95
|
91
|
if callKitProvider == nil {
|
|
96
|
|
- defaultProvider = CXProvider(configuration: providerConfiguration!)
|
|
|
92
|
+ defaultProvider = CXProvider(configuration: configuration)
|
|
97
|
93
|
}
|
|
98
|
94
|
|
|
99
|
|
- provider.setDelegate(emitter, queue: nil)
|
|
|
95
|
+ provider?.setDelegate(emitter, queue: nil)
|
|
100
|
96
|
} else {
|
|
101
|
|
- provider.setDelegate(nil, queue: nil)
|
|
|
97
|
+ provider?.setDelegate(nil, queue: nil)
|
|
102
|
98
|
}
|
|
103
|
99
|
}
|
|
104
|
100
|
}
|
|
|
@@ -149,9 +145,9 @@ extension CXCallController: CXCallControllerProtocol {
|
|
149
|
145
|
let callUpdate = makeCXUpdate(handle: handle,
|
|
150
|
146
|
displayName: displayName,
|
|
151
|
147
|
hasVideo: hasVideo)
|
|
152
|
|
- provider.reportNewIncomingCall(with: UUID,
|
|
153
|
|
- update: callUpdate,
|
|
154
|
|
- completion: completion)
|
|
|
148
|
+ provider?.reportNewIncomingCall(with: UUID,
|
|
|
149
|
+ update: callUpdate,
|
|
|
150
|
+ completion: completion)
|
|
155
|
151
|
}
|
|
156
|
152
|
|
|
157
|
153
|
@objc public static func reportCallUpdate(with UUID: UUID,
|
|
|
@@ -163,7 +159,7 @@ extension CXCallController: CXCallControllerProtocol {
|
|
163
|
159
|
let callUpdate = makeCXUpdate(handle: handle,
|
|
164
|
160
|
displayName: displayName,
|
|
165
|
161
|
hasVideo: hasVideo)
|
|
166
|
|
- provider.reportCall(with: UUID, updated: callUpdate)
|
|
|
162
|
+ provider?.reportCall(with: UUID, updated: callUpdate)
|
|
167
|
163
|
}
|
|
168
|
164
|
|
|
169
|
165
|
@objc public static func reportCall(
|
|
|
@@ -171,17 +167,17 @@ extension CXCallController: CXCallControllerProtocol {
|
|
171
|
167
|
endedAt dateEnded: Date?,
|
|
172
|
168
|
reason endedReason: CXCallEndedReason) {
|
|
173
|
169
|
guard enabled else { return }
|
|
174
|
|
- provider.reportCall(with: UUID,
|
|
175
|
|
- endedAt: dateEnded,
|
|
176
|
|
- reason: endedReason)
|
|
|
170
|
+ provider?.reportCall(with: UUID,
|
|
|
171
|
+ endedAt: dateEnded,
|
|
|
172
|
+ reason: endedReason)
|
|
177
|
173
|
}
|
|
178
|
174
|
|
|
179
|
175
|
@objc public static func reportOutgoingCall(
|
|
180
|
176
|
with UUID: UUID,
|
|
181
|
177
|
startedConnectingAt dateStartedConnecting: Date?) {
|
|
182
|
178
|
guard enabled else { return }
|
|
183
|
|
- provider.reportOutgoingCall(with: UUID,
|
|
184
|
|
- startedConnectingAt: dateStartedConnecting)
|
|
|
179
|
+ provider?.reportOutgoingCall(with: UUID,
|
|
|
180
|
+ startedConnectingAt: dateStartedConnecting)
|
|
185
|
181
|
}
|
|
186
|
182
|
|
|
187
|
183
|
@objc public static func reportOutgoingCall(
|
|
|
@@ -189,7 +185,7 @@ extension CXCallController: CXCallControllerProtocol {
|
|
189
|
185
|
connectedAt dateConnected: Date?) {
|
|
190
|
186
|
guard enabled else { return }
|
|
191
|
187
|
|
|
192
|
|
- provider.reportOutgoingCall(with: UUID, connectedAt: dateConnected)
|
|
|
188
|
+ provider?.reportOutgoingCall(with: UUID, connectedAt: dateConnected)
|
|
193
|
189
|
}
|
|
194
|
190
|
|
|
195
|
191
|
@objc public static func request(
|