浏览代码

ref(video-layout): get dominant speaker state from redux

Instead of keeping dominant speaker locally, get it from redux and be
updated when the dominant speaker changes. This is in an attempt to mimic
the video layout being reactified and connected to redux.
master
Leonard Kim 7 年前
父节点
当前提交
57f7abc6dd

+ 0
- 8
modules/UI/UI.js 查看文件

822
         null);
822
         null);
823
 };
823
 };
824
 
824
 
825
-/**
826
- * Mark user as dominant speaker.
827
- * @param {string} id user id
828
- */
829
-UI.markDominantSpeaker = function(id) {
830
-    VideoLayout.onDominantSpeakerChanged(id);
831
-};
832
-
833
 UI.handleLastNEndpoints = function(leavingIds, enteringIds) {
825
 UI.handleLastNEndpoints = function(leavingIds, enteringIds) {
834
     VideoLayout.onLastNEndpointsChanged(leavingIds, enteringIds);
826
     VideoLayout.onLastNEndpointsChanged(leavingIds, enteringIds);
835
 };
827
 };

+ 4
- 0
modules/UI/videolayout/SmallVideo.js 查看文件

679
         return;
679
         return;
680
     }
680
     }
681
 
681
 
682
+    if (this._showDominantSpeaker === show) {
683
+        return;
684
+    }
685
+
682
     this._showDominantSpeaker = show;
686
     this._showDominantSpeaker = show;
683
 
687
 
684
     this.updateIndicators();
688
     this.updateIndicators();

+ 34
- 43
modules/UI/videolayout/VideoLayout.js 查看文件

5
     JitsiParticipantConnectionStatus
5
     JitsiParticipantConnectionStatus
6
 } from '../../../react/features/base/lib-jitsi-meet';
6
 } from '../../../react/features/base/lib-jitsi-meet';
7
 import {
7
 import {
8
+    getParticipants,
8
     getPinnedParticipant,
9
     getPinnedParticipant,
9
     pinParticipant
10
     pinParticipant
10
 } from '../../../react/features/base/participants';
11
 } from '../../../react/features/base/participants';
21
 const remoteVideos = {};
22
 const remoteVideos = {};
22
 let localVideoThumbnail = null;
23
 let localVideoThumbnail = null;
23
 
24
 
24
-let currentDominantSpeaker = null;
25
-
26
 let eventEmitter = null;
25
 let eventEmitter = null;
27
 
26
 
28
 let largeVideo;
27
 let largeVideo;
43
     }
42
     }
44
 }
43
 }
45
 
44
 
45
+/**
46
+ * Returns the user ID of the remote participant that is current the dominant
47
+ * speaker.
48
+ *
49
+ * @private
50
+ * @returns {string|null}
51
+ */
52
+function getCurrentRemoteDominantSpeakerID() {
53
+    const dominantSpeaker = getParticipants(APP.store.getState)
54
+        .find(participant => participant.dominantSpeaker);
55
+
56
+    if (dominantSpeaker) {
57
+        return dominantSpeaker.local ? null : dominantSpeaker.id;
58
+    }
59
+
60
+    return null;
61
+}
62
+
46
 /**
63
 /**
47
  * Returns the corresponding resource id to the given peer container
64
  * Returns the corresponding resource id to the given peer container
48
  * DOM element.
65
  * DOM element.
228
 
245
 
229
         if (pinnedId) {
246
         if (pinnedId) {
230
             newId = pinnedId;
247
             newId = pinnedId;
231
-        } else if (currentDominantSpeaker) {
232
-            newId = currentDominantSpeaker;
248
+        } else if (getCurrentRemoteDominantSpeakerID()) {
249
+            newId = getCurrentRemoteDominantSpeakerID();
233
         } else { // Otherwise select last visible video
250
         } else { // Otherwise select last visible video
234
             newId = this.electLastVisibleVideo();
251
             newId = this.electLastVisibleVideo();
235
         }
252
         }
392
             this.pinParticipant(null);
409
             this.pinParticipant(null);
393
 
410
 
394
             // Enable the currently set dominant speaker.
411
             // Enable the currently set dominant speaker.
395
-            if (currentDominantSpeaker) {
396
-                this.updateLargeVideo(currentDominantSpeaker);
412
+            if (getCurrentRemoteDominantSpeakerID()) {
413
+                this.updateLargeVideo(getCurrentRemoteDominantSpeakerID());
397
             } else {
414
             } else {
398
                 // if there is no currentDominantSpeaker, it can also be
415
                 // if there is no currentDominantSpeaker, it can also be
399
                 // that local participant is the dominant speaker
416
                 // that local participant is the dominant speaker
501
         const pinnedId = this.getPinnedId();
518
         const pinnedId = this.getPinnedId();
502
 
519
 
503
         if ((!pinnedId
520
         if ((!pinnedId
504
-            && !currentDominantSpeaker
521
+            && !getCurrentRemoteDominantSpeakerID()
505
             && this.isLargeContainerTypeVisible(VIDEO_CONTAINER_TYPE))
522
             && this.isLargeContainerTypeVisible(VIDEO_CONTAINER_TYPE))
506
             || pinnedId === resourceJid
523
             || pinnedId === resourceJid
507
             || (!pinnedId && resourceJid
524
             || (!pinnedId && resourceJid
508
-                && currentDominantSpeaker === resourceJid)
525
+                && getCurrentRemoteDominantSpeakerID() === resourceJid)
509
 
526
 
510
             /* Playback started while we're on the stage - may need to update
527
             /* Playback started while we're on the stage - may need to update
511
                video source with the new stream */
