converse-core: Use built-in XHR instead of $.ajax

This commit is contained in:
JC Brand 2017-02-25 22:26:14 +00:00
parent 93b1481a2c
commit 3d2bfb5c8b

View File

@ -4,7 +4,7 @@
// Copyright (c) 2012-2017, Jan-Carel Brand <jc@opkode.com> // Copyright (c) 2012-2017, Jan-Carel Brand <jc@opkode.com>
// Licensed under the Mozilla Public License (MPLv2) // Licensed under the Mozilla Public License (MPLv2)
// //
/*global Backbone, define, window, document */ /*global Backbone, define, window, document, JSON */
(function (root, factory) { (function (root, factory) {
define(["sizzle", define(["sizzle",
"jquery-private", "jquery-private",
@ -1720,11 +1720,10 @@
var prev_status = this.get('status_message'); var prev_status = this.get('status_message');
this.save({'status_message': status_message}); this.save({'status_message': status_message});
if (this.xhr_custom_status) { if (this.xhr_custom_status) {
$.ajax({ var xhr = new XMLHttpRequest();
url: this.xhr_custom_status_url, xhr.open('POST', this.xhr_custom_status_url, true);
type: 'POST', xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
data: {'msg': status_message} xhr.send({'msg': status_message});
});
} }
if (prev_status === status_message) { if (prev_status === status_message) {
this.trigger("update-status-ui", this); this.trigger("update-status-ui", this);
@ -1826,44 +1825,48 @@
this.fetchLoginCredentials = function () { this.fetchLoginCredentials = function () {
var deferred = new $.Deferred(); var deferred = new $.Deferred();
$.ajax({ var xhr = new XMLHttpRequest();
url: _converse.credentials_url, xhr.open('GET', _converse.credentials_url, true);
type: 'GET', xhr.setRequestHeader('Accept', "application/json, text/javascript");
dataType: "json", xhr.onload = function() {
success: function (response) { if (xhr.status >= 200 && xhr.status < 400) {
var data = JSON.parse(xhr.responseText);
deferred.resolve({ deferred.resolve({
'jid': response.jid, 'jid': data.jid,
'password': response.password 'password': data.password
}); });
}, } else {
error: function (response) { xhr.onerror();
delete _converse.connection;
_converse.emit('noResumeableSession');
deferred.reject(response);
} }
}); };
xhr.onerror = function () {
delete _converse.connection;
_converse.emit('noResumeableSession');
deferred.reject(xhr.responseText);
};
xhr.send();
return deferred.promise(); return deferred.promise();
}; };
this.startNewBOSHSession = function () { this.startNewBOSHSession = function () {
var that = this; var xhr = new XMLHttpRequest();
$.ajax({ xhr.open('GET', _converse.prebind_url, true);
url: this.prebind_url, xhr.setRequestHeader('Accept', "application/json, text/javascript");
type: 'GET', xhr.onload = function() {
dataType: "json", if (xhr.status >= 200 && xhr.status < 400) {
success: function (response) { var data = JSON.parse(xhr.responseText);
that.connection.attach( _converse.connection.attach(
response.jid, data.jid, data.sid, data.rid,
response.sid, _converse.onConnectStatusChanged);
response.rid, } else {
that.onConnectStatusChanged xhr.onerror();
);
},
error: function (response) {
delete that.connection;
that.emit('noResumeableSession');
} }
}); };
xhr.onerror = function () {
delete _converse.connection;
_converse.emit('noResumeableSession');
};
xhr.send();
}; };
this.attemptPreboundSession = function (reconnecting) { this.attemptPreboundSession = function (reconnecting) {