瀏覽代碼

Fixes active speaker relevant issues. Moves all UI related code in the videolayout.js

j8
yanas 11 年之前
父節點
當前提交
1c1c3f8f5b
共有 3 個文件被更改,包括 76 次插入38 次删除
  1. 6
    1
      app.js
  2. 5
    18
      data_channels.js
  3. 65
    19
      videolayout.js

+ 6
- 1
app.js 查看文件

@@ -319,7 +319,10 @@ $(document).bind('remotestreamadded.jingle', function (event, data, sid) {
319 319
 
320 320
             // If the video has been "pinned" by the user we want to keep the
321 321
             // display name on place.
322
-            if (focusedVideoSrc !== videoSrc)
322
+            if (focusedVideoSrc && focusedVideoSrc !== videoSrc
323
+                || (!focusedVideoSrc
324
+                    && container.id
325
+                        !== VideoLayout.getActiveSpeakerContainerId()))
323 326
                 VideoLayout.showDisplayName(container.id, false);
324 327
         }
325 328
     );
@@ -436,6 +439,8 @@ function statsUpdated(statsCollector)
436 439
         {
437 440
             console.info(jid +  " audio level: " +
438 441
                 peerStats.ssrc2AudioLevel[ssrc] + " of ssrc: " + ssrc);
442
+//            VideoLayout.updateAudioLevel(   Strophe.getResourceFromJid(jid),
443
+//                                            peerStats.ssrc2AudioLevel[ssrc]);
439 444
         });
440 445
     });
441 446
 }

+ 5
- 18
data_channels.js 查看文件

@@ -30,27 +30,14 @@ function onDataChannel(event)
30 30
         console.info("Got Data Channel Message:", msgData, dataChannel);
31 31
 
32 32
         // Active speaker event
33
-        if (msgData.indexOf('activeSpeaker') === 0 && !focusedVideoSrc)
33
+        if (msgData.indexOf('activeSpeaker') === 0)
34 34
         {
35 35
             // Endpoint ID from the bridge
36
-            var endpointId = msgData.split(":")[1];
37
-            console.info("New active speaker: " + endpointId);
36
+            var resourceJid = msgData.split(":")[1];
38 37
 
39
-            var container  = document.getElementById(
40
-                'participant_' + endpointId);
41
-
42
-            // Local video will not have container found, but that's ok
43
-            // since we don't want to switch to local video
44
-
45
-            if (container)
46
-            {
47
-                var video = container.getElementsByTagName("video");
48
-                if (video.length)
49
-                {
50
-                    VideoLayout.updateLargeVideo(video[0].src);
51
-                    VideoLayout.enableActiveSpeaker(endpointId, true);
52
-                }
53
-            }
38
+            console.info(
39
+                "Data channel new active speaker event: " + resourceJid);
40
+            $(document).trigger('activespeakerchanged', [resourceJid]);
54 41
         }
55 42
     };
56 43
 

+ 65
- 19
videolayout.js 查看文件

