Browse Source

Reloads JitsiConnection on prosody or jicofo restart

dev1
hristoterezov 9 years ago
parent
commit
6ca2c62090

+ 3
- 2
JitsiConference.js View File

@@ -36,6 +36,7 @@ function JitsiConference(options) {
36 36
     }
37 37
     this.eventEmitter = new EventEmitter();
38 38
     this.settings = new Settings();
39
+    this.retries = 0;
39 40
     this._init(options);
40 41
     this.componentsVersions = new ComponentsVersions(this);
41 42
     this.rtc = new RTC(this, options);
@@ -84,9 +85,9 @@ JitsiConference.prototype._init = function (options) {
84 85
     // reloaded)
85 86
     this.connection = options.connection || this.connection;
86 87
     this.xmpp = this.connection.xmpp;
87
-
88
+    this.retries++;
88 89
     this.room = this.xmpp.createRoom(this.options.name, this.options.config,
89
-        this.settings);
90
+        this.settings, (this.retries < 4 ? 3 : null));
90 91
 
91 92
     //restore previous presence options
92 93
     if(options.roomState) {

+ 12
- 3
JitsiConferenceEventManager.js View File

@@ -130,9 +130,18 @@ JitsiConferenceEventManager.prototype.setupChatRoomListeners = function () {
130 130
         JitsiConferenceEvents.CONFERENCE_FAILED,
131 131
         JitsiConferenceErrors.FOCUS_DISCONNECTED);
132 132
 
133
-    this.chatRoomForwarder.forward(XMPPEvents.FOCUS_LEFT,
134
-        JitsiConferenceEvents.CONFERENCE_FAILED,
135
-        JitsiConferenceErrors.FOCUS_LEFT);
133
+    conference.room.addListener(XMPPEvents.FOCUS_LEFT,
134
+        function () {
135
+            if(!conference.connection.reload())
136
+                conference.eventEmitter.emit(
137
+                    JitsiConferenceEvents.CONFERENCE_FAILED,
138
+                    JitsiConferenceErrors.FOCUS_LEFT);
139
+        });
140
+
141
+    conference.room.addListener(XMPPEvents.ALLOCATE_FOCUS_MAX_RETRIES_ERROR,
142
+        function () {
143
+            conference.connection.reload();
144
+        });
136 145
 
137 146
     this.chatRoomForwarder.forward(XMPPEvents.CONNECTION_INTERRUPTED,
138 147
         JitsiConferenceEvents.CONNECTION_INTERRUPTED);

+ 20
- 1
JitsiConnection.js View File

@@ -1,6 +1,7 @@
1 1
 var JitsiConference = require("./JitsiConference");
2 2
 var XMPP = require("./modules/xmpp/xmpp");
3 3
 var JitsiConnectionEvents = require("./JitsiConnectionEvents");
4
+var JitsiConnectionErrors = require("./JitsiConnectionErrors");
4 5
 
5 6
 /**
6 7
  * Creates new connection object for the Jitsi Meet server side video conferencing service. Provides access to the
@@ -16,6 +17,20 @@ function JitsiConnection(appID, token, options) {
16 17
     this.options = options;
17 18
     this.xmpp = new XMPP(options, token);
18 19
     this.conferences = {};
20
+    this.retryOnFail = 0;
21
+    this.addEventListener(JitsiConnectionEvents.CONNECTION_ESTABLISHED,
22
+        function () {
23
+            this.retryOnFail = 3;
24
+        }.bind(this));
25
+
26
+    this.addEventListener(JitsiConnectionEvents.CONNECTION_FAILED,
27
+        function (errType, msg) {
28
+            if(errType === JitsiConnectionErrors.OTHER_ERROR &&
29
+                (msg === "item-not-found" || msg === "host-unknown")) {
30
+                    // FIXME: don't report the error if we are going to reload
31
+                    this.reload();
32
+                }
33
+        }.bind(this));
19 34
 }
20 35
 
21 36
 /**
@@ -46,16 +61,20 @@ JitsiConnection.prototype.attach = function (options) {
46 61
  * @param options {object} options to be overriden
47 62
  */
48 63
 JitsiConnection.prototype.reload = function (options) {
64
+    if(this.retryOnFail === 0)
65
+        return false;
66
+    this.retryOnFail--;
49 67
     var states = {};
50 68
     for(var name in this.conferences) {
51 69
         states[name] = this.conferences[name].room.exportState();
52 70
         this.conferences[name].leave(true);
53 71
     }
54 72
     this.connectionEstablishedHandler =
55
-        this.reloadConferneces.bind(this, states);
73
+        this.reloadConferences.bind(this, states);
56 74
     this.addEventListener(JitsiConnectionEvents.CONNECTION_ESTABLISHED,
57 75
         this.connectionEstablishedHandler);
58 76
     this.xmpp.reload(options || {});
77
+    return true;
59 78
 }
60 79
 
61 80
 /**

+ 5
- 3
modules/xmpp/ChatRoom.js View File

@@ -62,7 +62,8 @@ function filterNodeFromPresenceJSON(pres, nodeName){
62 62
     return res;
63 63
 }
64 64
 
65
-function ChatRoom(connection, jid, password, XMPP, options, settings) {
65
+function ChatRoom(connection, jid, password, XMPP, options, settings,
66
+    maxRetries) {
66 67
     this.eventEmitter = new EventEmitter();
67 68
     this.xmpp = XMPP;
68 69
     this.connection = connection;
@@ -79,7 +80,8 @@ function ChatRoom(connection, jid, password, XMPP, options, settings) {
79 80
     this.bridgeIsDown = false;
80 81
     this.options = options || {};
81 82
     this.moderator = new Moderator(this.roomjid, this.xmpp, this.eventEmitter,
82
-        settings, {connection: this.xmpp.options, conference: this.options});
83
+        settings, {connection: this.xmpp.options, conference: this.options},
84
+        maxRetries);
83 85
     this.initPresenceMap();
84 86
     this.session = null;
85 87
     var self = this;
@@ -243,7 +245,7 @@ ChatRoom.prototype.onPresence = function (pres) {
243 245
     member.jid = jid;
244 246
     member.isFocus
245 247
         = jid && jid.indexOf(this.moderator.getFocusUserJid() + "/") === 0;
246
-
248
+    console.debug("aaaaa", jid, this.moderator.getFocusUserJid(), pres);
247 249
     member.isHiddenDomain
248 250
         = jid && jid.indexOf("@") > 0
249 251
             && this.options.hiddenDomain

+ 3
- 0
modules/xmpp/JingleSessionPC.js View File

@@ -1078,6 +1078,9 @@ JingleSessionPC.prototype.newJingleErrorHandler = function(request, failureCb) {
1078 1078
             error.source = request.tree();
1079 1079
         }
1080 1080
 
1081
+        // FIXME: JSON.stringify(error) exception for
1082
+        // circular dependancies when we print that error. Maybe we can include
1083
+        // part of the session object
1081 1084
         error.session = this;
1082 1085
 
1083 1086
         logger.error("Jingle error", error);

+ 9
- 1
modules/xmpp/moderator.js View File

@@ -21,7 +21,7 @@ function createExpBackoffTimer(step) {
21 21
     };
22 22
 }
23 23
 
24
-function Moderator(roomName, xmpp, emitter, settings, options) {
24
+function Moderator(roomName, xmpp, emitter, settings, options, maxRetries) {
25 25
     this.roomName = roomName;
26 26
     this.xmppService = xmpp;
27 27
     this.getNextTimeout = createExpBackoffTimer(1000);
@@ -30,6 +30,8 @@ function Moderator(roomName, xmpp, emitter, settings, options) {
30 30
     this.externalAuthEnabled = false;
31 31
     this.settings = settings;
32 32
     this.options = options;
33
+    this.maxRetries = maxRetries || Infinity;
34
+    this.retries = 0;
33 35
 
34 36
     // Sip gateway can be enabled by configuring Jigasi host in config.js or
35 37
     // it will be enabled automatically if focus detects the component through
@@ -369,6 +371,12 @@ Moderator.prototype._allocateConferenceFocusError = function (error, callback) {
369 371
                 });
370 372
         return;
371 373
     }
374
+    if(this.retries >= this.maxRetries) {
375
+        self.eventEmitter.emit(
376
+                XMPPEvents.ALLOCATE_FOCUS_MAX_RETRIES_ERROR);
377
+        return;
378
+    }
379
+    this.retries++;
372 380
     var waitMs = self.getNextErrorTimeout();
373 381
     var errmsg = "Focus error, retry after "+ waitMs;
374 382
     GlobalOnErrorHandler.callErrorHandler(new Error(errmsg));

+ 2
- 2
modules/xmpp/strophe.emuc.js View File

@@ -24,7 +24,7 @@ module.exports = function(XMPP) {
24 24
             this.connection.addHandler(this.onMute.bind(this),
25 25
                 'http://jitsi.org/jitmeet/audio', 'iq', 'set',null,null);
26 26
         },
27
-        createRoom: function (jid, password, options, settings) {
27
+        createRoom: function (jid, password, options, settings, maxRetries) {
28 28
             var roomJid = Strophe.getBareJidFromJid(jid);
29 29
             if (this.rooms[roomJid]) {
30 30
                 var errmsg = "You are already in the room!";
@@ -33,7 +33,7 @@ module.exports = function(XMPP) {
33 33
                 return;
34 34
             }
35 35
             this.rooms[roomJid] = new ChatRoom(this.connection, jid,
36
-                password, XMPP, options, settings);
36
+                password, XMPP, options, settings, maxRetries);
37 37
             return this.rooms[roomJid];
38 38
         },
39 39
         doLeave: function (jid) {

+ 3
- 2
modules/xmpp/xmpp.js View File

@@ -276,7 +276,7 @@ XMPP.prototype.connect = function (jid, password) {
276 276
     return this._connect(jid, password);
277 277
 };
278 278
 
279
-XMPP.prototype.createRoom = function (roomName, options, settings) {
279
+XMPP.prototype.createRoom = function (roomName, options, settings, maxRetries) {
280 280
     var roomjid = roomName  + '@' + this.options.hosts.muc;
281 281
 
282 282
     if (options.useNicks) {
@@ -293,7 +293,8 @@ XMPP.prototype.createRoom = function (roomName, options, settings) {
293 293
         roomjid += '/' + tmpJid;
294 294
     }
295 295
 
296
-    return this.connection.emuc.createRoom(roomjid, null, options, settings);
296
+    return this.connection.emuc.createRoom(roomjid, null, options, settings,
297
+        maxRetries);
297 298
 }
298 299
 
299 300
 XMPP.prototype.addListener = function(type, listener) {

+ 5
- 0
service/xmpp/XMPPEvents.js View File

@@ -7,6 +7,11 @@ var XMPPEvents = {
7 7
     // audio.
8 8
     AUDIO_MUTED_BY_FOCUS: "xmpp.audio_muted_by_focus",
9 9
     AUTHENTICATION_REQUIRED: "xmpp.authentication_required",
10
+    /**
11
+     * Max retries value of Moderator.allocateConferenceFocus failures is
12
+     * reached.
13
+     */
14
+    ALLOCATE_FOCUS_MAX_RETRIES_ERROR: "xmpp.allocate_focus_max_retries_error",
10 15
     BRIDGE_DOWN: "xmpp.bridge_down",
11 16
     // Designates an event indicating that an offer (e.g. Jingle
12 17
     // session-initiate) was received.

Loading…
Cancel
Save