|
@@ -21,6 +21,7 @@ import Foundation
|
21
|
21
|
internal final class JMCallKitEmitter: NSObject, CXProviderDelegate {
|
22
|
22
|
|
23
|
23
|
private let listeners = NSMutableArray()
|
|
24
|
+ private var pendingMuteActions = Set<UUID>()
|
24
|
25
|
|
25
|
26
|
internal override init() {}
|
26
|
27
|
|
|
@@ -36,6 +37,12 @@ internal final class JMCallKitEmitter: NSObject, CXProviderDelegate {
|
36
|
37
|
listeners.remove(listener)
|
37
|
38
|
}
|
38
|
39
|
|
|
40
|
+ // MARK: - Add mute action
|
|
41
|
+
|
|
42
|
+ func addMuteAction(_ actionUUID: UUID) {
|
|
43
|
+ pendingMuteActions.insert(actionUUID)
|
|
44
|
+ }
|
|
45
|
+
|
39
|
46
|
// MARK: - CXProviderDelegate
|
40
|
47
|
|
41
|
48
|
func providerDidReset(_ provider: CXProvider) {
|
|
@@ -43,6 +50,7 @@ internal final class JMCallKitEmitter: NSObject, CXProviderDelegate {
|
43
|
50
|
let listener = $0 as! JMCallKitListener
|
44
|
51
|
listener.providerDidReset?()
|
45
|
52
|
}
|
|
53
|
+ pendingMuteActions.removeAll()
|
46
|
54
|
}
|
47
|
55
|
|
48
|
56
|
func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
|
|
@@ -64,9 +72,20 @@ internal final class JMCallKitEmitter: NSObject, CXProviderDelegate {
|
64
|
72
|
}
|
65
|
73
|
|
66
|
74
|
func provider(_ provider: CXProvider, perform action: CXSetMutedCallAction) {
|
67
|
|
- listeners.forEach {
|
68
|
|
- let listener = $0 as! JMCallKitListener
|
69
|
|
- listener.performSetMutedCall?(UUID: action.callUUID, isMuted: action.isMuted)
|
|
75
|
+ let uuid = pendingMuteActions.remove(action.uuid)
|
|
76
|
+
|
|
77
|
+ // Avoid mute actions ping-pong: if the mute action was caused by
|
|
78
|
+ // the JS side (we requested a transaction) don't call the delegate
|
|
79
|
+ // method. If it was called by the provder itself (when the user presses
|
|
80
|
+ // the mute button in the CallKit view) then call the delegate method.
|
|
81
|
+ //
|
|
82
|
+ // NOTE: don't try to be clever and remove this. Been there, done that.
|
|
83
|
+ // Won't work.
|
|
84
|
+ if (uuid == nil) {
|
|
85
|
+ listeners.forEach {
|
|
86
|
+ let listener = $0 as! JMCallKitListener
|
|
87
|
+ listener.performSetMutedCall?(UUID: action.callUUID, isMuted: action.isMuted)
|
|
88
|
+ }
|
70
|
89
|
}
|
71
|
90
|
|
72
|
91
|
action.fulfill()
|