Ver código fonte

Revert "ios: remove no longer needed code"

This reverts commit 603d161788.
j8
Saúl Ibarra Corretgé 6 anos atrás
pai
commit
9445cf99fd

+ 22
- 3
ios/sdk/src/callkit/JMCallKitEmitter.swift Ver arquivo

@@ -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()

+ 9
- 0
ios/sdk/src/callkit/JMCallKitProxy.swift Ver arquivo

@@ -160,6 +160,14 @@ import Foundation
160 160
             completion: @escaping (Error?) -> Swift.Void) {
161 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 171
         callController.request(transaction, completion: completion)
164 172
     }
165 173
 
@@ -187,3 +195,4 @@ import Foundation
187 195
         return update
188 196
     }
189 197
 }
198
+

Carregando…
Cancelar
Salvar