Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

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

paweldomas84a453597cf0
diff --git a/app.js b/app.js
index 9c9248c5f9..e876f306ef 100644
--- a/app.js
+++ b/app.js
@@ -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() {
diff --git a/moderator.js b/moderator.js
index 7f58119324..e810fe4107 100644
--- a/moderator.js
+++ b/moderator.js
@@ -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;
diff --git a/util.js b/util.js
index 652b5b14c4..e9e7f1f608 100644
--- a/util.js
+++ b/util.js
@@ -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 || {}));