Browse Source

feat: add config.startWithAudioMuted config.startWithVideoMuted

master
paweldomas 7 years ago
parent
commit
d2e8b13add
2 changed files with 68 additions and 24 deletions
  1. 66
    24
      conference.js
  2. 2
    0
      config.js

+ 66
- 24
conference.js View File

493
      * on.
493
      * on.
494
      * @param {boolean} options.startScreenSharing=false - if <tt>true</tt>
494
      * @param {boolean} options.startScreenSharing=false - if <tt>true</tt>
495
      * should start with screensharing instead of camera video.
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
      * @returns {Promise.<JitsiLocalTrack[], JitsiConnection>}
500
      * @returns {Promise.<JitsiLocalTrack[], JitsiConnection>}
497
      */
501
      */
498
     createInitialLocalTracksAndConnect(roomName, options = {}) {
502
     createInitialLocalTracksAndConnect(roomName, options = {}) {
500
             audioOnlyError,
504
             audioOnlyError,
501
             screenSharingError,
505
             screenSharingError,
502
             videoOnlyError;
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
         JitsiMeetJS.mediaDevices.addEventListener(
522
         JitsiMeetJS.mediaDevices.addEventListener(
505
             JitsiMeetJS.events.mediaDevices.PERMISSION_PROMPT_IS_SHOWN,
523
             JitsiMeetJS.events.mediaDevices.PERMISSION_PROMPT_IS_SHOWN,
508
                     mediaPermissionPromptVisibilityChanged(true, browser))
526
                     mediaPermissionPromptVisibilityChanged(true, browser))
509
         );
527
         );
510
 
528
 
511
-        // First try to retrieve both audio and video.
512
         let tryCreateLocalTracks;
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
             tryCreateLocalTracks = this._createDesktopTrack()
538
             tryCreateLocalTracks = this._createDesktopTrack()
530
                 .then(desktopStream => {
539
                 .then(desktopStream => {
540
+                    if (!requestedAudio) {
541
+                        return [desktopStream];
542
+                    }
543
+
531
                     return createLocalTracks({ devices: ['audio'] }, true)
544
                     return createLocalTracks({ devices: ['audio'] }, true)
532
                         .then(([audioStream]) => {
545
                         .then(([audioStream]) => {
533
                             return [desktopStream, audioStream];
546
                             return [desktopStream, audioStream];
539
                 }).catch(error => {
552
                 }).catch(error => {
540
                     logger.error('Failed to obtain desktop stream', error);
553
                     logger.error('Failed to obtain desktop stream', error);
541
                     screenSharingError = error;
554
                     screenSharingError = error;
542
-                    return createLocalTracks({ devices: ['audio'] }, true);
555
+                    return requestedAudio
556
+                        ? createLocalTracks({ devices: ['audio'] }, true)
557
+                        : [];
543
                 }).catch(error => {
558
                 }).catch(error => {
544
                     audioOnlyError = error;
559
                     audioOnlyError = error;
545
                     return [];
560
                     return [];
546
                 });
561
                 });
562
+        } else if (!requestedAudio && !requestedVideo) {
563
+            // Resolve with no tracks
564
+            tryCreateLocalTracks = Promise.resolve([]);
547
         } else {
565
         } else {
548
             tryCreateLocalTracks = createLocalTracks(
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
                 .catch(err => {
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
                     audioOnlyError = err;
590
                     audioOnlyError = err;
557
 
591
 
558
                     // Try video only...
592
                     // Try video only...
559
-                    return createLocalTracks({devices: ['video']}, true);
593
+                    return requestedVideo
594
+                        ? createLocalTracks({devices: ['video']}, true)
595
+                        : [];
560
                 })
596
                 })
561
                 .catch(err => {
597
                 .catch(err => {
598
+                    // Log this just in case...
599
+                    if (!requestedVideo) {
600
+                        logger.error('The impossible just happened', err);
601
+                    }
562
                     videoOnlyError = err;
602
                     videoOnlyError = err;
563
 
603
 
564
                     return [];
604
                     return [];
634
                 return this.createInitialLocalTracksAndConnect(
674
                 return this.createInitialLocalTracksAndConnect(
635
                     options.roomName, {
675
                     options.roomName, {
636
                         startAudioOnly: config.startAudioOnly,
676
                         startAudioOnly: config.startAudioOnly,
637
-                        startScreenSharing: config.startScreenSharing
677
+                        startScreenSharing: config.startScreenSharing,
678
+                        startWithAudioMuted: config.startWithAudioMuted,
679
+                        startWithVideoMuted: config.startWithVideoMuted,
638
                     });
680
                     });
639
             }).then(([tracks, con]) => {
681
             }).then(([tracks, con]) => {
640
                 tracks.forEach(track => {
682
                 tracks.forEach(track => {

+ 2
- 0
config.js View File

80
     startScreenSharing: false, // Will try to start with screensharing instead of camera
80
     startScreenSharing: false, // Will try to start with screensharing instead of camera
81
 //    startAudioMuted: 10, // every participant after the Nth will start audio muted
81
 //    startAudioMuted: 10, // every participant after the Nth will start audio muted
82
 //    startVideoMuted: 10, // every participant after the Nth will start video muted
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
 //    defaultLanguage: "en",
85
 //    defaultLanguage: "en",
84
 // To enable sending statistics to callstats.io you should provide Applicaiton ID and Secret.
86
 // To enable sending statistics to callstats.io you should provide Applicaiton ID and Secret.
85
 //    callStatsID: "", // Application ID for callstats.io API
87
 //    callStatsID: "", // Application ID for callstats.io API

Loading…
Cancel
Save