227:64acb7b50eee
Anton Shestakov <av6@dwimlabs.net>, Fri, 12 Aug 2016 22:26:01 +0800
pipelines: re-enable idempotence testing

next change 247:fcca53a2f523
previous change 178:226f648724e2

js/xmpp.js

Permissions: -rw-r--r--

Other formats: Feeds:
// Generated by CoffeeScript 1.10.0
(function() {
var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
Tram.XMPPInterface = (function() {
XMPPInterface.prototype.conn = null;
function XMPPInterface() {
this.onConnect = bind(this.onConnect, this);
}
XMPPInterface.prototype._prepareConnection = function() {
if (this.conn != null) {
console.debug('connection exists, not reconnecting');
}
return this.conn = new Strophe.Connection("https://" + Tram.config.host + "/http-bind");
};
XMPPInterface.prototype.connect = function(node, pass) {
var jid;
this._prepareConnection();
jid = node + "@" + Tram.config.domain;
return this.conn.connect(jid, pass, this.onConnect);
};
XMPPInterface.prototype.disconnect = function(reason) {
if (this.conn == null) {
return;
}
this.conn.disconnect(reason);
this.conn = null;
};
XMPPInterface.prototype.startRegistration = function() {
this._prepareConnection();
return this.conn.register.connect(Tram.config.domain, this.onConnect);
};
XMPPInterface.prototype.register = function(username, password) {
this.conn.register.fields.username = username;
this.conn.register.fields.password = password;
return this.conn.register.submit();
};
XMPPInterface.prototype.finishRegistration = function() {
return this.conn.authenticate();
};
XMPPInterface.prototype.unregister = function() {
var iq;
iq = $iq({
type: 'set'
}).c('query', {
xmlns: Strophe.NS.REGISTER
}).c('remove');
return this.conn.send(iq.tree());
};
XMPPInterface.prototype.savevCard = function(data, okcb, failcb) {
var $vcard, b, bi, binval, bl, d, dl, type;
$vcard = $iq({
type: 'set'
}).c('vCard', {
xmlns: Strophe.NS.VCARD
});
if (data.nickname) {
$vcard.c('NICKNAME').t(data.nickname).up();
}
if (data.fullname) {
$vcard.c('FN').t(data.fullname).up();
}
if (data.avatar) {
b = ';base64,';
d = 'data:';
dl = d.length;
bl = b.length;
bi = data.avatar.indexOf(b);
type = data.avatar.substr(dl, bi - dl);
binval = data.avatar.substr(bi + bl);
$vcard.c('PHOTO').c('TYPE').t(type).up().c('BINVAL').t(binval);
}
return this.conn.sendIQ($vcard.tree(), okcb, failcb);
};
XMPPInterface.prototype.onConnect = function(status, error) {
switch (status) {
case Strophe.Status.CONNECTING:
console.debug('Strophe is connecting.');
this.trigger('connecting');
break;
case Strophe.Status.AUTHENTICATING:
console.debug('Strophe is authenticating.');
this.trigger('authenticating');
break;
case Strophe.Status.AUTHFAIL:
console.debug('Strophe failed to authenticate:', error);
this.trigger('authfail');
break;
case Strophe.Status.ERROR:
console.debug('Strophe received an error:', error);
this.trigger('error');
break;
case Strophe.Status.CONNFAIL:
console.debug('Strophe failed to connect:', error);
this.trigger('connfail');
break;
case Strophe.Status.DISCONNECTING:
console.debug('Strophe is disconnecting.');
this.trigger('disconnecting');
break;
case Strophe.Status.DISCONNECTED:
console.debug('Strophe is disconnected.');
this.trigger('disconnected');
break;
case Strophe.Status.CONNECTED:
console.debug('Strophe is connected.');
console.info('My jid:', this.conn.jid);
this.trigger('connected');
break;
case Strophe.Status.ATTACHED:
console.debug('Strophe is attached.');
console.info('My jid:', this.conn.jid);
this.trigger('attached');
break;
case Strophe.Status.REGISTER:
console.debug('Got registration prompt.');
this.trigger('register');
break;
case Strophe.Status.REGISTERED:
console.debug('Registered!');
this.trigger('registered');
break;
case Strophe.Status.CONFLICT:
console.debug('Contact already exists!');
this.trigger('conflict');
break;
case Strophe.Status.NOTACCEPTABLE:
console.debug('Registration form not properly filled out.');
this.trigger('notacceptable');
break;
case Strophe.Status.REGIFAIL:
console.debug('The server does not support In-Band Registration.');
this.trigger('regifail');
}
return this.trigger('status', status);
};
XMPPInterface.prototype.generateVerificationString = function() {
var f, features, i, id, ids, j, k, len, len1, ref, ver;
ver = '';
ids = (function() {
var j, len, ref, results;
ref = this.conn.disco._identities;
results = [];
for (j = 0, len = ref.length; j < len; j++) {
i = ref[j];
results.push(i);
}
return results;
}).call(this);
ids.sort(function(a, b) {
if (a.category > b.category) {
return 1;
}
if (a.category < b.category) {
return -1;
}
if (a.type > b.type) {
return 1;
}
if (a.type < b.type) {
return -1;
}
if (a.lang > b.lang) {
return 1;
}
if (a.lang < b.lang) {
return -1;
}
return 0;
});
features = (function() {
var j, len, ref, results;
ref = this.conn.disco._features;
results = [];
for (j = 0, len = ref.length; j < len; j++) {
f = ref[j];
results.push(f);
}
return results;
}).call(this);
features.sort();
for (j = 0, len = ids.length; j < len; j++) {
id = ids[j];
ver += id.category + "/" + id.type + "/" + ((ref = id.lang) != null ? ref : '') + "/" + id.name + "<";
}
for (k = 0, len1 = features.length; k < len1; k++) {
f = features[k];
ver += f + "<";
}
return b64_sha1(ver);
};
XMPPInterface.prototype.sendPresence = function(attrs) {
var pres, ver;
ver = this.generateVerificationString();
pres = $pres().c('c', {
xmlns: Strophe.NS.CAPS,
hash: 'sha-1',
node: Tram.info.url,
ver: ver
}).up();
if (attrs.priority != null) {
pres.c('priority').t(attrs.priority).up();
}
if (attrs.show != null) {
pres.c('show').t(attrs.show).up();
}
if (attrs.status != null) {
pres.c('status').t(attrs.status).up();
}
return this.conn.send(pres.tree());
};
return XMPPInterface;
})();
_(Tram.XMPPInterface.prototype).extend(Backbone.Events);
}).call(this);
//# sourceMappingURL=xmpp.js.map