Pārlūkot izejas kodu

fix(base/tracks): local track for video already exists

The _setMuted method in a corner case was making an attempt to create
second video track, because it was not taking pending tracks into
account.
master
paweldomas 7 gadus atpakaļ
vecāks
revīzija
c03e66954d

+ 8
- 5
react/features/base/tracks/actions.js Parādīt failu

20
     TRACK_UPDATED,
20
     TRACK_UPDATED,
21
     TRACK_WILL_CREATE
21
     TRACK_WILL_CREATE
22
 } from './actionTypes';
22
 } from './actionTypes';
23
-import { createLocalTracksF } from './functions';
23
+import { createLocalTracksF, getLocalTrack, getLocalTracks } from './functions';
24
 
24
 
25
 const logger = require('jitsi-meet-logger').getLogger(__filename);
25
 const logger = require('jitsi-meet-logger').getLogger(__filename);
26
 
26
 
45
         }
45
         }
46
 
46
 
47
         const availableTypes
47
         const availableTypes
48
-            = state['features/base/tracks']
49
-                .filter(t => t.local)
48
+            = getLocalTracks(
49
+                    state['features/base/tracks'],
50
+                    /* includePending */ true)
50
                 .map(t => t.mediaType);
51
                 .map(t => t.mediaType);
51
 
52
 
52
         // We need to create the desired tracks which are not already available.
53
         // We need to create the desired tracks which are not already available.
85
         // to implement them) and the right thing to do is to ask for each
86
         // to implement them) and the right thing to do is to ask for each
86
         // device separately.
87
         // device separately.
