Pārlūkot izejas kodu

feat: add config.startWithAudioMuted config.startWithVideoMuted

master
paweldomas 7 gadus atpakaļ
vecāks
revīzija
d2e8b13add
2 mainītis faili ar 68 papildinājumiem un 24 dzēšanām
  1. 66
    24
      conference.js
  2. 2
    0
      config.js

+ 66
- 24
conference.js Parādīt failu

@@ -493,6 +493,10 @@ export default {
493 493
      * on.
494 494
      * @param {boolean} options.startScreenSharing=false - if <tt>true</tt>
495 495
      * should start with screensharing instead of camera video.
496
+     * @param {boolean} options.startWithAudioMuted - will start the conference
497
+     * without any audio tracks.
498
+     * @param {boolean} options.startWithVideoMuted - will start the conference
499
+     * without any video tracks.
496 500
      * @returns {Promise.<JitsiLocalTrack[], JitsiConnection>}
497 501
      */
498 502
     createInitialLocalTracksAndConnect(roomName, options = {}) {
@@ -500,6 +504,20 @@ export default {
500 504
             audioOnlyError,
501 505
             screenSharingError,
502 506
             videoOnlyError;
507
+        const initialDevices = [];
508
+        let requestedAudio = false;
509
+        let requestedVideo = false;
510
+
511
+        if (!options.startWithAudioMuted) {
512
+            initialDevices.push('audio');
513
+            requestedAudio = true;
514
+        }
515
+        if (!options.startWithVideoMuted
516
+                && !options.startAudioOnly
517
+                && !options.startScreenSharing) {
518
+            initialDevices.push('video');
519
+            requestedVideo = true;
520
+        }
503 521
 
504 522
         JitsiMeetJS.mediaDevices.addEventListener(
505 523
             JitsiMeetJS.events.mediaDevices.PERMISSION_PROMPT_IS_SHOWN,
@@ -508,26 +526,21 @@ export default {
508 526
                     mediaPermissionPromptVisibilityChanged(true, browser))
509 527
         );
510 528
 
511
-        // First try to retrieve both audio and video.
512 529
         let tryCreateLocalTracks;
513 530
 
514
-        // FIXME the logic about trying to go audio only on error is duplicated
515
-        if (options.startAudioOnly) {
516
-            tryCreateLocalTracks
517
-                = createLocalTracks({ devices: ['audio'] }, true)
518
-                    .catch(err => {
519
-                        audioOnlyError = err;
520
-
521
-                        return [];
522
-                    });
531
+        // Enable audio only mode
532
+        if (config.startAudioOnly) {
533
+            APP.store.dispatch(toggleAudioOnly());
534
+        }
523 535
 
524
-            // Enable audio only mode
525
-            if (config.startAudioOnly) {
526
-                APP.store.dispatch(toggleAudioOnly());
527
-            }
528
-        } else if (options.startScreenSharing) {
536
+        // FIXME is there any simpler way to rewrite this spaghetti below ?
537
+        if (options.startScreenSharing) {
529 538
             tryCreateLocalTracks = this._createDesktopTrack()
530 539
                 .then(desktopStream => {
540
+                    if (!requestedAudio) {
541
+                        return [desktopStream];
542
+                    }
543
+
531 544
                     return createLocalTracks({ devices: ['audio'] }, true)
532 545
                         .then(([audioStream]) => {
533 546
                             return [desktopStream, audioStream];
@@ -539,26 +552,53 @@ export default {
539 552
                 }).catch(error => {
540 553
                     logger.error('Failed to obtain desktop stream', error);
541 554
                     screenSharingError = error;
542
-                    return createLocalTracks({ devices: ['audio'] }, true);
555
+                    return requestedAudio
556
+                        ? createLocalTracks({ devices: ['audio'] }, true)
557
+                        : [];
543 558
                 }).catch(error => {
544 559
                     audioOnlyError = error;
545 560
                     return [];
546 561
                 });
562
+        } else if (!requestedAudio && !requestedVideo) {
563
+            // Resolve with no tracks
564
+            tryCreateLocalTracks = Promise.resolve([]);
547 565
         } else {
548 566
             tryCreateLocalTracks = createLocalTracks(
549
-                {devices: ['audio', 'video']}, true)
550
-                .catch(err => {
551
-                    // If failed then try to retrieve only audio.
552
-                    audioAndVideoError = err;
553
-                    return createLocalTracks({devices: ['audio']}, true);
554
-                })
567
+                { devices: initialDevices }, true)
555 568
                 .catch(err => {
569
+                    if (requestedAudio && requestedVideo) {
570
+
571
+                        // Try audio only...
572
+                        audioAndVideoError = err;
573
+
574
+                        return createLocalTracks({devices: ['audio']}, true);
575
+                    } else if (requestedAudio && !requestedVideo) {
576
+                        audioOnlyError = err;
577
+
578
+                        return [];
579
+                    } else if (requestedVideo && !requestedAudio) {
580
+                        videoOnlyError = err;
581
+
582
+                        return [];
583
+                    }
584
+                    logger.error('Should never happen');
585
+                }).catch(err => {
586
+                    // Log this just in case...
587
+                    if (!requestedAudio) {
588
+                        logger.error('The impossible just happened', err);
589
+                    }
556 590
                     audioOnlyError = err;
557 591
 
558 592
                     // Try video only...
559
-                    return createLocalTracks({devices: ['video']}, true);
593
+                    return requestedVideo
594
+                        ? createLocalTracks({devices: ['video']}, true)
595
+                        : [];
560 596
                 })
561 597
                 .catch(err => {
598
+                    // Log this just in case...
599
+                    if (!requestedVideo) {
600
+                        logger.error('The impossible just happened', err);
601
+                    }
562 602
                     videoOnlyError = err;
563 603
 
564 604
                     return [];
@@ -634,7 +674,9 @@ export default {
634 674
                 return this.createInitialLocalTracksAndConnect(
635 675
                     options.roomName, {
636 676
                         startAudioOnly: config.startAudioOnly,
637
-                        startScreenSharing: config.startScreenSharing
677
+                        startScreenSharing: config.startScreenSharing,
678
+                        startWithAudioMuted: config.startWithAudioMuted,
679
+                        startWithVideoMuted: config.startWithVideoMuted,
638 680
                     });
639 681
             }).then(([tracks, con]) => {
640 682
                 tracks.forEach(track => {

+ 2
- 0
config.js Parādīt failu

@@ -80,6 +80,8 @@ var config = { // eslint-disable-line no-unused-vars
80 80
     startScreenSharing: false, // Will try to start with screensharing instead of camera
81 81
 //    startAudioMuted: 10, // every participant after the Nth will start audio muted
82 82
 //    startVideoMuted: 10, // every participant after the Nth will start video muted
83
+    startWithAudioMuted: false, // will start with the microphone muted
84
+    startWithVideoMuted: false, // will start with the camera turned off
83 85
 //    defaultLanguage: "en",
84 86
 // To enable sending statistics to callstats.io you should provide Applicaiton ID and Secret.
85 87
 //    callStatsID: "", // Application ID for callstats.io API

Notiek ielāde…
Atcelt
Saglabāt