Browse Source

Replaces 'focus' occurrences with moderator for handling privileged functionalities.

j8
paweldomas 11 years ago
parent
commit
7dc8102dee
8 changed files with 127 additions and 53 deletions
  1. 6
    4
      app.js
  2. 4
    2
      etherpad.js
  3. 1
    0
      index.html
  4. 53
    0
      moderator.js
  5. 3
    2
      recording.js
  6. 1
    1
      toolbar.js
  7. 2
    2
      toolbar_toggler.js
  8. 57
    42
      videolayout.js

+ 6
- 4
app.js View File

@@ -728,8 +728,6 @@ $(document).bind('entered.muc', function (event, jid, info, pres) {
728 728
         'connected',
729 729
         'connected');
730 730
 
731
-    console.log('is focus? ' + (focus ? 'true' : 'false'));
732
-
733 731
     if (Strophe.getResourceFromJid(jid).indexOf('focus') != -1)
734 732
     {
735 733
         focusJid = jid;
@@ -1249,6 +1247,8 @@ $(document).ready(function () {
1249 1247
         }
1250 1248
     });
1251 1249
 
1250
+    Moderator.init();
1251
+
1252 1252
     // Set the defaults for prompt dialogs.
1253 1253
     jQuery.prompt.setDefaults({persistent: false});
1254 1254
 
@@ -1442,11 +1442,13 @@ function updateRoomUrl(newRoomUrl) {
1442 1442
  * Warning to the user that the conference window is about to be closed.
1443 1443
  */
1444 1444
 function closePageWarning() {
1445
+    /*
1446
+    FIXME: do we need a warning when the focus is a server-side one now ?
1445 1447
     if (focus !== null)
1446 1448
         return "You are the owner of this conference call and"
1447 1449
                 + " you are about to end it.";
1448
-    else
1449
-        return "You are about to leave this conversation.";
1450
+    else*/
1451
+    return "You are about to leave this conversation.";
1450 1452
 }
1451 1453
 
1452 1454
 /**

+ 4
- 2
etherpad.js View File

@@ -1,4 +1,5 @@
1
-/* global $, config, Prezi, Util, connection, setLargeVideoVisible, dockToolbar */
1
+/* global $, config, connection, dockToolbar, Moderator, Prezi,
2
+   setLargeVideoVisible, ToolbarToggler, Util, VideoLayout */
2 3
 var Etherpad = (function (my) {
3 4
     var etherpadName = null;
4 5
     var etherpadIFrame = null;
@@ -161,7 +162,7 @@ var Etherpad = (function (my) {
161 162
      */
162 163
     $(document).bind('etherpadadded.muc', function (event, jid, etherpadName) {
163 164
         console.log("Etherpad added", etherpadName);
164
-        if (config.etherpad_base && !focus) {
165
+        if (config.etherpad_base && !Moderator.isModerator()) {
165 166
             Etherpad.init(etherpadName);
166 167
         }
167 168
     });
@@ -169,6 +170,7 @@ var Etherpad = (function (my) {
169 170
     /**
170 171
      * On focus changed event.
171 172
      */
173
+    // FIXME: there is no such event as 'focusechanged.muc'
172 174
     $(document).bind('focusechanged.muc', function (event, focus) {
173 175
         console.log("Focus changed");
174 176
         if (config.etherpad_base)

+ 1
- 0
index.html View File

@@ -55,6 +55,7 @@
55 55
     <script src="audio_levels.js?v=2"></script><!-- audio levels plugin -->
56 56
     <script src="media_stream.js?v=1"></script><!-- media stream -->
57 57
     <script src="bottom_toolbar.js?v=5"></script><!-- media stream -->
58
+    <script src="moderator.js?v=1"></script><!-- media stream -->
58 59
     <script src="roomname_generator.js?v=1"></script><!-- generator for random room names -->
59 60
     <script src="keyboard_shortcut.js?v=3"></script>
60 61
     <script src="recording.js?v=1"></script>

+ 53
- 0
moderator.js View File

@@ -0,0 +1,53 @@
1
+/* global $, config, connection, Etherpad, Toolbar, VideoLayout */
2
+/**
3
+ * Contains logic responsible for enabling/disabling functionality available
4
+ * only to moderator users.
5
+ */
6
+var Moderator = (function (my) {
7
+
8
+    my.isModerator = function () {
9
+        return connection.emuc.isModerator();
10
+    };
11
+
12
+    my.onModeratorStatusChanged = function (isModerator) {
13
+
14
+        Toolbar.showSipCallButton(isModerator);
15
+        Toolbar.showRecordingButton(
16
+                isModerator); //&&
17
+                // FIXME:
18
+                // Recording visible if
19
+                // there are at least 2(+ 1 focus) participants
20
+                //Object.keys(connection.emuc.members).length >= 3);
21
+
22
+        if (isModerator && config.etherpad_base) {
23
+            Etherpad.init();
24
+        }
25
+
26
+        $(document).trigger('local.role.moderator', [isModerator]);
27
+    };
28
+
29
+    my.init = function () {
30
+        $(document).bind(
31
+            'role.changed.muc',
32
+            function (event, jid, info, pres) {
33
+                console.info(
34
+                    "Role changed for " + jid + ", new role: " + info.role);
35
+                VideoLayout.showModeratorIndicator();
36
+            }
37
+        );
38
+
39
+        $(document).bind(
40
+            'local.role.changed.muc',
41
+            function (event, jid, info, pres) {
42
+                console.info("My role changed, new role: " + info.role);
43
+                VideoLayout.showModeratorIndicator();
44
+                Moderator.onModeratorStatusChanged(Moderator.isModerator());
45
+            }
46
+        );
47
+    };
48
+
49
+    return my;
50
+}(Moderator || {}));
51
+
52
+
53
+

+ 3
- 2
recording.js View File

@@ -1,4 +1,5 @@
1
-/* global $, $iq, config, connection, focusJid, messageHandler, Toolbar, Util */
1
+/* global $, $iq, config, connection, focusJid, messageHandler, Moderator,
2
+   Toolbar, Util */
2 3
 var Recording = (function (my) {
3 4
     var status = false;
4 5
     var recordingToken = null;
@@ -36,7 +37,7 @@ var Recording = (function (my) {
36 37
     };
37 38
 
38 39
     my.toggleRecording = function () {
39
-        if (!connection.emuc.isModerator()) {
40
+        if (!Moderator.isModerator()) {
40 41
             console.log(
41 42
                 'non-focus, or conference not yet organized:' +
42 43
                 ' not enabling recording');

+ 1
- 1
toolbar.js View File

@@ -17,7 +17,7 @@ var Toolbar = (function (my) {
17 17
      */
18 18
     my.openLockDialog = function () {
19 19
         // Only the focus is able to set a shared key.
20
-        if (focus === null) {
20
+        if (Moderator.isModerator()) {
21 21
             if (sharedKey) {
22 22
                 messageHandler.openMessageDialog(null,
23 23
                         "This conversation is currently protected by" +

+ 2
- 2
toolbar_toggler.js View File

@@ -1,4 +1,4 @@
1
-/* global $, interfaceConfig, showDesktopSharingButton */
1
+/* global $, interfaceConfig, Moderator, showDesktopSharingButton */
2 2
 var ToolbarToggler = (function (my) {
3 3
     var toolbarTimeoutObject,
4 4
         toolbarTimeout = interfaceConfig.INITIAL_TOOLBAR_TIMEOUT;
@@ -25,7 +25,7 @@ var ToolbarToggler = (function (my) {
25 25
             toolbarTimeout = interfaceConfig.TOOLBAR_TIMEOUT;
26 26
         }
27 27
 
28
-        if (focus !== null)
28
+        if (Moderator.isModerator())
29 29
         {
30 30
 //            TODO: Enable settings functionality.
31 31
 //                  Need to uncomment the settings button in index.html.

+ 57
- 42
videolayout.js View File

@@ -380,11 +380,12 @@ var VideoLayout = (function (my) {
380 380
         var videoSpanId = 'participant_' + resourceJid;
381 381
 
382 382
         if ($('#' + videoSpanId).length > 0) {
383
-            // If there's been a focus change, make sure we add focus related
384
-            // interface!!
385
-            if (focus && $('#remote_popupmenu_' + resourceJid).length <= 0)
386
-                addRemoteVideoMenu( peerJid,
387
-                                    document.getElementById(videoSpanId));
383
+            // If there's been a moderator change, make sure we add moderator
384
+            // related interface!!
385
+            if (Moderator.isModerator() &&
386
+                $('#remote_popupmenu_' + resourceJid).length <= 0)
387
+                addRemoteVideoMenu(peerJid,
388
+                                   document.getElementById(videoSpanId));
388 389
         }
389 390
         else {
390 391
             var container
@@ -419,7 +420,7 @@ var VideoLayout = (function (my) {
419 420
 
420 421
         // If the peerJid is null then this video span couldn't be directly
421 422
         // associated with a participant (this could happen in the case of prezi).
422
-        if (focus && peerJid != null)
423
+        if (Moderator.isModerator() && peerJid !== null)
423 424
             addRemoteVideoMenu(peerJid, container);
424 425
 
425 426
         remotes.appendChild(container);
@@ -772,42 +773,47 @@ var VideoLayout = (function (my) {
772 773
     };
773 774
 
774 775
     /**
775
-     * Shows a visual indicator for the focus of the conference.
776
-     * Currently if we're not the owner of the conference we obtain the focus
777
-     * from the connection.jingle.sessions.
776
+     * Shows a visual indicator for the moderator of the conference.
778 777
      */
779
-    my.showFocusIndicator = function() {
780
-        if (focus !== null) {
778
+    my.showModeratorIndicator = function () {
779
+        if (Moderator.isModerator()) {
781 780
             var indicatorSpan = $('#localVideoContainer .focusindicator');
782 781
 
783 782
             if (indicatorSpan.children().length === 0)
784 783
             {
785
-                createFocusIndicatorElement(indicatorSpan[0]);
784
+                createModeratorIndicatorElement(indicatorSpan[0]);
786 785
             }
787
-        }
788
-        else if (Object.keys(connection.jingle.sessions).length > 0) {
789
-            // If we're only a participant the focus will be the only session we have.
790
-            var session
791
-                = connection.jingle.sessions
792
-                    [Object.keys(connection.jingle.sessions)[0]];
793
-            var focusId
794
-                = 'participant_' + Strophe.getResourceFromJid(session.peerjid);
795
-
796
-            var focusContainer = document.getElementById(focusId);
797
-            if (!focusContainer) {
798
-                console.error("No focus container!");
799
-                return;
800
-            }
801
-            var indicatorSpan = $('#' + focusId + ' .focusindicator');
786
+        } else {
787
+            Object.keys(connection.emuc.members).forEach(function (jid) {
788
+                var member = connection.emuc.members[jid];
789
+                if (member.role === 'moderator') {
790
+                    var moderatorId
791
+                        = 'participant_' + Strophe.getResourceFromJid(jid);
792
+
793
+                    var moderatorContainer
794
+                        = document.getElementById(moderatorId);
795
+
796
+                    if (Strophe.getResourceFromJid(jid) === 'focus') {
797
+                        // Skip server side focus
798
+                        return;
799
+                    }
800
+                    if (!moderatorContainer) {
801
+                        console.error("No moderator container for " + jid);
802
+                        return;
803
+                    }
804
+                    var indicatorSpan
805
+                        = $('#' + moderatorId + ' .focusindicator');
802 806
 
803
-            if (!indicatorSpan || indicatorSpan.length === 0) {
804
-                indicatorSpan = document.createElement('span');
805
-                indicatorSpan.className = 'focusindicator';
807
+                    if (!indicatorSpan || indicatorSpan.length === 0) {
808
+                        indicatorSpan = document.createElement('span');
809
+                        indicatorSpan.className = 'focusindicator';
806 810
 
807
-                focusContainer.appendChild(indicatorSpan);
811
+                        moderatorContainer.appendChild(indicatorSpan);
808 812
 
809
-                createFocusIndicatorElement(indicatorSpan);
810
-            }
813
+                        createModeratorIndicatorElement(indicatorSpan);
814
+                    }
815
+                }
816
+            });
811 817
         }
812 818
     };
813 819
 
@@ -1120,15 +1126,15 @@ var VideoLayout = (function (my) {
1120 1126
     }
1121 1127
 
1122 1128
     /**
1123
-     * Creates the element indicating the focus of the conference.
1129
+     * Creates the element indicating the moderator(owner) of the conference.
1124 1130
      *
1125
-     * @param parentElement the parent element where the focus indicator will
1131
+     * @param parentElement the parent element where the owner indicator will
1126 1132
      * be added
1127 1133
      */
1128
-    function createFocusIndicatorElement(parentElement) {
1129
-        var focusIndicator = document.createElement('i');
1130
-        focusIndicator.className = 'fa fa-star';
1131
-        parentElement.appendChild(focusIndicator);
1134
+    function createModeratorIndicatorElement(parentElement) {
1135
+        var moderatorIndicator = document.createElement('i');
1136
+        moderatorIndicator.className = 'fa fa-star';
1137
+        parentElement.appendChild(moderatorIndicator);
1132 1138
 
1133 1139
         Util.setTooltip(parentElement,
1134 1140
                 "The owner of<br/>this conference",
@@ -1328,19 +1334,28 @@ var VideoLayout = (function (my) {
1328 1334
      * On audio muted event.
1329 1335
      */
1330 1336
     $(document).bind('audiomuted.muc', function (event, jid, isMuted) {
1337
+        /*
1338
+         // FIXME: but focus can not mute in this case ? - check
1331 1339
         if (jid === connection.emuc.myroomjid) {
1340
+
1332 1341
             // The local mute indicator is controlled locally
1333 1342
             return;
1343
+        }*/
1344
+        var videoSpanId = null;
1345
+        if (jid === connection.emuc.myroomjid) {
1346
+            videoSpanId = 'localVideoContainer';
1347
+        } else {
1348
+            VideoLayout.ensurePeerContainerExists(jid);
1349
+            videoSpanId = 'participant_' + Strophe.getResourceFromJid(jid);
1334 1350
         }
1335 1351
 
1336 1352
         VideoLayout.ensurePeerContainerExists(jid);
1337 1353
 
1338
-        if (focus) {
1354
+        if (Moderator.isModerator()) {
1339 1355
             mutedAudios[jid] = isMuted;
1340 1356
             VideoLayout.updateRemoteVideoMenu(jid, isMuted);
1341 1357
         }
1342 1358
 
1343
-        var videoSpanId = 'participant_' + Strophe.getResourceFromJid(jid);
1344 1359
         if (videoSpanId)
1345 1360
             VideoLayout.showAudioIndicator(videoSpanId, isMuted);
1346 1361
     });
@@ -1614,7 +1629,7 @@ var VideoLayout = (function (my) {
1614 1629
                 VideoLayout.updateLargeVideo(videoelem.attr('src'), 1);
1615 1630
             }
1616 1631
 
1617
-            VideoLayout.showFocusIndicator();
1632
+            VideoLayout.showModeratorIndicator();
1618 1633
         }
1619 1634
     });
1620 1635
 

Loading…
Cancel
Save