Selaa lähdekoodia

Revert "ios: remove no longer needed code"

This reverts commit 603d161788.
master
Saúl Ibarra Corretgé 6 vuotta sitten
vanhempi
commit
9445cf99fd

+ 22
- 3
ios/sdk/src/callkit/JMCallKitEmitter.swift Näytä tiedosto

21
 internal final class JMCallKitEmitter: NSObject, CXProviderDelegate {
21
 internal final class JMCallKitEmitter: NSObject, CXProviderDelegate {
22
 
22
 
23
     private let listeners = NSMutableArray()
23
     private let listeners = NSMutableArray()
24
+    private var pendingMuteActions = Set<UUID>()
24
 
25
 
25
     internal override init() {}
26
     internal override init() {}
26
 
27
 
36
         listeners.remove(listener)
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
     // MARK: - CXProviderDelegate
46
     // MARK: - CXProviderDelegate
40
 
47
 
41
     func providerDidReset(_ provider: CXProvider) {
48
     func providerDidReset(_ provider: CXProvider) {
43
             let listener = $0 as! JMCallKitListener
50
             let listener = $0 as! JMCallKitListener
44
             listener.providerDidReset?()
51
             listener.providerDidReset?()
45
         }
52
         }
53
+        pendingMuteActions.removeAll()
46
     }
54
     }
47
 
55
 
48
     func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
56
     func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
64
     }
72
     }
65
 
73
 
66
     func provider(_ provider: CXProvider, perform action: CXSetMutedCallAction) {
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
         action.fulfill()
91
         action.fulfill()

+ 9
- 0
ios/sdk/src/callkit/JMCallKitProxy.swift Näytä tiedosto

160
             completion: @escaping (Error?) -> Swift.Void) {
160
             completion: @escaping (Error?) -> Swift.Void) {
161
         guard enabled else { return }
161
         guard enabled else { return }
162
 
162
 
163
+        // XXX keep track of muted actions to avoid "ping-pong"ing. See
164
+        // JMCallKitEmitter for details on the CXSetMutedCallAction handling.
165
+        for action in transaction.actions {
166
+            if (action as? CXSetMutedCallAction) != nil {
167
+                emitter.addMuteAction(action.uuid)
168
+            }
169
+        }
170
+
163
         callController.request(transaction, completion: completion)
171
         callController.request(transaction, completion: completion)
164
     }
172
     }
165
 
173
 
187
         return update
195
         return update
188
     }
196
     }
189
 }
197
 }
198
+

Loading…
Peruuta
Tallenna