Преглед изворни кода

Merge pull request #156 from jitsi/be-forgiving

Be forgiving towards API clients
dev1
hristoterezov пре 9 година
родитељ
комит
db2940b5a5
1 измењених фајлова са 16 додато и 6 уклоњено
  1. 16
    6
      JitsiConference.js

+ 16
- 6
JitsiConference.js Прегледај датотеку

@@ -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) {

Loading…
Откажи
Сачувај