浏览代码

simplify Promise chaining in FlacAdapter

master
Radium Zheng 7 年前
父节点
当前提交
e2def5f88b
共有 1 个文件被更改,包括 14 次插入20 次删除
  1. 14
    20
      react/features/local-recording/recording/flac/FlacAdapter.js

+ 14
- 20
react/features/local-recording/recording/flac/FlacAdapter.js 查看文件

145
     /**
145
     /**
146
      * Replaces the current microphone MediaStream.
146
      * Replaces the current microphone MediaStream.
147
      *
147
      *
148
-     * @param {*} micDeviceId - New microphone ID.
148
+     * @param {string} micDeviceId - New microphone ID.
149
      * @returns {Promise}
149
      * @returns {Promise}
150
      */
150
      */
151
     _replaceMic(micDeviceId) {
151
     _replaceMic(micDeviceId) {
152
         if (this._audioContext && this._audioProcessingNode) {
152
         if (this._audioContext && this._audioProcessingNode) {
153
-            return new Promise((resolve, reject) => {
154
-                this._getAudioStream(micDeviceId).then(newStream => {
155
-                    const newSource = this._audioContext
156
-                        .createMediaStreamSource(newStream);
157
-
158
-                    this._audioSource.disconnect();
159
-                    newSource.connect(this._audioProcessingNode);
160
-                    this._stream = newStream;
161
-                    this._audioSource = newSource;
162
-                    resolve();
163
-                })
164
-                .catch(() => {
165
-                    reject();
166
-                });
153
+            return this._getAudioStream(micDeviceId).then(newStream => {
154
+                const newSource = this._audioContext
155
+                    .createMediaStreamSource(newStream);
156
+
157
+                this._audioSource.disconnect();
158
+                newSource.connect(this._audioProcessingNode);
159
+                this._stream = newStream;
160
+                this._audioSource = newSource;
161
+
167
             });
162
             });
168
         }
163
         }
169
 
164
 
221
             });
216
             });
222
         });
217
         });
223
 
218
 
224
-        const callbackInitAudioContext = (resolve, reject) => {
219
+        const callbackInitAudioContext = () =>
225
             this._getAudioStream(micDeviceId)
220
             this._getAudioStream(micDeviceId)
226
             .then(stream => {
221
             .then(stream => {
227
                 this._stream = stream;
222
                 this._stream = stream;
244
                     });
239
                     });
245
                 };
240
                 };
246
                 logger.debug('AudioContext is set up.');
241
                 logger.debug('AudioContext is set up.');
247
-                resolve();
248
             })
242
             })
249
             .catch(err => {
243
             .catch(err => {
250
                 logger.error(`Error calling getUserMedia(): ${err}`);
244
                 logger.error(`Error calling getUserMedia(): ${err}`);
251
-                reject();
245
+
246
+                return Promise.reject(err);
252
             });
247
             });
253
-        };
254
 
248
 
255
         // Because Promise constructor immediately executes the executor
249
         // Because Promise constructor immediately executes the executor
256
         // function. This is undesirable, we want callbackInitAudioContext to be
250
         // function. This is undesirable, we want callbackInitAudioContext to be
257
         // executed only **after** promiseInitWorker is resolved.
251
         // executed only **after** promiseInitWorker is resolved.
258
         return promiseInitWorker
252
         return promiseInitWorker
259
-            .then(() => new Promise(callbackInitAudioContext));
253
+            .then(callbackInitAudioContext);
260
     }
254
     }
261
 
255
 
262
     /**
256
     /**

正在加载...
取消
保存