Browse Source

Reloads JitsiConnection on prosody or jicofo restart

dev1
hristoterezov 9 years ago
parent
commit
6ca2c62090

+ 3
- 2
JitsiConference.js View File

36
     }
36
     }
37
     this.eventEmitter = new EventEmitter();
37
     this.eventEmitter = new EventEmitter();
38
     this.settings = new Settings();
38
     this.settings = new Settings();
39
+    this.retries = 0;
39
     this._init(options);
40
     this._init(options);
40
     this.componentsVersions = new ComponentsVersions(this);
41
     this.componentsVersions = new ComponentsVersions(this);
41
     this.rtc = new RTC(this, options);
42
     this.rtc = new RTC(this, options);
84
     // reloaded)
85
     // reloaded)
85
     this.connection = options.connection || this.connection;
86
     this.connection = options.connection || this.connection;
86
     this.xmpp = this.connection.xmpp;
87
     this.xmpp = this.connection.xmpp;
87
-
88
+    this.retries++;
88
     this.room = this.xmpp.createRoom(this.options.name, this.options.config,
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
     //restore previous presence options
92
     //restore previous presence options
92
     if(options.roomState) {
93
     if(options.roomState) {

+ 12
- 3
JitsiConferenceEventManager.js View File

130
         JitsiConferenceEvents.CONFERENCE_FAILED,
130
         JitsiConferenceEvents.CONFERENCE_FAILED,
131
         JitsiConferenceErrors.FOCUS_DISCONNECTED);
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
     this.chatRoomForwarder.forward(XMPPEvents.CONNECTION_INTERRUPTED,
146
     this.chatRoomForwarder.forward(XMPPEvents.CONNECTION_INTERRUPTED,
138
         JitsiConferenceEvents.CONNECTION_INTERRUPTED);
147
         JitsiConferenceEvents.CONNECTION_INTERRUPTED);

+ 20
- 1
JitsiConnection.js View File

1
 var JitsiConference = require("./JitsiConference");
1
 var JitsiConference = require("./JitsiConference");
2
 var XMPP = require("./modules/xmpp/xmpp");
2
 var XMPP = require("./modules/xmpp/xmpp");
3
 var JitsiConnectionEvents = require("./JitsiConnectionEvents");
3
 var JitsiConnectionEvents = require("./JitsiConnectionEvents");
4
+var JitsiConnectionErrors = require("./JitsiConnectionErrors");
4
 
5
 
5
 /**
6
 /**
6
  * Creates new connection object for the Jitsi Meet server side video conferencing service. Provides access to the
7
  * Creates new connection object for the Jitsi Meet server side video conferencing service. Provides access to the
16
     this.options = options;
17
     this.options = options;
17
     this.xmpp = new XMPP(options, token);
18
     this.xmpp = new XMPP(options, token);
18
     this.conferences = {};
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
  * @param options {object} options to be overriden
61
  * @param options {object} options to be overriden
47
  */
62
  */
48
 JitsiConnection.prototype.reload = function (options) {
63
 JitsiConnection.prototype.reload = function (options) {
64
+    if(this.retryOnFail === 0)
65
+        return false;
66
+    this.retryOnFail--;
49
     var states = {};
67
     var states = {};
50
     for(var name in this.conferences) {
68
     for(var name in this.conferences) {
51
         states[name] = this.conferences[name].room.exportState();
69
         states[name] = this.conferences[name].room.exportState();
52
         this.conferences[name].leave(true);
70
         this.conferences[name].leave(true);
53
     }
71
     }
54
     this.connectionEstablishedHandler =
72
     this.connectionEstablishedHandler =
55
-        this.reloadConferneces.bind(this, states);
73
+        this.reloadConferences.bind(this, states);
56
     this.addEventListener(JitsiConnectionEvents.CONNECTION_ESTABLISHED,
74
     this.addEventListener(JitsiConnectionEvents.CONNECTION_ESTABLISHED,
57
         this.connectionEstablishedHandler);
75
         this.connectionEstablishedHandler);
58
     this.xmpp.reload(options || {});
76
     this.xmpp.reload(options || {});
77
+    return true;
59
 }
78
 }
60
 
79
 
61
 /**
80
 /**

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

62
     return res;
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
     this.eventEmitter = new EventEmitter();
67
     this.eventEmitter = new EventEmitter();
67
     this.xmpp = XMPP;
68
     this.xmpp = XMPP;
68
     this.connection = connection;
69
     this.connection = connection;
79
     this.bridgeIsDown = false;
80
     this.bridgeIsDown = false;
80
     this.options = options || {};
81
     this.options = options || {};
81
     this.moderator = new Moderator(this.roomjid, this.xmpp, this.eventEmitter,
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
     this.initPresenceMap();
85
     this.initPresenceMap();
84
     this.session = null;
86
     this.session = null;
85
     var self = this;
87
     var self = this;
243
     member.jid = jid;
245
     member.jid = jid;
244
     member.isFocus
246
     member.isFocus
245
         = jid && jid.indexOf(this.moderator.getFocusUserJid() + "/") === 0;
247
         = jid && jid.indexOf(this.moderator.getFocusUserJid() + "/") === 0;
246
-
248
+    console.debug("aaaaa", jid, this.moderator.getFocusUserJid(), pres);
247
     member.isHiddenDomain
249
     member.isHiddenDomain
248
         = jid && jid.indexOf("@") > 0
250
         = jid && jid.indexOf("@") > 0
249
             && this.options.hiddenDomain
251
             && this.options.hiddenDomain

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

1078
             error.source = request.tree();
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
         error.session = this;
1084
         error.session = this;
1082
 
1085
 
1083
         logger.error("Jingle error", error);
1086
         logger.error("Jingle error", error);

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

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

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

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

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

276
     return this._connect(jid, password);
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
     var roomjid = roomName  + '@' + this.options.hosts.muc;
280
     var roomjid = roomName  + '@' + this.options.hosts.muc;
281
 
281
 
282
     if (options.useNicks) {
282
     if (options.useNicks) {
293
         roomjid += '/' + tmpJid;
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
 XMPP.prototype.addListener = function(type, listener) {
300
 XMPP.prototype.addListener = function(type, listener) {

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

7
     // audio.
7
     // audio.
8
     AUDIO_MUTED_BY_FOCUS: "xmpp.audio_muted_by_focus",
8
     AUDIO_MUTED_BY_FOCUS: "xmpp.audio_muted_by_focus",
9
     AUTHENTICATION_REQUIRED: "xmpp.authentication_required",
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
     BRIDGE_DOWN: "xmpp.bridge_down",
15
     BRIDGE_DOWN: "xmpp.bridge_down",
11
     // Designates an event indicating that an offer (e.g. Jingle
16
     // Designates an event indicating that an offer (e.g. Jingle
12
     // session-initiate) was received.
17
     // session-initiate) was received.

Loading…
Cancel
Save