528
                video source with the new stream */
662
 
679
 
663
     /**
680
     /**
664
      * On dominant speaker changed event.
681
      * On dominant speaker changed event.
682
+     *
683
+     * @param {string} id - The participant ID of the new dominant speaker.
684
+     * @returns {void}
665
      */
685
      */
666
     onDominantSpeakerChanged(id) {
686
     onDominantSpeakerChanged(id) {
667
-        if (id === currentDominantSpeaker) {
668
-            return;
669
-        }
670
-
671
-        const oldSpeakerRemoteVideo = remoteVideos[currentDominantSpeaker];
687
+        Object.values(remoteVideos).forEach(remoteVideo =>
688
+            remoteVideo.showDominantSpeakerIndicator(
689
+                id === remoteVideo.getId()));
672
 
690
 
673
-        // We ignore local user events, but just unmark remote user as dominant
674
-        // while we are talking
691
+        localVideoThumbnail.showDominantSpeakerIndicator(
692
+            APP.conference.isLocalId(id));
675
 
693
 
676
-        if (APP.conference.isLocalId(id)) {
677
-            if (oldSpeakerRemoteVideo) {
678
-                oldSpeakerRemoteVideo.showDominantSpeakerIndicator(false);
679
-                currentDominantSpeaker = null;
680
-            }
681
-            localVideoThumbnail.showDominantSpeakerIndicator(true);
682
-
683
-            return;
684
-        }
685
-
686
-        const remoteVideo = remoteVideos[id];
687
-
688
-        if (!remoteVideo) {
694
+        if (!remoteVideos[id]) {
689
             return;
695
             return;
690
         }
696
         }
691
 
697
 
692
-        // Update the current dominant speaker.
693
-        remoteVideo.showDominantSpeakerIndicator(true);
694
-        localVideoThumbnail.showDominantSpeakerIndicator(false);
695
-
696
-        // let's remove the indications from the remote video if any
697
-        if (oldSpeakerRemoteVideo) {
698
-            oldSpeakerRemoteVideo.showDominantSpeakerIndicator(false);
699
-        }
700
-        currentDominantSpeaker = id;
701
-
702
         // Local video will not have container found, but that's ok
698
         // Local video will not have container found, but that's ok
703
         // since we don't want to switch to local video.
699
         // since we don't want to switch to local video.
704
         if (!interfaceConfig.filmStripOnly && !this.getPinnedId()
700
         if (!interfaceConfig.filmStripOnly && !this.getPinnedId()
804
             this.pinParticipant(null);
800
             this.pinParticipant(null);
805
         }
801
         }
806
 
802
 
807
-        if (currentDominantSpeaker === id) {
808
-            logger.info('Dominant speaker has left the conference');
809
-            currentDominantSpeaker = null;
810
-        }
811
-
812
         const remoteVideo = remoteVideos[id];
803
         const remoteVideo = remoteVideos[id];
813
 
804
 
814
         if (remoteVideo) {
805
         if (remoteVideo) {

+ 0
- 2
react/features/base/participants/middleware.js 查看文件

77
                 raisedHand: false
77
                 raisedHand: false
78
             }));
78
             }));
79
 
79
 
80
-        typeof APP === 'object' && APP.UI.markDominantSpeaker(id);
81
-
82
         break;
80
         break;
83
     }
81
     }
84
 
82
 

+ 14
- 1
react/features/video-layout/middleware.web.js 查看文件

1
+import VideoLayout from '../../../modules/UI/videolayout/VideoLayout.js';
2
+
3
+import { DOMINANT_SPEAKER_CHANGED } from '../base/participants';
1
 import { MiddlewareRegistry } from '../base/redux';
4
 import { MiddlewareRegistry } from '../base/redux';
2
 
5
 
3
 /**
6
 /**
9
  * @returns {Function}
12
  * @returns {Function}
10
  */
13
  */
11
 // eslint-disable-next-line no-unused-vars
14
 // eslint-disable-next-line no-unused-vars
12
-MiddlewareRegistry.register(store => next => action => next(action));
15
+MiddlewareRegistry.register(store => next => action => {
16
+    const result = next(action);
17
+
18
+    switch (action.type) {
19
+    case DOMINANT_SPEAKER_CHANGED:
20
+        VideoLayout.onDominantSpeakerChanged(action.participant.id);
21
+        break;
22
+    }
23
+
24
+    return result;
25
+});

正在加载...
取消
保存