Bugfixes around connection handling.
Properly disconnect after auth fail, so that we can log in again. Don't reset the connection when logging out (not necessary).
This commit is contained in:
parent
7125bd1d67
commit
a4dd5a2a46
50
converse.js
50
converse.js
@ -332,10 +332,15 @@
|
|||||||
// Module-level functions
|
// Module-level functions
|
||||||
// ----------------------
|
// ----------------------
|
||||||
this.giveFeedback = function (message, klass) {
|
this.giveFeedback = function (message, klass) {
|
||||||
$('.conn-feedback').attr('class', 'conn-feedback').text(message);
|
$('.conn-feedback').each(function (idx, el) {
|
||||||
|
var $el = $(el);
|
||||||
|
$el.addClass('conn-feedback').text(message);
|
||||||
if (klass) {
|
if (klass) {
|
||||||
$('.conn-feedback').addClass(klass);
|
$el.addClass(klass);
|
||||||
|
} else {
|
||||||
|
$el.removeClass('error');
|
||||||
}
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.log = function (txt, level) {
|
this.log = function (txt, level) {
|
||||||
@ -431,30 +436,26 @@
|
|||||||
converse.onConnected();
|
converse.onConnected();
|
||||||
}
|
}
|
||||||
} else if (status === Strophe.Status.DISCONNECTED) {
|
} else if (status === Strophe.Status.DISCONNECTED) {
|
||||||
converse.giveFeedback(__('Disconnected'), 'error');
|
|
||||||
if (converse.auto_reconnect) {
|
if (converse.auto_reconnect) {
|
||||||
converse.reconnect();
|
converse.reconnect();
|
||||||
} else {
|
} else {
|
||||||
converse.renderLoginPanel();
|
converse.renderLoginPanel();
|
||||||
}
|
}
|
||||||
} else if (status === Strophe.Status.Error) {
|
} else if (status === Strophe.Status.Error) {
|
||||||
converse.renderLoginPanel();
|
|
||||||
converse.giveFeedback(__('Error'), 'error');
|
converse.giveFeedback(__('Error'), 'error');
|
||||||
} else if (status === Strophe.Status.CONNECTING) {
|
} else if (status === Strophe.Status.CONNECTING) {
|
||||||
converse.giveFeedback(__('Connecting'));
|
converse.giveFeedback(__('Connecting'));
|
||||||
} else if (status === Strophe.Status.CONNFAIL) {
|
|
||||||
converse.renderLoginPanel();
|
|
||||||
converse.giveFeedback(__('Connection Failed'), 'error');
|
|
||||||
} else if (status === Strophe.Status.AUTHENTICATING) {
|
} else if (status === Strophe.Status.AUTHENTICATING) {
|
||||||
converse.giveFeedback(__('Authenticating'));
|
converse.giveFeedback(__('Authenticating'));
|
||||||
} else if (status === Strophe.Status.AUTHFAIL) {
|
} else if (status === Strophe.Status.AUTHFAIL) {
|
||||||
converse.renderLoginPanel();
|
|
||||||
converse.giveFeedback(__('Authentication Failed'), 'error');
|
converse.giveFeedback(__('Authentication Failed'), 'error');
|
||||||
|
converse.connection.disconnect(__('Authentication Failed'));
|
||||||
} else if (status === Strophe.Status.DISCONNECTING) {
|
} else if (status === Strophe.Status.DISCONNECTING) {
|
||||||
if (!converse.connection.connected) {
|
if (!converse.connection.connected) {
|
||||||
converse.renderLoginPanel();
|
converse.renderLoginPanel();
|
||||||
} else {
|
}
|
||||||
converse.giveFeedback(__('Disconnecting'), 'error');
|
if (condition) {
|
||||||
|
converse.giveFeedback(condition, 'error');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -543,7 +544,6 @@
|
|||||||
converse.chatboxviews.closeAllChatBoxes(false);
|
converse.chatboxviews.closeAllChatBoxes(false);
|
||||||
converse.clearSession();
|
converse.clearSession();
|
||||||
converse.connection.disconnect();
|
converse.connection.disconnect();
|
||||||
converse.connection.reset();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.registerGlobalEventHandlers = function () {
|
this.registerGlobalEventHandlers = function () {
|
||||||
@ -622,10 +622,6 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.onConnected = function () {
|
this.onConnected = function () {
|
||||||
if (this.debug) {
|
|
||||||
this.connection.xmlInput = function (body) { console.log(body); };
|
|
||||||
this.connection.xmlOutput = function (body) { console.log(body); };
|
|
||||||
}
|
|
||||||
// When reconnecting, there might be some open chat boxes. We don't
|
// When reconnecting, there might be some open chat boxes. We don't
|
||||||
// know whether these boxes are of the same account or not, so we
|
// know whether these boxes are of the same account or not, so we
|
||||||
// close them now.
|
// close them now.
|
||||||
@ -1913,8 +1909,11 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
giveFeedback: function (message, klass) {
|
giveFeedback: function (message, klass) {
|
||||||
// TODO:
|
var $el = this.$('.conn-feedback');
|
||||||
alert(message);
|
$el.addClass('conn-feedback').text(message);
|
||||||
|
if (klass) {
|
||||||
|
$el.addClass(klass);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onConnected: function () {
|
onConnected: function () {
|
||||||
@ -1958,6 +1957,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
renderLoginPanel: function () {
|
renderLoginPanel: function () {
|
||||||
|
var $feedback = this.$('.conn-feedback'); // we want to still show any existing feedback.
|
||||||
this.$el.html(converse.templates.controlbox(this.model.toJSON()));
|
this.$el.html(converse.templates.controlbox(this.model.toJSON()));
|
||||||
var cfg = {'$parent': this.$el.find('.controlbox-panes'), 'model': this};
|
var cfg = {'$parent': this.$el.find('.controlbox-panes'), 'model': this};
|
||||||
if (!this.loginpanel) {
|
if (!this.loginpanel) {
|
||||||
@ -1976,6 +1976,9 @@
|
|||||||
this.registerpanel.render().$el.hide();
|
this.registerpanel.render().$el.hide();
|
||||||
}
|
}
|
||||||
this.initDragResize();
|
this.initDragResize();
|
||||||
|
if ($feedback.length) {
|
||||||
|
this.$('.conn-feedback').replaceWith($feedback);
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -5009,9 +5012,17 @@
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.setUpXMLLogging = function () {
|
||||||
|
if (this.debug) {
|
||||||
|
this.connection.xmlInput = function (body) { console.log(body); };
|
||||||
|
this.connection.xmlOutput = function (body) { console.log(body); };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
this.initConnection = function () {
|
this.initConnection = function () {
|
||||||
var rid, sid, jid;
|
var rid, sid, jid;
|
||||||
if (this.connection && this.connection.connected) {
|
if (this.connection && this.connection.connected) {
|
||||||
|
this.setUpXMLLogging();
|
||||||
this.onConnected();
|
this.onConnected();
|
||||||
} else {
|
} else {
|
||||||
// XXX: it's not yet clear what the order of preference should
|
// XXX: it's not yet clear what the order of preference should
|
||||||
@ -5026,6 +5037,7 @@
|
|||||||
throw("Error: you must supply a value for the bosh_service_url");
|
throw("Error: you must supply a value for the bosh_service_url");
|
||||||
}
|
}
|
||||||
this.connection = new Strophe.Connection(this.bosh_service_url);
|
this.connection = new Strophe.Connection(this.bosh_service_url);
|
||||||
|
this.setUpXMLLogging();
|
||||||
|
|
||||||
if (this.prebind) {
|
if (this.prebind) {
|
||||||
if (this.jid && this.sid && this.rid) {
|
if (this.jid && this.sid && this.rid) {
|
||||||
@ -5056,10 +5068,14 @@
|
|||||||
* connection.
|
* connection.
|
||||||
*/
|
*/
|
||||||
this.initial_presence_sent = false;
|
this.initial_presence_sent = false;
|
||||||
|
if (this.roster) {
|
||||||
this.roster.off().reset(); // Removes roster contacts
|
this.roster.off().reset(); // Removes roster contacts
|
||||||
|
}
|
||||||
this.connection.roster._callbacks = []; // Remove all Roster handlers (e.g. rosterHandler)
|
this.connection.roster._callbacks = []; // Remove all Roster handlers (e.g. rosterHandler)
|
||||||
|
if (this.rosterview) {
|
||||||
this.rosterview.model.off().reset(); // Removes roster groups
|
this.rosterview.model.off().reset(); // Removes roster groups
|
||||||
this.rosterview.undelegateEvents().remove();
|
this.rosterview.undelegateEvents().remove();
|
||||||
|
}
|
||||||
this.chatboxes.remove(); // Don't call off(), events won't get re-registered upon reconnect.
|
this.chatboxes.remove(); // Don't call off(), events won't get re-registered upon reconnect.
|
||||||
if (this.features) {
|
if (this.features) {
|
||||||
this.features.reset();
|
this.features.reset();
|
||||||
|
Loading…
Reference in New Issue
Block a user