Ver código fonte

Handle cases when new media devices are added/removed more precisely and more predictable

master
Kostiantyn Tsaregradskyi 9 anos atrás
pai
commit
c1807c3649
1 arquivos alterados com 47 adições e 15 exclusões
  1. 47
    15
      conference.js

+ 47
- 15
conference.js Ver arquivo

@@ -22,6 +22,7 @@ const TrackEvents = JitsiMeetJS.events.track;
22 22
 const TrackErrors = JitsiMeetJS.errors.track;
23 23
 
24 24
 let room, connection, localAudio, localVideo, roomLocker;
25
+let currentAudioInputDevices, currentVideoInputDevices;
25 26
 
26 27
 import {VIDEO_CONTAINER_TYPE} from "./modules/UI/videolayout/LargeVideo";
27 28
 
@@ -197,6 +198,17 @@ function createLocalTracks (devices, cameraDeviceId, micDeviceId) {
197 198
     });
198 199
 }
199 200
 
201
+/**
202
+ * Stores lists of current 'audioinput' and 'videoinput' devices
203
+ * @param {MediaDeviceInfo[]} devices
204
+ */
205
+function setCurrentMediaDevices(devices) {
206
+    currentAudioInputDevices = devices.filter(
207
+        d => d.kind === 'audioinput');
208
+    currentVideoInputDevices = devices.filter(
209
+        d => d.kind === 'videoinput');
210
+}
211
+
200 212
 class ConferenceConnector {
201 213
     constructor(resolve, reject) {
202 214
         this._resolve = resolve;
@@ -408,6 +420,8 @@ export default {
408 420
                             localVideo.getDeviceId());
409 421
                     }
410 422
 
423
+                    setCurrentMediaDevices(devices);
424
+
411 425
                     APP.UI.onAvailableDevicesChanged(devices);
412 426
                 });
413 427
 
@@ -419,6 +433,8 @@ export default {
419 433
                         window.setTimeout(() => {
420 434
                             checkLocalDevicesAfterDeviceListChanged(devices)
421 435
                                 .then(() => {
436
+                                    setCurrentMediaDevices(devices);
437
+
422 438
                                     APP.UI.onAvailableDevicesChanged(devices);
423 439
                                 });
424 440
                         }, 0);
@@ -453,6 +469,12 @@ export default {
453 469
             }
454 470
 
455 471
             function checkLocalDevicesAfterDeviceListChanged(newDevices) {
472
+                // Event handler can be fire before direct enumerateDevices()
473
+                // call, so handle this situation here.
474
+                if (!currentAudioInputDevices && !currentVideoInputDevices) {
475
+                    setCurrentMediaDevices(newDevices);
476
+                }
477
+
456 478
                 checkAudioOutputDeviceAfterDeviceListChanged(newDevices);
457 479
 
458 480
                 let availableAudioInputDevices = newDevices.filter(
@@ -555,39 +577,49 @@ export default {
555 577
                 }
556 578
 
557 579
                 function onTracksCreated(tracks) {
558
-                    tracks && tracks.forEach(track => {
580
+                    return Promise.all((tracks || []).map(track => {
559 581
                         if (track.isAudioTrack()) {
560
-                            self.useAudioStream(track).then(() => {
582
+                            let audioWasMuted = self.audioMuted;
583
+
584
+                            return self.useAudioStream(track).then(() => {
561 585
                                 console.log('switched local audio');
562 586
 
563
-                                // If we have more than 1 device - mute.
564
-                                // We check with 2 for audio, because
565
-                                // it always has 'default' if device is
566
-                                // available at all.
567
-                                // TODO: this is not 100% solution - need
568
-                                // to investigate more
569
-                                if (availableAudioInputDevices.length > 2) {
587
+                                // If we plugged-in new device (and switched to
588
+                                // it), but video was muted before, or we
589
+                                // unplugged current device and selected new
590
+                                // one, then mute new video track.
591
+                                if (audioWasMuted ||
592
+                                    currentAudioInputDevices.length >
593
+                                    availableAudioInputDevices.length) {
570 594
                                     muteLocalAudio(true);
571 595
                                 }
572 596
                             });
573 597
                         } else if (track.isVideoTrack()) {
574
-                            self.useVideoStream(track).then(() => {
598
+                            let videoWasMuted = self.videoMuted;
599
+
600
+                            return self.useVideoStream(track).then(() => {
575 601
                                 console.log('switched local video');
576 602
 
577 603
                                 // TODO: maybe make video large if we
578 604
                                 // are not in conference yet
579
-                                // If we have more than 1 device - mute.
580
-                                // TODO: this is not 100% solution - need
581
-                                // to investigate more
582
-                                if (availableVideoInputDevices.length > 1) {
605
+
606
+                                // If we plugged-in new device (and switched to
607
+                                // it), but video was muted before, or we
608
+                                // unplugged current device and selected new
609
+                                // one, then mute new video track.
610
+                                if (videoWasMuted ||
611
+                                    (currentVideoInputDevices.length >
612
+                                    availableVideoInputDevices.length)) {
583 613
                                     muteLocalVideo(true);
584 614
                                 }
585 615
                             });
586 616
                         } else {
587 617
                             console.error("Ignored not an audio nor a "
588 618
                                 + "video track: ", track);
619
+
620
+                            return Promise.resolve();
589 621
                         }
590
-                    });
622
+                    }));
591 623
                 }
592 624
             }
593 625
         });

Carregando…
Cancelar
Salvar