Quellcode durchsuchen

Be forgiving towards API clients

If the API client happened to try to add one and the same local video
track twice, the library would throw an error. I find that draconian
because:

1. The error message states that a second local video stream cannot be
added but that is incorrect because the API client is not trying to add
a second local video stream but add one and the same local video stream
multiple times.

2. The jsdoc says that a throw will happen if another local video stream
is added but that is misleading because the API client is not trying to
add another local video stream but add the same local video stream.

3. Adding one and the same local video stream multiple times can be
handled gracefully by the lib-jitsi-meet library. Thus, the library
appears more friendly.

Hence, gracefully handle the case of adding the same local video track
multiple times without throwing an error.
dev1
Lyubomir Marinov vor 9 Jahren
Ursprung
Commit
609039745a
1 geänderte Dateien mit 16 neuen und 6 gelöschten Zeilen
  1. 16
    6
      JitsiConference.js

+ 16
- 6
JitsiConference.js Datei anzeigen

@@ -308,17 +308,27 @@ JitsiConference.prototype.setSubject = function (subject) {
308 308
  * Adds JitsiLocalTrack object to the conference.
309 309
  * @param track the JitsiLocalTrack object.
310 310
  * @returns {Promise<JitsiLocalTrack>}
311
- * @throws will throw and error if track is video track
312
- * and there is already another video track in the conference.
311
+ * @throws {Error} if the specified track is a video track and there is already
312
+ * another video track in the conference.
313 313
  */
314 314
 JitsiConference.prototype.addTrack = function (track) {
315
-    if(track.disposed)
316
-    {
315
+    if (track.disposed) {
317 316
         throw new JitsiTrackError(JitsiTrackErrors.TRACK_IS_DISPOSED);
318 317
     }
319 318
 
320
-    if (track.isVideoTrack() && this.rtc.getLocalVideoTrack()) {
321
-        throw new Error("cannot add second video track to the conference");
319
+    if (track.isVideoTrack()) {
320
+        // Ensure there's exactly 1 local video track in the conference.
321
+        var localVideoTrack = this.rtc.getLocalVideoTrack();
322
+        if (localVideoTrack) {
323
+            // Don't be excessively harsh and severe if the API client happens
324
+            // to attempt to add the same local video track twice.
325
+            if (track === localVideoTrack) {
326
+                return Promise.resolve(track);
327
+            } else {
328
+                throw new Error(
329
+                        "cannot add second video track to the conference");
330
+            }
331
+        }
322 332
     }
323 333
 
324 334
     track.ssrcHandler = function (conference, ssrcMap) {

Laden…
Abbrechen
Speichern