|
@@ -190,8 +190,13 @@ function registerListeners() {
|
190
|
190
|
});
|
191
|
191
|
}
|
192
|
192
|
|
193
|
|
-function setupEvents() {
|
194
|
|
- $(window).bind('beforeunload', function () {
|
|
193
|
+var unload = (function () {
|
|
194
|
+ var unloaded = false;
|
|
195
|
+
|
|
196
|
+ return function () {
|
|
197
|
+ if (unloaded) { return; }
|
|
198
|
+ unloaded = true;
|
|
199
|
+
|
195
|
200
|
if (connection && connection.connected) {
|
196
|
201
|
// ensure signout
|
197
|
202
|
$.ajax({
|
|
@@ -200,24 +205,41 @@ function setupEvents() {
|
200
|
205
|
async: false,
|
201
|
206
|
cache: false,
|
202
|
207
|
contentType: 'application/xml',
|
203
|
|
- data: "<body rid='" + (connection.rid || connection._proto.rid)
|
204
|
|
- + "' xmlns='http://jabber.org/protocol/httpbind' sid='"
|
205
|
|
- + (connection.sid || connection._proto.sid)
|
206
|
|
- + "' type='terminate'>" +
|
207
|
|
- "<presence xmlns='jabber:client' type='unavailable'/>" +
|
208
|
|
- "</body>",
|
|
208
|
+ data: "<body rid='" + (connection.rid || connection._proto.rid) +
|
|
209
|
+ "' xmlns='http://jabber.org/protocol/httpbind' sid='" +
|
|
210
|
+ (connection.sid || connection._proto.sid) +
|
|
211
|
+ "' type='terminate'>" +
|
|
212
|
+ "<presence xmlns='jabber:client' type='unavailable'/>" +
|
|
213
|
+ "</body>",
|
209
|
214
|
success: function (data) {
|
210
|
215
|
console.log('signed out');
|
211
|
216
|
console.log(data);
|
212
|
217
|
},
|
213
|
218
|
error: function (XMLHttpRequest, textStatus, errorThrown) {
|
214
|
219
|
console.log('signout error',
|
215
|
|
- textStatus + ' (' + errorThrown + ')');
|
|
220
|
+ textStatus + ' (' + errorThrown + ')');
|
216
|
221
|
}
|
217
|
222
|
});
|
218
|
223
|
}
|
219
|
224
|
XMPP.disposeConference(true);
|
220
|
|
- });
|
|
225
|
+ };
|
|
226
|
+})();
|
|
227
|
+
|
|
228
|
+function setupEvents() {
|
|
229
|
+ // In recent versions of FF the 'beforeunload' event is not fired when the
|
|
230
|
+ // window or the tab is closed. It is only fired when we leave the page
|
|
231
|
+ // (change URL). If this participant doesn't unload properly, then it
|
|
232
|
+ // becomes a ghost for the rest of the participants that stay in the
|
|
233
|
+ // conference. Thankfully handling the 'unload' event in addition to the
|
|
234
|
+ // 'beforeunload' event seems to garante the execution of the 'unload'
|
|
235
|
+ // method at least once.
|
|
236
|
+ //
|
|
237
|
+ // The 'unload' method can safely be run multiple times, it will actually do
|
|
238
|
+ // something only the first time that it's run, so we're don't have to worry
|
|
239
|
+ // about browsers that fire both events.
|
|
240
|
+
|
|
241
|
+ $(window).bind('beforeunload', unload);
|
|
242
|
+ $(window).bind('unload', unload);
|
221
|
243
|
}
|
222
|
244
|
|
223
|
245
|
var XMPP = {
|