Browse Source

Receives all data-channel events/messages from Videobridge as JSON-formatted text. Renames active speaker to dominant speaker.

j8
Lyubomir Marinov 11 years ago
parent
commit
7ce446bcda
4 changed files with 70 additions and 55 deletions
  1. 1
    1
      app.js
  2. 1
    1
      css/videolayout_default.css
  3. 37
    22
      data_channels.js
  4. 31
    31
      videolayout.js

+ 1
- 1
app.js View File

@@ -562,7 +562,7 @@ $(document).bind('callactive.jingle', function (event, videoelem, sid) {
562 562
 
563 563
         // Update the large video to the last added video only if there's no
564 564
         // current active or focused speaker.
565
-        if (!focusedVideoSrc && !VideoLayout.getActiveSpeakerResourceJid())
565
+        if (!focusedVideoSrc && !VideoLayout.getDominantSpeakerResourceJid())
566 566
             VideoLayout.updateLargeVideo(videoelem.attr('src'), 1);
567 567
 
568 568
         VideoLayout.showFocusIndicator();

+ 1
- 1
css/videolayout_default.css View File

@@ -94,7 +94,7 @@
94 94
     height: 100%;
95 95
 }
96 96
 
97
-.activespeaker {
97
+.dominantspeaker {
98 98
     background: #000 !important;
99 99
 }
100 100
 

+ 37
- 22
data_channels.js View File

@@ -27,38 +27,53 @@ function onDataChannel(event)
27 27
     dataChannel.onmessage = function (event)
28 28
     {
29 29
         var data = event.data;
30
+        // JSON
31
+        var obj;
30 32
 
31
-        console.info("Got Data Channel Message:", data, dataChannel);
32
-
33
-        // Active speaker event
34
-        if (data.indexOf('activeSpeaker') === 0)
33
+        try
35 34
         {
36
-            // Endpoint ID from the Videobridge.
37
-            var resourceJid = data.split(":")[1];
38
-
39
-            console.info(
40
-                "Data channel new active speaker event: " + resourceJid);
41
-            $(document).trigger('activespeakerchanged', [resourceJid]);
35
+            obj = JSON.parse(data);
36
+        }
37
+        catch (e)
38
+        {
39
+            console.error(
40
+                "Failed to parse data channel message as JSON: ",
41
+                data,
42
+                dataChannel);
42 43
         }
43
-        else
44
+        if (('undefined' !== typeof(obj)) && (null !== obj))
44 45
         {
45
-            // JSON
46
-            var obj;
46
+            var colibriClass = obj.colibriClass;
47 47
 
48
-            try
48
+            if ("DominantSpeakerEndpointChangeEvent" === colibriClass)
49 49
             {
50
-                obj = JSON.parse(data);
50
+                // Endpoint ID from the Videobridge.
51
+                var dominantSpeakerEndpoint = obj.dominantSpeakerEndpoint;
52
+
53
+                console.info(
54
+                    "Data channel new dominant speaker event: ",
55
+                    dominantSpeakerEndpoint);
56
+                $(document).trigger(
57
+                    'dominantspeakerchanged',
58
+                    [dominantSpeakerEndpoint]);
51 59
             }
52
-            catch (e)
60
+            else if ("LastNEndpointsChangeEvent" === colibriClass)
53 61
             {
54
-                console.error(
55
-                    "Failed to parse data channel message as JSON: ",
56
-                    data,
57
-                    dataChannel);
62
+                // The new/latest list of last-n endpoint IDs.
63
+                var lastNEndpoints = obj.lastNEndpoints;
64
+                /*
65
+                 * The list of endpoint IDs which are entering the list of
66
+                 * last-n at this time i.e. were not in the old list of last-n
67
+                 * endpoint IDs.
68
+                 */
69
+                var endpointsEnteringLastN = obj.endpointsEnteringLastN;
70
+
71
+                console.debug(
72
+                    "Data channel new last-n event: ",
73
+                    lastNEndpoints);
58 74
             }
59
-            if (('undefined' !== typeof(obj)) && (null !== obj))
75
+            else
60 76
             {
61
-                // TODO Consume the JSON-formatted data channel message.
62 77
                 console.debug("Data channel JSON-formatted message: ", obj);
63 78
             }
64 79
         }

+ 31
- 31
videolayout.js View File

@@ -1,6 +1,6 @@
1 1
 var VideoLayout = (function (my) {
2 2
     var preMuted = false;
3
-    var currentActiveSpeaker = null;
3
+    var currentDominantSpeaker = null;
4 4
 
5 5
     my.changeLocalAudio = function(stream) {
6 6
         connection.jingle.localAudio = stream;
@@ -139,19 +139,19 @@ var VideoLayout = (function (my) {
139 139
 
140 140
                 if (isVisible) {
141 141
                     // Only if the large video is currently visible.
142
-                    // Disable previous active speaker video.
142
+                    // Disable previous dominant speaker video.
143 143
                     var oldJid = getJidFromVideoSrc(oldSrc);
144 144
                     if (oldJid) {
145 145
                         var oldResourceJid = Strophe.getResourceFromJid(oldJid);
146
-                        VideoLayout.enableActiveSpeaker(oldResourceJid, false);
146
+                        VideoLayout.enableDominantSpeaker(oldResourceJid, false);
147 147
                     }
148 148
 
149
-                    // Enable new active speaker in the remote videos section.
149
+                    // Enable new dominant speaker in the remote videos section.
150 150
                     var userJid = getJidFromVideoSrc(newSrc);
151 151
                     if (userJid)
152 152
                     {
153 153
                         var resourceJid = Strophe.getResourceFromJid(userJid);
154
-                        VideoLayout.enableActiveSpeaker(resourceJid, true);
154
+                        VideoLayout.enableDominantSpeaker(resourceJid, true);
155 155
                     }
156 156
 
157 157
                     $(this).fadeIn(300);
@@ -173,15 +173,15 @@ var VideoLayout = (function (my) {
173 173
         if (focusedVideoSrc === videoSrc)
174 174
         {
175 175
             focusedVideoSrc = null;
176
-            var activeSpeakerVideo = null;
177
-            // Enable the currently set active speaker.
178
-            if (currentActiveSpeaker) {
179
-                activeSpeakerVideo
180
-                    = $('#participant_' + currentActiveSpeaker + '>video')
176
+            var dominantSpeakerVideo = null;
177
+            // Enable the currently set dominant speaker.
178
+            if (currentDominantSpeaker) {
179
+                dominantSpeakerVideo
180
+                    = $('#participant_' + currentDominantSpeaker + '>video')
181 181
                         .get(0);
182 182
 
183
-                if (activeSpeakerVideo)
184
-                    VideoLayout.updateLargeVideo(activeSpeakerVideo.src, 1);
183
+                if (dominantSpeakerVideo)
184
+                    VideoLayout.updateLargeVideo(dominantSpeakerVideo.src, 1);
185 185
             }
186 186
 
187 187
             return;
@@ -254,12 +254,12 @@ var VideoLayout = (function (my) {
254 254
         if (isVisible) {
255 255
             $('#largeVideo').css({visibility: 'visible'});
256 256
             $('.watermark').css({visibility: 'visible'});
257
-            VideoLayout.enableActiveSpeaker(resourceJid, true);
257
+            VideoLayout.enableDominantSpeaker(resourceJid, true);
258 258
         }
259 259
         else {
260 260
             $('#largeVideo').css({visibility: 'hidden'});
261 261
             $('.watermark').css({visibility: 'hidden'});
262
-            VideoLayout.enableActiveSpeaker(resourceJid, false);
262
+            VideoLayout.enableDominantSpeaker(resourceJid, false);
263 263
         }
264 264
     };
265 265
 
@@ -582,20 +582,20 @@ var VideoLayout = (function (my) {
582 582
     };
583 583
 
584 584
     /**
585
-     * Enables the active speaker UI.
585
+     * Enables the dominant speaker UI.
586 586
      *
587 587
      * @param resourceJid the jid indicating the video element to
588 588
      * activate/deactivate
589
-     * @param isEnable indicates if the active speaker should be enabled or
589
+     * @param isEnable indicates if the dominant speaker should be enabled or
590 590
      * disabled
591 591
      */
592
-    my.enableActiveSpeaker = function(resourceJid, isEnable) {
592
+    my.enableDominantSpeaker = function(resourceJid, isEnable) {
593 593
         var displayName = resourceJid;
594 594
         var nameSpan = $('#participant_' + resourceJid + '>span.displayname');
595 595
         if (nameSpan.length > 0)
596 596
             displayName = nameSpan.text();
597 597
 
598
-        console.log("UI enable active speaker",
598
+        console.log("UI enable dominant speaker",
599 599
                     displayName,
600 600
                     resourceJid,
601 601
                     isEnable);
@@ -625,16 +625,16 @@ var VideoLayout = (function (my) {
625 625
             if (isEnable) {
626 626
                 VideoLayout.showDisplayName(videoContainerId, true);
627 627
 
628
-                if (!videoSpan.classList.contains("activespeaker"))
629
-                    videoSpan.classList.add("activespeaker");
628
+                if (!videoSpan.classList.contains("dominantspeaker"))
629
+                    videoSpan.classList.add("dominantspeaker");
630 630
 
631 631
                 video.css({visibility: 'hidden'});
632 632
             }
633 633
             else {
634 634
                 VideoLayout.showDisplayName(videoContainerId, false);
635 635
 
636
-                if (videoSpan.classList.contains("activespeaker"))
637
-                    videoSpan.classList.remove("activespeaker");
636
+                if (videoSpan.classList.contains("dominantspeaker"))
637
+                    videoSpan.classList.remove("dominantspeaker");
638 638
 
639 639
                 video.css({visibility: 'visible'});
640 640
             }
@@ -805,10 +805,10 @@ var VideoLayout = (function (my) {
805 805
     };
806 806
 
807 807
     /**
808
-     * Returns the current active speaker resource jid.
808
+     * Returns the current dominant speaker resource jid.
809 809
      */
810
-    my.getActiveSpeakerResourceJid = function () {
811
-        return currentActiveSpeaker;
810
+    my.getDominantSpeakerResourceJid = function () {
811
+        return currentDominantSpeaker;
812 812
     };
813 813
 
814 814
     /**
@@ -926,21 +926,21 @@ var VideoLayout = (function (my) {
926 926
     });
927 927
 
928 928
     /**
929
-     * On active speaker changed event.
929
+     * On dominant speaker changed event.
930 930
      */
931
-    $(document).bind('activespeakerchanged', function (event, resourceJid) {
931
+    $(document).bind('dominantspeakerchanged', function (event, resourceJid) {
932 932
         // We ignore local user events.
933 933
         if (resourceJid
934 934
                 === Strophe.getResourceFromJid(connection.emuc.myroomjid))
935 935
             return;
936 936
 
937
-        // Obtain container for new active speaker.
937
+        // Obtain container for new dominant speaker.
938 938
         var container  = document.getElementById(
939 939
                 'participant_' + resourceJid);
940 940
 
941
-        // Update the current active speaker.
942
-        if (resourceJid !== currentActiveSpeaker)
943
-            currentActiveSpeaker = resourceJid;
941
+        // Update the current dominant speaker.
942
+        if (resourceJid !== currentDominantSpeaker)
943
+            currentDominantSpeaker = resourceJid;
944 944
         else
945 945
             return;
946 946
 

Loading…
Cancel
Save