@@ -138,8 +138,7 @@ var VideoLayout = (function (my) {
138 138
     my.handleVideoThumbClicked = function(videoSrc) {
139 139
         // Restore style for previously focused video
140 140
         var focusJid = getJidFromVideoSrc(focusedVideoSrc);
141
-        var oldContainer =
142
-            getParticipantContainer(focusJid);
141
+        var oldContainer = getParticipantContainer(focusJid);
143 142
 
144 143
         if (oldContainer) {
145 144
             oldContainer.removeClass("videoContainerFocused");
@@ -147,12 +146,22 @@ var VideoLayout = (function (my) {
147 146
                     Strophe.getResourceFromJid(focusJid), false);
148 147
         }
149 148
 
150
-        // Unlock
149
+        // Unlock current focused.
151 150
         if (focusedVideoSrc === videoSrc)
152 151
         {
153 152
             focusedVideoSrc = null;
153
+            // Enable the currently set active speaker.
154
+            if (currentActiveSpeaker) {
155
+                VideoLayout.enableActiveSpeaker(currentActiveSpeaker, true);
156
+            }
157
+
154 158
             return;
155 159
         }
160
+        // Remove style for current active speaker if we're going to lock
161
+        // another video.
162
+        else if (currentActiveSpeaker) {
163
+            VideoLayout.enableActiveSpeaker(currentActiveSpeaker, false);
164
+        }
156 165
 
157 166
         // Lock new video
158 167
         focusedVideoSrc = videoSrc;
@@ -526,7 +535,12 @@ var VideoLayout = (function (my) {
526 535
      * disabled
527 536
      */
528 537
     my.enableActiveSpeaker = function(resourceJid, isEnable) {
529
-        console.log("Enable active speaker", resourceJid, isEnable);
538
+        var displayName = resourceJid;
539
+        var nameSpan = $('#participant_' + resourceJid + '>span.displayname');
540
+        if (nameSpan.length > 0)
541
+            displayName = nameSpan.text();
542
+
543
+        console.log("Enable active speaker", displayName, isEnable);
530 544
 
531 545
         var videoSpanId = null;
532 546
         if (resourceJid
@@ -542,21 +556,6 @@ var VideoLayout = (function (my) {
542 556
             return;
543 557
         }
544 558
 
545
-        // If there's an active speaker (automatically) selected we have to
546
-        // disable this state and update the current active speaker.
547
-        if (isEnable) {
548
-            if (currentActiveSpeaker) {
549
-                var oldSpeaker = currentActiveSpeaker;
550
-                setTimeout(function () {
551
-                    VideoLayout.enableActiveSpeaker(oldSpeaker, false);
552
-                    }, 200);
553
-            }
554
-
555
-            currentActiveSpeaker = resourceJid;
556
-        }
557
-        else if (resourceJid === currentActiveSpeaker)
558
-            currentActiveSpeaker = null;
559
-
560 559
         var video = $('#' + videoSpanId + '>video');
561 560
 
562 561
         if (video && video.length > 0) {
@@ -733,6 +732,13 @@ var VideoLayout = (function (my) {
733 732
         }
734 733
     };
735 734
 
735
+    /**
736
+     * Returns the current active speaker.
737
+     */
738
+    my.getActiveSpeakerContainerId = function () {
739
+        return 'participant_' + currentActiveSpeaker;
740
+    };
741
+
736 742
     /**
737 743
      * Adds the remote video menu element for the given <tt>jid</tt> in the
738 744
      * given <tt>parentElement</tt>.
@@ -841,5 +847,45 @@ var VideoLayout = (function (my) {
841 847
             VideoLayout.showVideoIndicator(videoSpanId, isMuted);
842 848
     });
843 849
 
850
+    /**
851
+     * On active speaker changed event.
852
+     */
853
+    $(document).bind('activespeakerchanged', function (event, resourceJid) {
854
+
855
+        // Disable style for previous active speaker.
856
+        if (currentActiveSpeaker
857
+                && currentActiveSpeaker !== resourceJid
858
+                && !focusedVideoSrc) {
859
+            var oldContainer  = document.getElementById(
860
+                    'participant_' + currentActiveSpeaker);
861
+
862
+            if (oldContainer) {
863
+                VideoLayout.enableActiveSpeaker(currentActiveSpeaker, false);
864
+            }
865
+        }
866
+
867
+        // Obtain container for new active speaker.
868
+        var container  = document.getElementById(
869
+                'participant_' + resourceJid);
870
+
871
+        // Update the current active speaker.
872
+        if (resourceJid !== currentActiveSpeaker)
873
+            currentActiveSpeaker = resourceJid;
874
+        else
875
+            return;
876
+
877
+        // Local video will not have container found, but that's ok
878
+        // since we don't want to switch to local video.
879
+        if (container && !focusedVideoSrc)
880
+        {
881
+            var video = container.getElementsByTagName("video");
882
+            if (video.length)
883
+            {
884
+                VideoLayout.updateLargeVideo(video[0].src);
885
+                VideoLayout.enableActiveSpeaker(resourceJid, true);
886
+            }
887
+        }
888
+    });
889
+
844 890
     return my;
845 891
 }(VideoLayout || {}));

Loading…
取消
儲存