Reloads the page when focus leaves to dispose MUC room. Adds exponential backoff to focus polling.

This commit is contained in:
paweldomas 2014-11-28 16:18:12 +01:00
parent 7dc8102dee
commit 84a453597c
3 changed files with 69 additions and 24 deletions

25
app.js
View File

@ -219,29 +219,8 @@ function doJoin() {
generateRoomName();
}
var elem = $iq({to: config.hosts.focus, type: 'set'});
elem.c('conference', {
xmlns: 'http://jitsi.org/protocol/focus',
room: roomName
});
elem.up();
connection.sendIQ(elem,
function (result) {
console.info("Focus replied ", result);
if ('true' === $(result).find('conference').attr('ready')) {
doJoinAfterFocus();
} else {
console.info("Waiting for the focus...");
window.setTimeout(
function () {
doJoin();
}, 3000);
}
},
function (error) {
console.warn(error);
}
);
Moderator.allocateConferenceFocus(
roomName, doJoinAfterFocus);
}
function doJoinAfterFocus() {

View File

@ -1,10 +1,13 @@
/* global $, config, connection, Etherpad, Toolbar, VideoLayout */
/* global $, $iq, config, connection, Etherpad, hangUp, Strophe, Toolbar,
Util, VideoLayout */
/**
* Contains logic responsible for enabling/disabling functionality available
* only to moderator users.
*/
var Moderator = (function (my) {
var getNextTimeout = Util.createExpBackoffTimer(1000);
my.isModerator = function () {
return connection.emuc.isModerator();
};
@ -44,6 +47,54 @@ var Moderator = (function (my) {
Moderator.onModeratorStatusChanged(Moderator.isModerator());
}
);
$(document).bind(
'left.muc',
function (event, jid) {
console.info("Someone left is it focus ? " + jid);
var resource = Strophe.getResourceFromJid(jid);
if (resource === 'focus') {
console.info(
"Focus has left the room - leaving conference");
//hangUp();
// We'd rather reload to have everything re-initialized
location.reload();
}
}
);
};
my.allocateConferenceFocus = function (roomName, callback) {
var elem = $iq({to: config.hosts.focus, type: 'set'});
elem.c('conference', {
xmlns: 'http://jitsi.org/protocol/focus',
room: roomName
});
elem.up();
connection.sendIQ(elem,
function (result) {
if ('true' === $(result).find('conference').attr('ready')) {
// Reset timer
getNextTimeout(true);
callback();
} else {
var waitMs = getNextTimeout();
console.info("Waiting for the focus... " + waitMs);
window.setTimeout(
function () {
Moderator.allocateConferenceFocus(roomName, callback);
}, waitMs);
}
},
function (error) {
var waitMs = getNextTimeout();
console.error("Focus error, retry after " + waitMs, error);
window.setTimeout(
function () {
Moderator.allocateConferenceFocus(roomName, callback);
}, waitMs);
}
);
};
return my;

15
util.js
View File

@ -84,5 +84,20 @@ var Util = (function (my) {
element.setAttribute("data-container", "body");
};
my.createExpBackoffTimer = function (step) {
var count = 1;
return function (reset) {
// Reset call
if (reset) {
count = 1;
return;
}
// Calculate next timeout
var timeout = Math.pow(2, count - 1);
count += 1;
return timeout * step;
};
};
return my;
}(Util || {}));