Pārlūkot izejas kodu

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

j8
yanas 11 gadus atpakaļ
vecāks
revīzija
1c1c3f8f5b
3 mainītis faili ar 76 papildinājumiem un 38 dzēšanām
  1. 6
    1
      app.js
  2. 5
    18
      data_channels.js
  3. 65
    19
      videolayout.js

+ 6
- 1
app.js Parādīt failu

319
 
319
 
320
             // If the video has been "pinned" by the user we want to keep the
320
             // If the video has been "pinned" by the user we want to keep the
321
             // display name on place.
321
             // display name on place.
322
-            if (focusedVideoSrc !== videoSrc)
322
+            if (focusedVideoSrc && focusedVideoSrc !== videoSrc
323
+                || (!focusedVideoSrc
324
+                    && container.id
325
+                        !== VideoLayout.getActiveSpeakerContainerId()))
323
                 VideoLayout.showDisplayName(container.id, false);
326
                 VideoLayout.showDisplayName(container.id, false);
324
         }
327
         }
325
     );
328
     );
436
         {
439
         {
437
             console.info(jid +  " audio level: " +
440
             console.info(jid +  " audio level: " +
438
                 peerStats.ssrc2AudioLevel[ssrc] + " of ssrc: " + ssrc);
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 Parādīt failu

30
         console.info("Got Data Channel Message:", msgData, dataChannel);
30
         console.info("Got Data Channel Message:", msgData, dataChannel);
31
 
31
 
32
         // Active speaker event
32
         // Active speaker event
33
-        if (msgData.indexOf('activeSpeaker') === 0 && !focusedVideoSrc)
33
+        if (msgData.indexOf('activeSpeaker') === 0)
34
         {
34
         {
35
             // Endpoint ID from the bridge
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 Parādīt failu

138
     my.handleVideoThumbClicked = function(videoSrc) {
138
     my.handleVideoThumbClicked = function(videoSrc) {
139
         // Restore style for previously focused video
139
         // Restore style for previously focused video
140
         var focusJid = getJidFromVideoSrc(focusedVideoSrc);
140
         var focusJid = getJidFromVideoSrc(focusedVideoSrc);
141
-        var oldContainer =
142
-            getParticipantContainer(focusJid);
141
+        var oldContainer = getParticipantContainer(focusJid);
143
 
142
 
144
         if (oldContainer) {
143
         if (oldContainer) {
145
             oldContainer.removeClass("videoContainerFocused");
144
             oldContainer.removeClass("videoContainerFocused");
147
                     Strophe.getResourceFromJid(focusJid), false);
146
                     Strophe.getResourceFromJid(focusJid), false);
148
         }
147
         }
149
 
148
 
150
-        // Unlock
149
+        // Unlock current focused.
151
         if (focusedVideoSrc === videoSrc)
150
         if (focusedVideoSrc === videoSrc)
152
         {
151
         {
153
             focusedVideoSrc = null;
152
             focusedVideoSrc = null;
153
+            // Enable the currently set active speaker.
154
+            if (currentActiveSpeaker) {
155
+                VideoLayout.enableActiveSpeaker(currentActiveSpeaker, true);
156
+            }
157
+
154
             return;
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
         // Lock new video
166
         // Lock new video
158
         focusedVideoSrc = videoSrc;
167
         focusedVideoSrc = videoSrc;
526
      * disabled
535
      * disabled
527
      */
536
      */
528
     my.enableActiveSpeaker = function(resourceJid, isEnable) {
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
         var videoSpanId = null;
545
         var videoSpanId = null;
532
         if (resourceJid
546
         if (resourceJid
542
             return;
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
         var video = $('#' + videoSpanId + '>video');
559
         var video = $('#' + videoSpanId + '>video');
561
 
560
 
562
         if (video && video.length > 0) {
561
         if (video && video.length > 0) {
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
      * Adds the remote video menu element for the given <tt>jid</tt> in the
743
      * Adds the remote video menu element for the given <tt>jid</tt> in the
738
      * given <tt>parentElement</tt>.
744
      * given <tt>parentElement</tt>.
841
             VideoLayout.showVideoIndicator(videoSpanId, isMuted);
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
     return my;
890
     return my;
845
 }(VideoLayout || {}));
891
 }(VideoLayout || {}));

Notiek ielāde…
Atcelt
Saglabāt