From 7dc8102dee0758f5a69e9b8f44d33bb07068791b Mon Sep 17 00:00:00 2001 From: paweldomas Date: Fri, 28 Nov 2014 16:17:53 +0100 Subject: [PATCH] Replaces 'focus' occurrences with moderator for handling privileged functionalities. --- app.js | 10 +++-- etherpad.js | 6 ++- index.html | 1 + moderator.js | 53 +++++++++++++++++++++++++ recording.js | 5 ++- toolbar.js | 2 +- toolbar_toggler.js | 4 +- videolayout.js | 97 ++++++++++++++++++++++++++-------------------- 8 files changed, 126 insertions(+), 52 deletions(-) create mode 100644 moderator.js diff --git a/app.js b/app.js index 45c857248..9c9248c5f 100644 --- a/app.js +++ b/app.js @@ -728,8 +728,6 @@ $(document).bind('entered.muc', function (event, jid, info, pres) { 'connected', 'connected'); - console.log('is focus? ' + (focus ? 'true' : 'false')); - if (Strophe.getResourceFromJid(jid).indexOf('focus') != -1) { focusJid = jid; @@ -1249,6 +1247,8 @@ $(document).ready(function () { } }); + Moderator.init(); + // Set the defaults for prompt dialogs. jQuery.prompt.setDefaults({persistent: false}); @@ -1442,11 +1442,13 @@ function updateRoomUrl(newRoomUrl) { * Warning to the user that the conference window is about to be closed. */ function closePageWarning() { + /* + FIXME: do we need a warning when the focus is a server-side one now ? if (focus !== null) return "You are the owner of this conference call and" + " you are about to end it."; - else - return "You are about to leave this conversation."; + else*/ + return "You are about to leave this conversation."; } /** diff --git a/etherpad.js b/etherpad.js index f7a0b3ec2..67fe1ec0a 100644 --- a/etherpad.js +++ b/etherpad.js @@ -1,4 +1,5 @@ -/* global $, config, Prezi, Util, connection, setLargeVideoVisible, dockToolbar */ +/* global $, config, connection, dockToolbar, Moderator, Prezi, + setLargeVideoVisible, ToolbarToggler, Util, VideoLayout */ var Etherpad = (function (my) { var etherpadName = null; var etherpadIFrame = null; @@ -161,7 +162,7 @@ var Etherpad = (function (my) { */ $(document).bind('etherpadadded.muc', function (event, jid, etherpadName) { console.log("Etherpad added", etherpadName); - if (config.etherpad_base && !focus) { + if (config.etherpad_base && !Moderator.isModerator()) { Etherpad.init(etherpadName); } }); @@ -169,6 +170,7 @@ var Etherpad = (function (my) { /** * On focus changed event. */ + // FIXME: there is no such event as 'focusechanged.muc' $(document).bind('focusechanged.muc', function (event, focus) { console.log("Focus changed"); if (config.etherpad_base) diff --git a/index.html b/index.html index 67ce73050..cb8b901cc 100644 --- a/index.html +++ b/index.html @@ -55,6 +55,7 @@ + diff --git a/moderator.js b/moderator.js new file mode 100644 index 000000000..7f5811932 --- /dev/null +++ b/moderator.js @@ -0,0 +1,53 @@ +/* global $, config, connection, Etherpad, Toolbar, VideoLayout */ +/** + * Contains logic responsible for enabling/disabling functionality available + * only to moderator users. + */ +var Moderator = (function (my) { + + my.isModerator = function () { + return connection.emuc.isModerator(); + }; + + my.onModeratorStatusChanged = function (isModerator) { + + Toolbar.showSipCallButton(isModerator); + Toolbar.showRecordingButton( + isModerator); //&& + // FIXME: + // Recording visible if + // there are at least 2(+ 1 focus) participants + //Object.keys(connection.emuc.members).length >= 3); + + if (isModerator && config.etherpad_base) { + Etherpad.init(); + } + + $(document).trigger('local.role.moderator', [isModerator]); + }; + + my.init = function () { + $(document).bind( + 'role.changed.muc', + function (event, jid, info, pres) { + console.info( + "Role changed for " + jid + ", new role: " + info.role); + VideoLayout.showModeratorIndicator(); + } + ); + + $(document).bind( + 'local.role.changed.muc', + function (event, jid, info, pres) { + console.info("My role changed, new role: " + info.role); + VideoLayout.showModeratorIndicator(); + Moderator.onModeratorStatusChanged(Moderator.isModerator()); + } + ); + }; + + return my; +}(Moderator || {})); + + + diff --git a/recording.js b/recording.js index 92c3f0771..fffcfee92 100644 --- a/recording.js +++ b/recording.js @@ -1,4 +1,5 @@ -/* global $, $iq, config, connection, focusJid, messageHandler, Toolbar, Util */ +/* global $, $iq, config, connection, focusJid, messageHandler, Moderator, + Toolbar, Util */ var Recording = (function (my) { var status = false; var recordingToken = null; @@ -36,7 +37,7 @@ var Recording = (function (my) { }; my.toggleRecording = function () { - if (!connection.emuc.isModerator()) { + if (!Moderator.isModerator()) { console.log( 'non-focus, or conference not yet organized:' + ' not enabling recording'); diff --git a/toolbar.js b/toolbar.js index 50701a683..8ccf727a4 100644 --- a/toolbar.js +++ b/toolbar.js @@ -17,7 +17,7 @@ var Toolbar = (function (my) { */ my.openLockDialog = function () { // Only the focus is able to set a shared key. - if (focus === null) { + if (Moderator.isModerator()) { if (sharedKey) { messageHandler.openMessageDialog(null, "This conversation is currently protected by" + diff --git a/toolbar_toggler.js b/toolbar_toggler.js index bba32cbb7..29b5904cf 100644 --- a/toolbar_toggler.js +++ b/toolbar_toggler.js @@ -1,4 +1,4 @@ -/* global $, interfaceConfig, showDesktopSharingButton */ +/* global $, interfaceConfig, Moderator, showDesktopSharingButton */ var ToolbarToggler = (function (my) { var toolbarTimeoutObject, toolbarTimeout = interfaceConfig.INITIAL_TOOLBAR_TIMEOUT; @@ -25,7 +25,7 @@ var ToolbarToggler = (function (my) { toolbarTimeout = interfaceConfig.TOOLBAR_TIMEOUT; } - if (focus !== null) + if (Moderator.isModerator()) { // TODO: Enable settings functionality. // Need to uncomment the settings button in index.html. diff --git a/videolayout.js b/videolayout.js index 2d1ae1989..bd044a6ec 100644 --- a/videolayout.js +++ b/videolayout.js @@ -380,11 +380,12 @@ var VideoLayout = (function (my) { var videoSpanId = 'participant_' + resourceJid; if ($('#' + videoSpanId).length > 0) { - // If there's been a focus change, make sure we add focus related - // interface!! - if (focus && $('#remote_popupmenu_' + resourceJid).length <= 0) - addRemoteVideoMenu( peerJid, - document.getElementById(videoSpanId)); + // If there's been a moderator change, make sure we add moderator + // related interface!! + if (Moderator.isModerator() && + $('#remote_popupmenu_' + resourceJid).length <= 0) + addRemoteVideoMenu(peerJid, + document.getElementById(videoSpanId)); } else { var container @@ -419,7 +420,7 @@ var VideoLayout = (function (my) { // If the peerJid is null then this video span couldn't be directly // associated with a participant (this could happen in the case of prezi). - if (focus && peerJid != null) + if (Moderator.isModerator() && peerJid !== null) addRemoteVideoMenu(peerJid, container); remotes.appendChild(container); @@ -772,42 +773,47 @@ var VideoLayout = (function (my) { }; /** - * Shows a visual indicator for the focus of the conference. - * Currently if we're not the owner of the conference we obtain the focus - * from the connection.jingle.sessions. + * Shows a visual indicator for the moderator of the conference. */ - my.showFocusIndicator = function() { - if (focus !== null) { + my.showModeratorIndicator = function () { + if (Moderator.isModerator()) { var indicatorSpan = $('#localVideoContainer .focusindicator'); if (indicatorSpan.children().length === 0) { - createFocusIndicatorElement(indicatorSpan[0]); + createModeratorIndicatorElement(indicatorSpan[0]); } - } - else if (Object.keys(connection.jingle.sessions).length > 0) { - // If we're only a participant the focus will be the only session we have. - var session - = connection.jingle.sessions - [Object.keys(connection.jingle.sessions)[0]]; - var focusId - = 'participant_' + Strophe.getResourceFromJid(session.peerjid); + } else { + Object.keys(connection.emuc.members).forEach(function (jid) { + var member = connection.emuc.members[jid]; + if (member.role === 'moderator') { + var moderatorId + = 'participant_' + Strophe.getResourceFromJid(jid); - var focusContainer = document.getElementById(focusId); - if (!focusContainer) { - console.error("No focus container!"); - return; - } - var indicatorSpan = $('#' + focusId + ' .focusindicator'); + var moderatorContainer + = document.getElementById(moderatorId); - if (!indicatorSpan || indicatorSpan.length === 0) { - indicatorSpan = document.createElement('span'); - indicatorSpan.className = 'focusindicator'; + if (Strophe.getResourceFromJid(jid) === 'focus') { + // Skip server side focus + return; + } + if (!moderatorContainer) { + console.error("No moderator container for " + jid); + return; + } + var indicatorSpan + = $('#' + moderatorId + ' .focusindicator'); - focusContainer.appendChild(indicatorSpan); + if (!indicatorSpan || indicatorSpan.length === 0) { + indicatorSpan = document.createElement('span'); + indicatorSpan.className = 'focusindicator'; - createFocusIndicatorElement(indicatorSpan); - } + moderatorContainer.appendChild(indicatorSpan); + + createModeratorIndicatorElement(indicatorSpan); + } + } + }); } }; @@ -1120,15 +1126,15 @@ var VideoLayout = (function (my) { } /** - * Creates the element indicating the focus of the conference. + * Creates the element indicating the moderator(owner) of the conference. * - * @param parentElement the parent element where the focus indicator will + * @param parentElement the parent element where the owner indicator will * be added */ - function createFocusIndicatorElement(parentElement) { - var focusIndicator = document.createElement('i'); - focusIndicator.className = 'fa fa-star'; - parentElement.appendChild(focusIndicator); + function createModeratorIndicatorElement(parentElement) { + var moderatorIndicator = document.createElement('i'); + moderatorIndicator.className = 'fa fa-star'; + parentElement.appendChild(moderatorIndicator); Util.setTooltip(parentElement, "The owner of
this conference", @@ -1328,19 +1334,28 @@ var VideoLayout = (function (my) { * On audio muted event. */ $(document).bind('audiomuted.muc', function (event, jid, isMuted) { + /* + // FIXME: but focus can not mute in this case ? - check if (jid === connection.emuc.myroomjid) { + // The local mute indicator is controlled locally return; + }*/ + var videoSpanId = null; + if (jid === connection.emuc.myroomjid) { + videoSpanId = 'localVideoContainer'; + } else { + VideoLayout.ensurePeerContainerExists(jid); + videoSpanId = 'participant_' + Strophe.getResourceFromJid(jid); } VideoLayout.ensurePeerContainerExists(jid); - if (focus) { + if (Moderator.isModerator()) { mutedAudios[jid] = isMuted; VideoLayout.updateRemoteVideoMenu(jid, isMuted); } - var videoSpanId = 'participant_' + Strophe.getResourceFromJid(jid); if (videoSpanId) VideoLayout.showAudioIndicator(videoSpanId, isMuted); }); @@ -1614,7 +1629,7 @@ var VideoLayout = (function (my) { VideoLayout.updateLargeVideo(videoelem.attr('src'), 1); } - VideoLayout.showFocusIndicator(); + VideoLayout.showModeratorIndicator(); } });