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

This commit is contained in:
paweldomas 2014-11-28 16:17:53 +01:00
parent ed2d7e4282
commit 7dc8102dee
8 changed files with 126 additions and 52 deletions

10
app.js
View File

@ -728,8 +728,6 @@ $(document).bind('entered.muc', function (event, jid, info, pres) {
'connected', 'connected',
'connected'); 'connected');
console.log('is focus? ' + (focus ? 'true' : 'false'));
if (Strophe.getResourceFromJid(jid).indexOf('focus') != -1) if (Strophe.getResourceFromJid(jid).indexOf('focus') != -1)
{ {
focusJid = jid; focusJid = jid;
@ -1249,6 +1247,8 @@ $(document).ready(function () {
} }
}); });
Moderator.init();
// Set the defaults for prompt dialogs. // Set the defaults for prompt dialogs.
jQuery.prompt.setDefaults({persistent: false}); 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. * Warning to the user that the conference window is about to be closed.
*/ */
function closePageWarning() { function closePageWarning() {
/*
FIXME: do we need a warning when the focus is a server-side one now ?
if (focus !== null) if (focus !== null)
return "You are the owner of this conference call and" return "You are the owner of this conference call and"
+ " you are about to end it."; + " you are about to end it.";
else else*/
return "You are about to leave this conversation."; return "You are about to leave this conversation.";
} }
/** /**

View File

@ -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 Etherpad = (function (my) {
var etherpadName = null; var etherpadName = null;
var etherpadIFrame = null; var etherpadIFrame = null;
@ -161,7 +162,7 @@ var Etherpad = (function (my) {
*/ */
$(document).bind('etherpadadded.muc', function (event, jid, etherpadName) { $(document).bind('etherpadadded.muc', function (event, jid, etherpadName) {
console.log("Etherpad added", etherpadName); console.log("Etherpad added", etherpadName);
if (config.etherpad_base && !focus) { if (config.etherpad_base && !Moderator.isModerator()) {
Etherpad.init(etherpadName); Etherpad.init(etherpadName);
} }
}); });
@ -169,6 +170,7 @@ var Etherpad = (function (my) {
/** /**
* On focus changed event. * On focus changed event.
*/ */
// FIXME: there is no such event as 'focusechanged.muc'
$(document).bind('focusechanged.muc', function (event, focus) { $(document).bind('focusechanged.muc', function (event, focus) {
console.log("Focus changed"); console.log("Focus changed");
if (config.etherpad_base) if (config.etherpad_base)

View File

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

53
moderator.js Normal file
View File

@ -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 || {}));

View File

@ -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 Recording = (function (my) {
var status = false; var status = false;
var recordingToken = null; var recordingToken = null;
@ -36,7 +37,7 @@ var Recording = (function (my) {
}; };
my.toggleRecording = function () { my.toggleRecording = function () {
if (!connection.emuc.isModerator()) { if (!Moderator.isModerator()) {
console.log( console.log(
'non-focus, or conference not yet organized:' + 'non-focus, or conference not yet organized:' +
' not enabling recording'); ' not enabling recording');

View File

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

View File

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

View File

@ -380,11 +380,12 @@ var VideoLayout = (function (my) {
var videoSpanId = 'participant_' + resourceJid; var videoSpanId = 'participant_' + resourceJid;
if ($('#' + videoSpanId).length > 0) { if ($('#' + videoSpanId).length > 0) {
// If there's been a focus change, make sure we add focus related // If there's been a moderator change, make sure we add moderator
// interface!! // related interface!!
if (focus && $('#remote_popupmenu_' + resourceJid).length <= 0) if (Moderator.isModerator() &&
addRemoteVideoMenu( peerJid, $('#remote_popupmenu_' + resourceJid).length <= 0)
document.getElementById(videoSpanId)); addRemoteVideoMenu(peerJid,
document.getElementById(videoSpanId));
} }
else { else {
var container var container
@ -419,7 +420,7 @@ var VideoLayout = (function (my) {
// If the peerJid is null then this video span couldn't be directly // 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). // associated with a participant (this could happen in the case of prezi).
if (focus && peerJid != null) if (Moderator.isModerator() && peerJid !== null)
addRemoteVideoMenu(peerJid, container); addRemoteVideoMenu(peerJid, container);
remotes.appendChild(container); remotes.appendChild(container);
@ -772,42 +773,47 @@ var VideoLayout = (function (my) {
}; };
/** /**
* Shows a visual indicator for the focus of the conference. * Shows a visual indicator for the moderator of the conference.
* Currently if we're not the owner of the conference we obtain the focus
* from the connection.jingle.sessions.
*/ */
my.showFocusIndicator = function() { my.showModeratorIndicator = function () {
if (focus !== null) { if (Moderator.isModerator()) {
var indicatorSpan = $('#localVideoContainer .focusindicator'); var indicatorSpan = $('#localVideoContainer .focusindicator');
if (indicatorSpan.children().length === 0) if (indicatorSpan.children().length === 0)
{ {
createFocusIndicatorElement(indicatorSpan[0]); createModeratorIndicatorElement(indicatorSpan[0]);
} }
} } else {
else if (Object.keys(connection.jingle.sessions).length > 0) { Object.keys(connection.emuc.members).forEach(function (jid) {
// If we're only a participant the focus will be the only session we have. var member = connection.emuc.members[jid];
var session if (member.role === 'moderator') {
= connection.jingle.sessions var moderatorId
[Object.keys(connection.jingle.sessions)[0]]; = 'participant_' + Strophe.getResourceFromJid(jid);
var focusId
= 'participant_' + Strophe.getResourceFromJid(session.peerjid);
var focusContainer = document.getElementById(focusId); var moderatorContainer
if (!focusContainer) { = document.getElementById(moderatorId);
console.error("No focus container!");
return;
}
var indicatorSpan = $('#' + focusId + ' .focusindicator');
if (!indicatorSpan || indicatorSpan.length === 0) { if (Strophe.getResourceFromJid(jid) === 'focus') {
indicatorSpan = document.createElement('span'); // Skip server side focus
indicatorSpan.className = 'focusindicator'; 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 * be added
*/ */
function createFocusIndicatorElement(parentElement) { function createModeratorIndicatorElement(parentElement) {
var focusIndicator = document.createElement('i'); var moderatorIndicator = document.createElement('i');
focusIndicator.className = 'fa fa-star'; moderatorIndicator.className = 'fa fa-star';
parentElement.appendChild(focusIndicator); parentElement.appendChild(moderatorIndicator);
Util.setTooltip(parentElement, Util.setTooltip(parentElement,
"The owner of<br/>this conference", "The owner of<br/>this conference",
@ -1328,19 +1334,28 @@ var VideoLayout = (function (my) {
* On audio muted event. * On audio muted event.
*/ */
$(document).bind('audiomuted.muc', function (event, jid, isMuted) { $(document).bind('audiomuted.muc', function (event, jid, isMuted) {
/*
// FIXME: but focus can not mute in this case ? - check
if (jid === connection.emuc.myroomjid) { if (jid === connection.emuc.myroomjid) {
// The local mute indicator is controlled locally // The local mute indicator is controlled locally
return; return;
}*/
var videoSpanId = null;
if (jid === connection.emuc.myroomjid) {
videoSpanId = 'localVideoContainer';
} else {
VideoLayout.ensurePeerContainerExists(jid);
videoSpanId = 'participant_' + Strophe.getResourceFromJid(jid);
} }
VideoLayout.ensurePeerContainerExists(jid); VideoLayout.ensurePeerContainerExists(jid);
if (focus) { if (Moderator.isModerator()) {
mutedAudios[jid] = isMuted; mutedAudios[jid] = isMuted;
VideoLayout.updateRemoteVideoMenu(jid, isMuted); VideoLayout.updateRemoteVideoMenu(jid, isMuted);
} }
var videoSpanId = 'participant_' + Strophe.getResourceFromJid(jid);
if (videoSpanId) if (videoSpanId)
VideoLayout.showAudioIndicator(videoSpanId, isMuted); VideoLayout.showAudioIndicator(videoSpanId, isMuted);
}); });
@ -1614,7 +1629,7 @@ var VideoLayout = (function (my) {
VideoLayout.updateLargeVideo(videoelem.attr('src'), 1); VideoLayout.updateLargeVideo(videoelem.attr('src'), 1);
} }
VideoLayout.showFocusIndicator(); VideoLayout.showModeratorIndicator();
} }
}); });