Properly tear down when logging out or disconnecting.
Remove interval handler and the user activity handler. Make sure the connection is reset when logging out. Also removed the reconnectTimeout, instead debounce the reconnect method by 1 second.
This commit is contained in:
parent
35f222d339
commit
aee232421c
10
Gruntfile.js
10
Gruntfile.js
@ -22,11 +22,11 @@ module.exports = function(grunt) {
|
|||||||
cssmin: {
|
cssmin: {
|
||||||
options: {
|
options: {
|
||||||
banner: "/*"+
|
banner: "/*"+
|
||||||
"* Converse.js (Web-based XMPP instant messaging client) \n"+
|
" * Converse.js (Web-based XMPP instant messaging client) \n"+
|
||||||
"* http://conversejs.org \n"+
|
" * http://conversejs.org \n"+
|
||||||
"* Copyright (c) 2012, Jan-Carel Brand <jc@opkode.com> \n"+
|
" * Copyright (c) 2012, Jan-Carel Brand <jc@opkode.com> \n"+
|
||||||
"* Dual licensed under the MIT and GPL Licenses \n"+
|
" * Dual licensed under the MIT and GPL Licenses \n"+
|
||||||
"*/"
|
" */"
|
||||||
},
|
},
|
||||||
minify: {
|
minify: {
|
||||||
dest: 'css/converse.min.css',
|
dest: 'css/converse.min.css',
|
||||||
|
6
dev.html
6
dev.html
@ -53,6 +53,11 @@
|
|||||||
<script>
|
<script>
|
||||||
require(['converse'], function (converse) {
|
require(['converse'], function (converse) {
|
||||||
converse.initialize({
|
converse.initialize({
|
||||||
|
auto_away: 300,
|
||||||
|
i18n: locales['af'],
|
||||||
|
auto_join_rooms: [
|
||||||
|
'discuss@conference.conversejs.org',
|
||||||
|
],
|
||||||
auto_reconnect: true,
|
auto_reconnect: true,
|
||||||
bosh_service_url: 'https://conversejs.org/http-bind/', // Please use this connection manager only for testing purposes
|
bosh_service_url: 'https://conversejs.org/http-bind/', // Please use this connection manager only for testing purposes
|
||||||
keepalive: true,
|
keepalive: true,
|
||||||
@ -60,6 +65,7 @@
|
|||||||
play_sounds: true,
|
play_sounds: true,
|
||||||
roster_groups: true,
|
roster_groups: true,
|
||||||
show_controlbox_by_default: true,
|
show_controlbox_by_default: true,
|
||||||
|
chatstate_notification_blacklist: ['mulles@movim.eu'],
|
||||||
xhr_user_search: false,
|
xhr_user_search: false,
|
||||||
debug: true
|
debug: true
|
||||||
});
|
});
|
||||||
|
@ -51,7 +51,11 @@
|
|||||||
onDisconnected: function () {
|
onDisconnected: function () {
|
||||||
var result = this._super.onDisconnected.apply(this, arguments);
|
var result = this._super.onDisconnected.apply(this, arguments);
|
||||||
if (result === 'disconnected') {
|
if (result === 'disconnected') {
|
||||||
converse.renderLoginPanel();
|
converse._tearDown();
|
||||||
|
var view = converse.chatboxviews.get('controlbox');
|
||||||
|
view.model.set({connected:false});
|
||||||
|
view.$('#controlbox-tabs').empty();
|
||||||
|
view.renderLoginPanel();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -180,14 +184,6 @@
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
converse.renderLoginPanel = function () {
|
|
||||||
converse._tearDown();
|
|
||||||
var view = converse.chatboxviews.get('controlbox');
|
|
||||||
view.model.set({connected:false});
|
|
||||||
view.renderLoginPanel();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
converse.ControlBoxView = converse.ChatBoxView.extend({
|
converse.ControlBoxView = converse.ChatBoxView.extend({
|
||||||
tagName: 'div',
|
tagName: 'div',
|
||||||
className: 'chatbox',
|
className: 'chatbox',
|
||||||
@ -225,7 +221,6 @@
|
|||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
if (!converse.connection.connected || !converse.connection.authenticated || converse.connection.disconnecting) {
|
if (!converse.connection.connected || !converse.connection.authenticated || converse.connection.disconnecting) {
|
||||||
// TODO: we might need to take prebinding into consideration here.
|
|
||||||
this.renderLoginPanel();
|
this.renderLoginPanel();
|
||||||
} else if (!this.contactspanel || !this.contactspanel.$el.is(':visible')) {
|
} else if (!this.contactspanel || !this.contactspanel.$el.is(':visible')) {
|
||||||
this.renderContactsPanel();
|
this.renderContactsPanel();
|
||||||
@ -262,15 +257,10 @@
|
|||||||
|
|
||||||
renderLoginPanel: function () {
|
renderLoginPanel: function () {
|
||||||
var $feedback = this.$('.conn-feedback'); // we want to still show any existing feedback.
|
var $feedback = this.$('.conn-feedback'); // we want to still show any existing feedback.
|
||||||
var cfg = {
|
this.loginpanel = new converse.LoginPanel({
|
||||||
'$parent': this.$el.find('.controlbox-panes'),
|
'$parent': this.$el.find('.controlbox-panes'),
|
||||||
'model': this
|
'model': this
|
||||||
};
|
});
|
||||||
if (!this.loginpanel) {
|
|
||||||
this.loginpanel = new converse.LoginPanel(cfg);
|
|
||||||
} else {
|
|
||||||
this.loginpanel.delegateEvents().initialize(cfg);
|
|
||||||
}
|
|
||||||
this.loginpanel.render();
|
this.loginpanel.render();
|
||||||
if ($feedback.length && $feedback.text() !== __('Connecting')) {
|
if ($feedback.length && $feedback.text() !== __('Connecting')) {
|
||||||
this.$('.conn-feedback').replaceWith($feedback);
|
this.$('.conn-feedback').replaceWith($feedback);
|
||||||
@ -701,6 +691,9 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
updateOnlineCount: _.debounce(function () {
|
updateOnlineCount: _.debounce(function () {
|
||||||
|
if (typeof converse.roster === 'undefined') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
var $count = this.$('#online-count');
|
var $count = this.$('#online-count');
|
||||||
$count.text('('+converse.roster.getNumOnlineContacts()+')');
|
$count.text('('+converse.roster.getNumOnlineContacts()+')');
|
||||||
if (!$count.is(':visible')) {
|
if (!$count.is(':visible')) {
|
||||||
|
@ -321,7 +321,6 @@
|
|||||||
*/
|
*/
|
||||||
this.send_initial_presence = true;
|
this.send_initial_presence = true;
|
||||||
this.msg_counter = 0;
|
this.msg_counter = 0;
|
||||||
this.reconnectTimeout = undefined;
|
|
||||||
|
|
||||||
// Module-level functions
|
// Module-level functions
|
||||||
// ----------------------
|
// ----------------------
|
||||||
@ -334,50 +333,54 @@
|
|||||||
/* Send out a Chat Status Notification (XEP-0352) */
|
/* Send out a Chat Status Notification (XEP-0352) */
|
||||||
if (converse.features[Strophe.NS.CSI] || true) {
|
if (converse.features[Strophe.NS.CSI] || true) {
|
||||||
converse.connection.send($build(stat, {xmlns: Strophe.NS.CSI}));
|
converse.connection.send($build(stat, {xmlns: Strophe.NS.CSI}));
|
||||||
this.inactive = (stat === converse.INACTIVE) ? true : false;
|
converse.inactive = (stat === converse.INACTIVE) ? true : false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.onUserActivity = function () {
|
this.onUserActivity = function () {
|
||||||
/* Resets counters and flags relating to CSI and auto_away/auto_xa */
|
/* Resets counters and flags relating to CSI and auto_away/auto_xa */
|
||||||
if (this.idle_seconds > 0) {
|
if (converse.idle_seconds > 0) {
|
||||||
this.idle_seconds = 0;
|
converse.idle_seconds = 0;
|
||||||
}
|
}
|
||||||
if (!converse.connection.authenticated) {
|
if (!converse.connection.authenticated) {
|
||||||
// We can't send out any stanzas when there's no authenticated connection.
|
// We can't send out any stanzas when there's no authenticated connection.
|
||||||
// This can happen when the connection reconnects.
|
// converse can happen when the connection reconnects.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.inactive) {
|
if (converse.inactive) {
|
||||||
this.sendCSI(converse.ACTIVE);
|
converse.sendCSI(converse.ACTIVE);
|
||||||
}
|
}
|
||||||
if (this.auto_changed_status === true) {
|
if (converse.auto_changed_status === true) {
|
||||||
this.auto_changed_status = false;
|
converse.auto_changed_status = false;
|
||||||
this.xmppstatus.setStatus('online');
|
converse.xmppstatus.setStatus('online');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.onEverySecond = function () {
|
this.onEverySecond = function () {
|
||||||
/* An interval handler running every second.
|
/* An interval handler running every second.
|
||||||
* Used for CSI and the auto_away and auto_xa
|
* Used for CSI and the auto_away and auto_xa features.
|
||||||
* features.
|
|
||||||
*/
|
*/
|
||||||
if (!converse.connection.authenticated) {
|
if (!converse.connection.authenticated) {
|
||||||
// We can't send out any stanzas when there's no authenticated connection.
|
// We can't send out any stanzas when there's no authenticated connection.
|
||||||
// This can happen when the connection reconnects.
|
// This can happen when the connection reconnects.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var stat = this.xmppstatus.getStatus();
|
var stat = converse.xmppstatus.getStatus();
|
||||||
this.idle_seconds++;
|
converse.idle_seconds++;
|
||||||
if (this.csi_waiting_time > 0 && this.idle_seconds > this.csi_waiting_time && !this.inactive) {
|
if (converse.csi_waiting_time > 0 &&
|
||||||
this.sendCSI(converse.INACTIVE);
|
converse.idle_seconds > converse.csi_waiting_time &&
|
||||||
|
!converse.inactive) {
|
||||||
|
converse.sendCSI(converse.INACTIVE);
|
||||||
}
|
}
|
||||||
if (this.auto_away > 0 && this.idle_seconds > this.auto_away && stat !== 'away' && stat !== 'xa') {
|
if (converse.auto_away > 0 &&
|
||||||
this.auto_changed_status = true;
|
converse.idle_seconds > converse.auto_away &&
|
||||||
this.xmppstatus.setStatus('away');
|
stat !== 'away' && stat !== 'xa') {
|
||||||
} else if (this.auto_xa > 0 && this.idle_seconds > this.auto_xa && stat !== 'xa') {
|
converse.auto_changed_status = true;
|
||||||
this.auto_changed_status = true;
|
converse.xmppstatus.setStatus('away');
|
||||||
this.xmppstatus.setStatus('xa');
|
} else if (converse.auto_xa > 0 &&
|
||||||
|
converse.idle_seconds > converse.auto_xa && stat !== 'xa') {
|
||||||
|
converse.auto_changed_status = true;
|
||||||
|
converse.xmppstatus.setStatus('xa');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -385,14 +388,14 @@
|
|||||||
/* Set an interval of one second and register a handler for it.
|
/* Set an interval of one second and register a handler for it.
|
||||||
* Required for the auto_away, auto_xa and csi_waiting_time features.
|
* Required for the auto_away, auto_xa and csi_waiting_time features.
|
||||||
*/
|
*/
|
||||||
if (this.auto_away < 1 && this.auto_xa < 1 && this.csi_waiting_time < 1) {
|
if (converse.auto_away < 1 && converse.auto_xa < 1 && converse.csi_waiting_time < 1) {
|
||||||
// Waiting time of less then one second means features aren't used.
|
// Waiting time of less then one second means features aren't used.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.idle_seconds = 0;
|
converse.idle_seconds = 0;
|
||||||
this.auto_changed_status = false; // Was the user's status changed by converse.js?
|
converse.auto_changed_status = false; // Was the user's status changed by converse.js?
|
||||||
$(window).on('click mousemove keypress focus'+unloadevent , this.onUserActivity.bind(this));
|
$(window).on('click mousemove keypress focus'+unloadevent, converse.onUserActivity);
|
||||||
window.setInterval(this.onEverySecond.bind(this), 1000);
|
converse.everySecondTrigger = window.setInterval(converse.onEverySecond, 1000);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.giveFeedback = function (message, klass) {
|
this.giveFeedback = function (message, klass) {
|
||||||
@ -421,35 +424,31 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
this.reconnect = function (condition) {
|
this.reconnect = _.debounce(function (condition) {
|
||||||
this.connection.disconnect('re-connecting');
|
converse.connection.disconnect('re-connecting');
|
||||||
this.connection.reset();
|
converse.connection.reset();
|
||||||
converse.log('Attempting to reconnect in 5 seconds');
|
converse.log('Attempting to reconnect');
|
||||||
converse.giveFeedback(__('Attempting to reconnect in 5 seconds'), 'error');
|
converse.giveFeedback(__('Attempting to reconnect'), 'error');
|
||||||
window.clearTimeout(converse.reconnectTimeout);
|
converse.clearSession();
|
||||||
converse.reconnectTimeout = window.setTimeout(function () {
|
converse._tearDown();
|
||||||
converse.clearSession();
|
if (converse.authentication !== "prebind") {
|
||||||
converse._tearDown();
|
converse.attemptNonPreboundSession();
|
||||||
if (converse.authentication !== "prebind") {
|
} else if (converse.prebind_url) {
|
||||||
converse.attemptNonPreboundSession();
|
converse.startNewBOSHSession();
|
||||||
} else if (converse.prebind_url) {
|
}
|
||||||
converse.startNewBOSHSession();
|
}, 1000);
|
||||||
}
|
|
||||||
}, 5000);
|
|
||||||
};
|
|
||||||
|
|
||||||
this.onDisconnected = function (condition) {
|
this.onDisconnected = function (condition) {
|
||||||
if (!converse.auto_reconnect) { return; }
|
if (!converse.auto_reconnect) { return; }
|
||||||
if ( converse.disconnection_cause === Strophe.Status.CONNFAIL ||
|
if (converse.disconnection_cause === Strophe.Status.CONNFAIL ||
|
||||||
( converse.disconnection_cause === Strophe.Status.AUTHFAIL &&
|
(converse.disconnection_cause === Strophe.Status.AUTHFAIL &&
|
||||||
converse.credentials_url &&
|
converse.credentials_url &&
|
||||||
converse.auto_login
|
converse.auto_login
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
converse.reconnect(condition);
|
converse.reconnect(condition);
|
||||||
return 'reconnecting';
|
return 'reconnecting';
|
||||||
} else {
|
} else {
|
||||||
converse.giveFeedback(__('Disconnected'));
|
|
||||||
return 'disconnected';
|
return 'disconnected';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -460,10 +459,6 @@
|
|||||||
// By default we always want to send out an initial presence stanza.
|
// By default we always want to send out an initial presence stanza.
|
||||||
converse.send_initial_presence = true;
|
converse.send_initial_presence = true;
|
||||||
delete converse.disconnection_cause;
|
delete converse.disconnection_cause;
|
||||||
if (!!converse.reconnectTimeout) {
|
|
||||||
window.clearTimeout(converse.reconnectTimeout);
|
|
||||||
delete converse.reconnectTimeout;
|
|
||||||
}
|
|
||||||
if ((typeof reconnect !== 'undefined') && (reconnect)) {
|
if ((typeof reconnect !== 'undefined') && (reconnect)) {
|
||||||
converse.log(status === Strophe.Status.CONNECTED ? 'Reconnected' : 'Reattached');
|
converse.log(status === Strophe.Status.CONNECTED ? 'Reconnected' : 'Reattached');
|
||||||
converse.onReconnected();
|
converse.onReconnected();
|
||||||
@ -488,13 +483,14 @@
|
|||||||
converse.connection.disconnect(__('Authentication Failed'));
|
converse.connection.disconnect(__('Authentication Failed'));
|
||||||
converse.disconnection_cause = Strophe.Status.AUTHFAIL;
|
converse.disconnection_cause = Strophe.Status.AUTHFAIL;
|
||||||
} else if (status === Strophe.Status.CONNFAIL) {
|
} else if (status === Strophe.Status.CONNFAIL) {
|
||||||
converse.disconnection_cause = Strophe.Status.CONNFAIL;
|
if (converse.connection.authenticated) {
|
||||||
} else if (status === Strophe.Status.DISCONNECTING) {
|
// Only set the disconnection_cause if we're still
|
||||||
if (!converse.connection.connected) {
|
// authenticated. If we're not, then the user logged out,
|
||||||
// FIXME: leaky abstraction from converse-controlbox.js
|
// and it's therefore not strictly speaking a connection
|
||||||
// Is this needed at all?
|
// failure (so we won't automatically reconnect).
|
||||||
converse.renderLoginPanel();
|
converse.disconnection_cause = Strophe.Status.CONNFAIL;
|
||||||
}
|
}
|
||||||
|
} else if (status === Strophe.Status.DISCONNECTING) {
|
||||||
if (condition) {
|
if (condition) {
|
||||||
converse.giveFeedback(condition, 'error');
|
converse.giveFeedback(condition, 'error');
|
||||||
}
|
}
|
||||||
@ -559,6 +555,7 @@
|
|||||||
converse.chatboxviews.closeAllChatBoxes();
|
converse.chatboxviews.closeAllChatBoxes();
|
||||||
converse.clearSession();
|
converse.clearSession();
|
||||||
converse.connection.disconnect();
|
converse.connection.disconnect();
|
||||||
|
converse.connection.reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
this.registerGlobalEventHandlers = function () {
|
this.registerGlobalEventHandlers = function () {
|
||||||
@ -1741,6 +1738,8 @@
|
|||||||
if (this.features) {
|
if (this.features) {
|
||||||
this.features.reset();
|
this.features.reset();
|
||||||
}
|
}
|
||||||
|
$(window).off('click mousemove keypress focus'+unloadevent, converse.onUserActivity);
|
||||||
|
window.clearInterval(converse.everySecondTrigger);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -56,18 +56,12 @@
|
|||||||
* login panel.
|
* login panel.
|
||||||
*/
|
*/
|
||||||
this._super.renderLoginPanel.apply(this, arguments);
|
this._super.renderLoginPanel.apply(this, arguments);
|
||||||
var converse = this._super.converse,
|
var converse = this._super.converse;
|
||||||
cfg;
|
|
||||||
if (converse.allow_registration) {
|
if (converse.allow_registration) {
|
||||||
cfg = {
|
this.registerpanel = new converse.RegisterPanel({
|
||||||
'$parent': this.$el.find('.controlbox-panes'),
|
'$parent': this.$el.find('.controlbox-panes'),
|
||||||
'model': this
|
'model': this
|
||||||
};
|
});
|
||||||
if (typeof this.registerpanel === 'undefined') {
|
|
||||||
this.registerpanel = new converse.RegisterPanel(cfg);
|
|
||||||
} else {
|
|
||||||
this.registerpanel.delegateEvents().initialize(cfg);
|
|
||||||
}
|
|
||||||
this.registerpanel.render().$el.hide();
|
this.registerpanel.render().$el.hide();
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
Loading…
Reference in New Issue
Block a user