Browse Source

ios,callkit: delay updating the muted state until conference starts

In iOS 13 if the call is not unmuted when we report it to the system as started,
an action to unmute it is dispatched automagically. Thanks, Apple.

So, delay synchronizing the muted state until the conference is started (after
the join action). This creates a small window for de-synchronization, but it's
very short and it seems unavoidable.

This change is only applied to operating systems built by the fruit company in
Cupertino.
master
Saúl Ibarra Corretgé 5 years ago
parent
commit
6c4901a826
1 changed files with 30 additions and 12 deletions
  1. 30
    12
      react/features/mobile/call-integration/middleware.js

+ 30
- 12
react/features/mobile/call-integration/middleware.js View File

@@ -1,6 +1,6 @@
1 1
 // @flow
2 2
 
3
-import { Alert } from 'react-native';
3
+import { Alert, Platform } from 'react-native';
4 4
 import uuid from 'uuid';
5 5
 
6 6
 import { createTrackMutedEvent, sendAnalytics } from '../../analytics';
@@ -170,13 +170,19 @@ function _conferenceFailed(store, next, action) {
170 170
  * @private
171 171
  * @returns {*} The value returned by {@code next(action)}.
172 172
  */
173
-function _conferenceJoined(store, next, action) {
173
+function _conferenceJoined({ getState }, next, action) {
174 174
     const result = next(action);
175 175
 
176 176
     const { callUUID } = action.conference;
177 177
 
178 178
     if (callUUID) {
179
-        CallIntegration.reportConnectedOutgoingCall(callUUID);
179
+        CallIntegration.reportConnectedOutgoingCall(callUUID).then(() => {
180
+            // iOS 13 doesn't like the mute state to be false before the call is started
181
+            // so we update it here in case the user selected startWithAudioMuted.
182
+            if (Platform.OS === 'ios') {
183
+                _updateCallIntegrationMuted(action.conference, getState());
184
+            }
185
+        });
180 186
     }
181 187
 
182 188
     return result;
@@ -238,10 +244,6 @@ function _conferenceWillJoin({ dispatch, getState }, next, action) {
238 244
     CallIntegration.startCall(conference.callUUID, handle, hasVideo)
239 245
         .then(() => {
240 246
             const displayName = getConferenceName(state);
241
-            const muted
242
-                = isLocalTrackMuted(
243
-                    state['features/base/tracks'],
244
-                    MEDIA_TYPE.AUDIO);
245 247
 
246 248
             CallIntegration.updateCall(
247 249
                 conference.callUUID,
@@ -249,7 +251,12 @@ function _conferenceWillJoin({ dispatch, getState }, next, action) {
249 251
                     displayName,
250 252
                     hasVideo
251 253
                 });
252
-            CallIntegration.setMuted(conference.callUUID, muted);
254
+
255
+            // iOS 13 doesn't like the mute state to be false before the call is started
256
+            // so delay it until the conference was joined.
257
+            if (Platform.OS !== 'ios') {
258
+                _updateCallIntegrationMuted(conference, state);
259
+            }
253 260
         })
254 261
         .catch(error => {
255 262
             // Currently this error code is emitted only by Android.
@@ -393,10 +400,7 @@ function _syncTrackState({ getState }, next, action) {
393 400
     if (jitsiTrack.isLocal() && conference && conference.callUUID) {
394 401
         switch (jitsiTrack.getType()) {
395 402
         case 'audio': {
396
-            const tracks = state['features/base/tracks'];
397
-            const muted = isLocalTrackMuted(tracks, MEDIA_TYPE.AUDIO);
398
-
399
-            CallIntegration.setMuted(conference.callUUID, muted);
403
+            _updateCallIntegrationMuted(conference, state);
400 404
             break;
401 405
         }
402 406
         case 'video': {
@@ -411,3 +415,17 @@ function _syncTrackState({ getState }, next, action) {
411 415
 
412 416
     return result;
413 417
 }
418
+
419
+/**
420
+ * Update the muted state in the native side.
421
+ *
422
+ * @param {Object} conference - The current active conference.
423
+ * @param {Object} state - The redux store state.
424
+ * @private
425
+ * @returns {void}
426
+ */
427
+function _updateCallIntegrationMuted(conference, state) {
428
+    const muted = isLocalTrackMuted(state['features/base/tracks'], MEDIA_TYPE.AUDIO);
429
+
430
+    CallIntegration.setMuted(conference.callUUID, muted);
431
+}

Loading…
Cancel
Save