2014-12-05 15:58:11 +00:00
|
|
|
/* global $, $iq, config, connection, Etherpad, hangUp, messageHandler,
|
2014-12-11 18:14:46 +00:00
|
|
|
roomName, sessionTerminated, Strophe, Toolbar, Util, VideoLayout */
|
2014-11-28 15:17:53 +00:00
|
|
|
/**
|
|
|
|
* Contains logic responsible for enabling/disabling functionality available
|
|
|
|
* only to moderator users.
|
|
|
|
*/
|
|
|
|
var Moderator = (function (my) {
|
|
|
|
|
2014-12-05 15:43:04 +00:00
|
|
|
var focusUserJid;
|
2014-11-28 15:18:12 +00:00
|
|
|
var getNextTimeout = Util.createExpBackoffTimer(1000);
|
2014-11-28 15:18:31 +00:00
|
|
|
var getNextErrorTimeout = Util.createExpBackoffTimer(1000);
|
2014-12-16 13:54:13 +00:00
|
|
|
// External authentication stuff
|
|
|
|
var externalAuthEnabled = false;
|
2014-11-28 15:18:12 +00:00
|
|
|
|
2014-11-28 15:17:53 +00:00
|
|
|
my.isModerator = function () {
|
|
|
|
return connection.emuc.isModerator();
|
|
|
|
};
|
|
|
|
|
2014-12-16 13:54:13 +00:00
|
|
|
my.isPeerModerator = function (peerJid) {
|
|
|
|
return connection.emuc.getMemberRole(peerJid) === 'moderator';
|
|
|
|
};
|
|
|
|
|
|
|
|
my.isExternalAuthEnabled = function () {
|
|
|
|
return externalAuthEnabled;
|
|
|
|
};
|
|
|
|
|
2014-11-28 15:17:53 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
my.init = function () {
|
|
|
|
$(document).bind(
|
|
|
|
'local.role.changed.muc',
|
|
|
|
function (event, jid, info, pres) {
|
|
|
|
Moderator.onModeratorStatusChanged(Moderator.isModerator());
|
|
|
|
}
|
|
|
|
);
|
2014-11-28 15:18:12 +00:00
|
|
|
|
|
|
|
$(document).bind(
|
|
|
|
'left.muc',
|
|
|
|
function (event, jid) {
|
|
|
|
console.info("Someone left is it focus ? " + jid);
|
|
|
|
var resource = Strophe.getResourceFromJid(jid);
|
2014-12-11 18:14:46 +00:00
|
|
|
if (resource === 'focus' && !sessionTerminated) {
|
2014-11-28 15:18:12 +00:00
|
|
|
console.info(
|
|
|
|
"Focus has left the room - leaving conference");
|
|
|
|
//hangUp();
|
|
|
|
// We'd rather reload to have everything re-initialized
|
2014-11-28 15:18:31 +00:00
|
|
|
// FIXME: show some message before reload
|
2014-11-28 15:18:12 +00:00
|
|
|
location.reload();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2014-12-05 15:43:04 +00:00
|
|
|
my.setFocusUserJid = function (focusJid) {
|
|
|
|
if (!focusUserJid) {
|
|
|
|
focusUserJid = focusJid;
|
|
|
|
console.info("Focus jid set to: " + focusUserJid);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
my.getFocusUserJid = function () {
|
|
|
|
return focusUserJid;
|
|
|
|
};
|
|
|
|
|
2014-12-05 15:58:11 +00:00
|
|
|
my.getFocusComponent = function () {
|
2014-12-05 15:43:04 +00:00
|
|
|
// Get focus component address
|
|
|
|
var focusComponent = config.hosts.focus;
|
|
|
|
// If not specified use default: 'focus.domain'
|
|
|
|
if (!focusComponent) {
|
|
|
|
focusComponent = 'focus.' + config.hosts.domain;
|
|
|
|
}
|
2014-12-05 15:58:11 +00:00
|
|
|
return focusComponent;
|
|
|
|
};
|
|
|
|
|
|
|
|
my.createConferenceIq = function () {
|
2014-12-05 15:43:04 +00:00
|
|
|
// Generate create conference IQ
|
2014-12-05 15:58:11 +00:00
|
|
|
var elem = $iq({to: Moderator.getFocusComponent(), type: 'set'});
|
2014-11-28 15:18:12 +00:00
|
|
|
elem.c('conference', {
|
|
|
|
xmlns: 'http://jitsi.org/protocol/focus',
|
|
|
|
room: roomName
|
|
|
|
});
|
2014-12-08 08:24:23 +00:00
|
|
|
if (config.hosts.bridge !== undefined)
|
|
|
|
{
|
|
|
|
elem.c(
|
|
|
|
'property',
|
|
|
|
{ name: 'bridge', value: config.hosts.bridge})
|
|
|
|
.up();
|
|
|
|
}
|
2014-11-28 15:31:01 +00:00
|
|
|
if (config.channelLastN !== undefined)
|
|
|
|
{
|
|
|
|
elem.c(
|
|
|
|
'property',
|
|
|
|
{ name: 'channelLastN', value: config.channelLastN})
|
|
|
|
.up();
|
|
|
|
}
|
|
|
|
if (config.adaptiveLastN !== undefined)
|
|
|
|
{
|
|
|
|
elem.c(
|
|
|
|
'property',
|
|
|
|
{ name: 'adaptiveLastN', value: config.adaptiveLastN})
|
|
|
|
.up();
|
|
|
|
}
|
|
|
|
if (config.adaptiveSimulcast !== undefined)
|
|
|
|
{
|
|
|
|
elem.c(
|
|
|
|
'property',
|
|
|
|
{ name: 'adaptiveSimulcast', value: config.adaptiveSimulcast})
|
|
|
|
.up();
|
|
|
|
}
|
2014-12-05 15:29:59 +00:00
|
|
|
if (config.openSctp !== undefined)
|
|
|
|
{
|
|
|
|
elem.c(
|
|
|
|
'property',
|
|
|
|
{ name: 'openSctp', value: config.openSctp})
|
|
|
|
.up();
|
|
|
|
}
|
|
|
|
if (config.enableFirefoxSupport !== undefined)
|
|
|
|
{
|
|
|
|
elem.c(
|
|
|
|
'property',
|
|
|
|
{ name: 'enableFirefoxHacks', value: config.enableFirefoxSupport})
|
|
|
|
.up();
|
|
|
|
}
|
2014-11-28 15:18:12 +00:00
|
|
|
elem.up();
|
2014-11-28 15:31:01 +00:00
|
|
|
return elem;
|
|
|
|
};
|
|
|
|
|
2014-12-16 13:54:13 +00:00
|
|
|
my.parseConfigOptions = function (resultIq) {
|
|
|
|
|
|
|
|
Moderator.setFocusUserJid(
|
|
|
|
$(resultIq).find('conference').attr('focusjid'));
|
|
|
|
|
|
|
|
var extAuthParam
|
|
|
|
= $(resultIq).find('>conference>property[name=\'externalAuth\']');
|
|
|
|
if (extAuthParam.length) {
|
|
|
|
externalAuthEnabled = extAuthParam.attr('value') === 'true';
|
|
|
|
}
|
|
|
|
console.info("External authentication enabled: " + externalAuthEnabled);
|
|
|
|
};
|
|
|
|
|
2014-11-28 15:31:01 +00:00
|
|
|
// FIXME: we need to show the fact that we're waiting for the focus
|
|
|
|
// to the user(or that focus is not available)
|
|
|
|
my.allocateConferenceFocus = function (roomName, callback) {
|
2014-12-05 15:43:04 +00:00
|
|
|
// Try to use focus user JID from the config
|
|
|
|
Moderator.setFocusUserJid(config.focusUserJid);
|
|
|
|
// Send create conference IQ
|
2014-11-28 15:31:01 +00:00
|
|
|
var iq = Moderator.createConferenceIq();
|
|
|
|
connection.sendIQ(
|
|
|
|
iq,
|
2014-11-28 15:18:12 +00:00
|
|
|
function (result) {
|
|
|
|
if ('true' === $(result).find('conference').attr('ready')) {
|
2014-11-28 15:18:31 +00:00
|
|
|
// Reset both timers
|
2014-11-28 15:18:12 +00:00
|
|
|
getNextTimeout(true);
|
2014-11-28 15:18:31 +00:00
|
|
|
getNextErrorTimeout(true);
|
2014-12-16 13:54:13 +00:00
|
|
|
// Setup config options
|
|
|
|
Moderator.parseConfigOptions(result);
|
|
|
|
// Exec callback
|
2014-11-28 15:18:12 +00:00
|
|
|
callback();
|
|
|
|
} else {
|
|
|
|
var waitMs = getNextTimeout();
|
|
|
|
console.info("Waiting for the focus... " + waitMs);
|
2014-11-28 15:18:31 +00:00
|
|
|
// Reset error timeout
|
|
|
|
getNextErrorTimeout(true);
|
2014-11-28 15:18:12 +00:00
|
|
|
window.setTimeout(
|
|
|
|
function () {
|
2014-11-28 15:31:01 +00:00
|
|
|
Moderator.allocateConferenceFocus(
|
|
|
|
roomName, callback);
|
2014-11-28 15:18:12 +00:00
|
|
|
}, waitMs);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
function (error) {
|
2014-12-16 13:54:13 +00:00
|
|
|
// Not authorized to create new room
|
|
|
|
if ($(error).find('>error>not-authorized').length) {
|
|
|
|
console.warn("Unauthorized to start the conference");
|
|
|
|
$(document).trigger('auth_required.moderator');
|
|
|
|
return;
|
|
|
|
}
|
2014-11-28 15:18:31 +00:00
|
|
|
var waitMs = getNextErrorTimeout();
|
2014-11-28 15:18:12 +00:00
|
|
|
console.error("Focus error, retry after " + waitMs, error);
|
2014-12-05 15:58:11 +00:00
|
|
|
// Show message
|
|
|
|
messageHandler.notify(
|
|
|
|
'Conference focus', 'disconnected',
|
|
|
|
Moderator.getFocusComponent() +
|
|
|
|
' not available - retry in ' + (waitMs / 1000) + ' sec');
|
2014-11-28 15:18:31 +00:00
|
|
|
// Reset response timeout
|
|
|
|
getNextTimeout(true);
|
2014-11-28 15:18:12 +00:00
|
|
|
window.setTimeout(
|
|
|
|
function () {
|
|
|
|
Moderator.allocateConferenceFocus(roomName, callback);
|
|
|
|
}, waitMs);
|
|
|
|
}
|
|
|
|
);
|
2014-11-28 15:17:53 +00:00
|
|
|
};
|
|
|
|
|
2014-12-16 13:54:13 +00:00
|
|
|
my.getAuthUrl = function (urlCallback) {
|
|
|
|
var iq = $iq({to: Moderator.getFocusComponent(), type: 'get'});
|
|
|
|
iq.c('auth-url', {
|
|
|
|
xmlns: 'http://jitsi.org/protocol/focus',
|
|
|
|
room: roomName
|
|
|
|
});
|
|
|
|
connection.sendIQ(
|
|
|
|
iq,
|
|
|
|
function (result) {
|
|
|
|
var url = $(result).find('auth-url').attr('url');
|
|
|
|
if (url) {
|
|
|
|
console.info("Got auth url: " + url);
|
|
|
|
urlCallback(url);
|
|
|
|
} else {
|
|
|
|
console.error(
|
|
|
|
"Failed to get auth url fro mthe focus", result);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
function (error) {
|
|
|
|
console.error("Get auth url error", error);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2014-11-28 15:17:53 +00:00
|
|
|
return my;
|
|
|
|
}(Moderator || {}));
|
|
|
|
|
|
|
|
|
|
|
|
|