瀏覽代碼

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 年之前
父節點
當前提交
c03e66954d

+ 8
- 5
react/features/base/tracks/actions.js 查看文件

@@ -20,7 +20,7 @@ import {
20 20
     TRACK_UPDATED,
21 21
     TRACK_WILL_CREATE
22 22
 } from './actionTypes';
23
-import { createLocalTracksF } from './functions';
23
+import { createLocalTracksF, getLocalTrack, getLocalTracks } from './functions';
24 24
 
25 25
 const logger = require('jitsi-meet-logger').getLogger(__filename);
26 26
 
@@ -45,8 +45,9 @@ export function createDesiredLocalTracks(...desiredTypes) {
45 45
         }
46 46
 
47 47
         const availableTypes
48
-            = state['features/base/tracks']
49
-                .filter(t => t.local)
48
+            = getLocalTracks(
49
+                    state['features/base/tracks'],
50
+                    /* includePending */ true)
50 51
                 .map(t => t.mediaType);
51 52
 
52 53
         // We need to create the desired tracks which are not already available.
@@ -85,8 +86,10 @@ export function createLocalTracksA(options = {}) {
85 86
         // to implement them) and the right thing to do is to ask for each
86 87
         // device separately.
87 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 93
                 throw new Error(`Local track for ${device} already exists`);
91 94
             }
92 95
 

+ 17
- 6
react/features/base/tracks/functions.js 查看文件

@@ -106,21 +106,32 @@ export function getLocalAudioTrack(tracks) {
106 106
  *
107 107
  * @param {Track[]} tracks - List of all tracks.
108 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 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 124
  * {@code JitsiTrack}.
118 125
  *
119 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 132
  * @returns {Track[]}
121 133
  */
122
-export function getLocalTracks(tracks) {
123
-
134
+export function getLocalTracks(tracks, includePending = false) {
124 135
     // XXX A local track is considered ready only once it has its `jitsiTrack`
125 136
     // property set by the `TRACK_ADDED` action. Until then there is a stub
126 137
     // added just before the `getUserMedia` call with a cancellable
@@ -128,7 +139,7 @@ export function getLocalTracks(tracks) {
128 139
     // has not yet been added to the redux store. Once GUM is cancelled, it will
129 140
     // never make it to the store nor there will be any
130 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 查看文件

@@ -147,12 +147,24 @@ MiddlewareRegistry.register(store => next => action => {
147 147
  * with the specified {@code mediaType} is to be retrieved.
148 148
  * @param {MEDIA_TYPE} mediaType - The {@code MEDIA_TYPE} of the local track to
149 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 155
  * @private
151 156
  * @returns {Track} The local {@code Track} associated with the specified
152 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,10 +179,17 @@ function _getLocalTrack({ getState }, mediaType: MEDIA_TYPE) {
167 179
  * @returns {void}
168 180
  */
169 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 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 193
     } else if (!muted && ensureTrack && typeof APP === 'undefined') {
175 194
         // FIXME: This only runs on mobile now because web has its own way of
176 195
         // creating local tracks. Adjust the check once they are unified.

Loading…
取消
儲存