Browse Source

fix(prejoin): Replace the stored audio/video tracks when device list changes

When on prejoin screen, if the device list changes (devices are added or removed),
the newly created tracks do not properly replace the old ones, resulting in
errors after joining the meeting and trying to change the devices.
This change fixes the problem.
master
Vlad Piersec 5 years ago
parent
commit
2b5787163e
2 changed files with 53 additions and 12 deletions
  1. 41
    12
      conference.js
  2. 12
    0
      react/features/base/tracks/functions.js

+ 41
- 12
conference.js View File

95
     createLocalPresenterTrack,
95
     createLocalPresenterTrack,
96
     createLocalTracksF,
96
     createLocalTracksF,
97
     destroyLocalTracks,
97
     destroyLocalTracks,
98
+    getLocalJitsiAudioTrack,
99
+    getLocalJitsiVideoTrack,
98
     isLocalVideoTrackMuted,
100
     isLocalVideoTrackMuted,
99
     isLocalTrackMuted,
101
     isLocalTrackMuted,
100
     isUserInteractionRequiredForUnmute,
102
     isUserInteractionRequiredForUnmute,
118
 import { suspendDetected } from './react/features/power-monitor';
120
 import { suspendDetected } from './react/features/power-monitor';
119
 import {
121
 import {
120
     initPrejoin,
122
     initPrejoin,
121
-    isPrejoinPageEnabled
123
+    isPrejoinPageEnabled,
124
+    isPrejoinPageVisible
122
 } from './react/features/prejoin';
125
 } from './react/features/prejoin';
123
 import { createRnnoiseProcessorPromise } from './react/features/rnnoise';
126
 import { createRnnoiseProcessorPromise } from './react/features/rnnoise';
124
 import { toggleScreenshotCaptureEffect } from './react/features/screenshot-capture';
127
 import { toggleScreenshotCaptureEffect } from './react/features/screenshot-capture';
1400
     /**
1403
     /**
1401
      * Start using provided video stream.
1404
      * Start using provided video stream.
1402
      * Stops previous video stream.
1405
      * Stops previous video stream.
1403
-     * @param {JitsiLocalTrack} [stream] new stream to use or null
1406
+     * @param {JitsiLocalTrack} newTrack - new track to use or null
1404
      * @returns {Promise}
1407
      * @returns {Promise}
1405
      */
1408
      */
1406
-    useVideoStream(newStream) {
1409
+    useVideoStream(newTrack) {
1407
         return new Promise((resolve, reject) => {
1410
         return new Promise((resolve, reject) => {
1408
             _replaceLocalVideoTrackQueue.enqueue(onFinish => {
1411
             _replaceLocalVideoTrackQueue.enqueue(onFinish => {
1412
+                const state = APP.store.getState();
1413
+
1414
+                // When the prejoin page is displayed localVideo is not set
1415
+                // so just replace the video track from the store with the new one.
1416
+                if (isPrejoinPageVisible(state)) {
1417
+                    const oldTrack = getLocalJitsiVideoTrack(state);
1418
+
1419
+                    return APP.store.dispatch(replaceLocalTrack(oldTrack, newTrack))
1420
+                        .then(resolve)
1421
+                        .catch(reject)
1422
+                        .then(onFinish);
1423
+                }
1424
+
1409
                 APP.store.dispatch(
1425
                 APP.store.dispatch(
1410
-                replaceLocalTrack(this.localVideo, newStream, room))
1426
+                replaceLocalTrack(this.localVideo, newTrack, room))
1411
                     .then(() => {
1427
                     .then(() => {
1412
-                        this.localVideo = newStream;
1413
-                        this._setSharingScreen(newStream);
1414
-                        if (newStream) {
1415
-                            APP.UI.addLocalVideoStream(newStream);
1428
+                        this.localVideo = newTrack;
1429
+                        this._setSharingScreen(newTrack);
1430
+                        if (newTrack) {
1431
+                            APP.UI.addLocalVideoStream(newTrack);
1416
                         }
1432
                         }
1417
                         this.setVideoMuteStatus(this.isLocalVideoMuted());
1433
                         this.setVideoMuteStatus(this.isLocalVideoMuted());
1418
                     })
1434
                     })
1453
     /**
1469
     /**
1454
      * Start using provided audio stream.
1470
      * Start using provided audio stream.
1455
      * Stops previous audio stream.
1471
      * Stops previous audio stream.
1456
-     * @param {JitsiLocalTrack} [stream] new stream to use or null
1472
+     * @param {JitsiLocalTrack} newTrack - new track to use or null
1457
      * @returns {Promise}
1473
      * @returns {Promise}
1458
      */
1474
      */
1459
-    useAudioStream(newStream) {
1475
+    useAudioStream(newTrack) {
1460
         return new Promise((resolve, reject) => {
1476
         return new Promise((resolve, reject) => {
1461
             _replaceLocalAudioTrackQueue.enqueue(onFinish => {
1477
             _replaceLocalAudioTrackQueue.enqueue(onFinish => {
1478
+                const state = APP.store.getState();
1479
+
1480
+                // When the prejoin page is displayed localAudio is not set
1481
+                // so just replace the audio track from the store with the new one.
1482
+                if (isPrejoinPageVisible(state)) {
1483
+                    const oldTrack = getLocalJitsiAudioTrack(state);
1484
+
1485
+                    return APP.store.dispatch(replaceLocalTrack(oldTrack, newTrack))
1486
+                        .then(resolve)
1487
+                        .catch(reject)
1488
+                        .then(onFinish);
1489
+                }
1490
+
1462
                 APP.store.dispatch(
1491
                 APP.store.dispatch(
1463
-                replaceLocalTrack(this.localAudio, newStream, room))
1492
+                replaceLocalTrack(this.localAudio, newTrack, room))
1464
                     .then(() => {
1493
                     .then(() => {
1465
-                        this.localAudio = newStream;
1494
+                        this.localAudio = newTrack;
1466
                         this.setAudioMuteStatus(this.isLocalAudioMuted());
1495
                         this.setAudioMuteStatus(this.isLocalAudioMuted());
1467
                     })
1496
                     })
1468
                     .then(resolve)
1497
                     .then(resolve)

+ 12
- 0
react/features/base/tracks/functions.js View File

210
     return track?.jitsiTrack;
210
     return track?.jitsiTrack;
211
 }
211
 }
212
 
212
 
213
+/**
214
+ * Returns the stored local audio track.
215
+ *
216
+ * @param {Object} state - The redux state.
217
+ * @returns {Object}
218
+ */
219
+export function getLocalJitsiAudioTrack(state) {
220
+    const track = getLocalAudioTrack(state['features/base/tracks']);
221
+
222
+    return track?.jitsiTrack;
223
+}
224
+
213
 /**
225
 /**
214
  * Returns track of specified media type for specified participant id.
226
  * Returns track of specified media type for specified participant id.
215
  *
227
  *

Loading…
Cancel
Save