87
         for (const device of devices) {
88
         for (const device of devices) {
88
-            if (getState()['features/base/tracks']
89
-                    .find(t => t.local && t.mediaType === device)) {
89
+            if (getLocalTrack(
90
+                    getState()['features/base/tracks'],
91
+                    device,
92
+                    /* includePending */ true)) {
90
                 throw new Error(`Local track for ${device} already exists`);
93
                 throw new Error(`Local track for ${device} already exists`);
91
             }
94
             }
92
 
95
 

+ 17
- 6
react/features/base/tracks/functions.js Parādīt failu

106
  *
106
  *
107
  * @param {Track[]} tracks - List of all tracks.
107
  * @param {Track[]} tracks - List of all tracks.
108
  * @param {MEDIA_TYPE} mediaType - Media type.
108
  * @param {MEDIA_TYPE} mediaType - Media type.
109
+ * @param {boolean} [includePending] - Indicates whether a local track is to be
110
+ * returned if it is still pending. A local track is pending if
111
+ * {@code getUserMedia} is still executing to create it and, consequently, its
112
+ * {@code jitsiTrack} property is {@code undefined}. By default a pending local
113
+ * track is not returned.
109
  * @returns {(Track|undefined)}
114
  * @returns {(Track|undefined)}
110
  */
115
  */
111
-export function getLocalTrack(tracks, mediaType) {
112
-    return getLocalTracks(tracks).find(t => t.mediaType === mediaType);
116
+export function getLocalTrack(tracks, mediaType, includePending = false) {
117
+    return (
118
+        getLocalTracks(tracks, includePending)
119
+            .find(t => t.mediaType === mediaType));
113
 }
120
 }
114
 
121
 
115
 /**
122
 /**
116
- * Returns an array containing the local tracks with a (valid)
123
+ * Returns an array containing the local tracks with or without a (valid)
117
  * {@code JitsiTrack}.
124
  * {@code JitsiTrack}.
118
  *
125
  *
119
  * @param {Track[]} tracks - An array containing all local tracks.
126
  * @param {Track[]} tracks - An array containing all local tracks.
127
+ * @param {boolean} [includePending] - Indicates whether a local track is to be
128
+ * returned if it is still pending. A local track is pending if
129
+ * {@code getUserMedia} is still executing to create it and, consequently, its
130
+ * {@code jitsiTrack} property is {@code undefined}. By default a pending local
131
+ * track is not returned.
120
  * @returns {Track[]}
132
  * @returns {Track[]}
121
  */
133
  */
122
-export function getLocalTracks(tracks) {
123
-
134
+export function getLocalTracks(tracks, includePending = false) {
124
     // XXX A local track is considered ready only once it has its `jitsiTrack`
135
     // XXX A local track is considered ready only once it has its `jitsiTrack`
125
     // property set by the `TRACK_ADDED` action. Until then there is a stub
136
     // property set by the `TRACK_ADDED` action. Until then there is a stub
126
     // added just before the `getUserMedia` call with a cancellable
137
     // added just before the `getUserMedia` call with a cancellable
128
     // has not yet been added to the redux store. Once GUM is cancelled, it will
139
     // has not yet been added to the redux store. Once GUM is cancelled, it will
129
     // never make it to the store nor there will be any
140
     // never make it to the store nor there will be any
130
     // `TRACK_ADDED`/`TRACK_REMOVED` actions dispatched for it.
141
     // `TRACK_ADDED`/`TRACK_REMOVED` actions dispatched for it.
131
-    return tracks.filter(t => t.local && t.jitsiTrack);
142
+    return tracks.filter(t => t.local && (t.jitsiTrack || includePending));
132
 }
143
 }
133
 
144
 
134
 /**
145
 /**

+ 23
- 4
react/features/base/tracks/middleware.js Parādīt failu

147
  * with the specified {@code mediaType} is to be retrieved.
147
  * with the specified {@code mediaType} is to be retrieved.
148
  * @param {MEDIA_TYPE} mediaType - The {@code MEDIA_TYPE} of the local track to
148
  * @param {MEDIA_TYPE} mediaType - The {@code MEDIA_TYPE} of the local track to
149
  * be retrieved from the specified {@code store}.
149
  * be retrieved from the specified {@code store}.
150
+ * @param {boolean} [includePending] - Indicates whether a local track is to be
151
+ * returned if it is still pending. A local track is pending if
152
+ * {@code getUserMedia} is still executing to create it and, consequently, its
153
+ * {@code jitsiTrack} property is {@code undefined}. By default a pending local
154
+ * track is not returned.
150
  * @private
155
  * @private
151
  * @returns {Track} The local {@code Track} associated with the specified
156
  * @returns {Track} The local {@code Track} associated with the specified
152
  * {@code mediaType} in the specified {@code store}.
157
  * {@code mediaType} in the specified {@code store}.
153
  */
158
  */
154
-function _getLocalTrack({ getState }, mediaType: MEDIA_TYPE) {
155
-    return getLocalTrack(getState()['features/base/tracks'], mediaType);
159
+function _getLocalTrack(
160
+        { getState }: { getState: Function },
161
+        mediaType: MEDIA_TYPE,
162
+        includePending: boolean = false) {
163
+    return (
164
+        getLocalTrack(
165
+            getState()['features/base/tracks'],
166
+            mediaType,
167
+            includePending));
156
 }
168
 }
157
 
169
 
158
 /**
170
 /**
167
  * @returns {void}
179
  * @returns {void}
168
  */
180
  */
169
 function _setMuted(store, { ensureTrack, muted }, mediaType: MEDIA_TYPE) {
181
 function _setMuted(store, { ensureTrack, muted }, mediaType: MEDIA_TYPE) {
170
-    const localTrack = _getLocalTrack(store, mediaType);
182
+    const localTrack
183
+        = _getLocalTrack(store, mediaType, /* includePending */ true);
171
 
184
 
172
     if (localTrack) {
185
     if (localTrack) {
173
-        setTrackMuted(localTrack.jitsiTrack, muted);
186
+        // The `jitsiTrack` property will have a value only for a localTrack for
187
+        // which `getUserMedia` has already completed. If there's no
188
+        // `jitsiTrack`, then the `muted` state will be applied once the
189
+        // `jitsiTrack` is created.
190
+        const { jitsiTrack } = localTrack;
191
+
192
+        jitsiTrack && setTrackMuted(jitsiTrack, muted);
174
     } else if (!muted && ensureTrack && typeof APP === 'undefined') {
193
     } else if (!muted && ensureTrack && typeof APP === 'undefined') {
175
         // FIXME: This only runs on mobile now because web has its own way of
194
         // FIXME: This only runs on mobile now because web has its own way of
176
         // creating local tracks. Adjust the check once they are unified.
195
         // creating local tracks. Adjust the check once they are unified.

Notiek ielāde…
Atcelt
Saglabāt