18:be40f584efc1
Anton Shestakov <av6@dwimlabs.net>, Sun, 20 Mar 2016 23:30:16 +0800
register: improve scripting, move XMPP interface to a separate file

next change 20:aa1eeed14fff

js/xmpp.js

Permissions: -rw-r--r--

Other formats: Feeds:
// Generated by CoffeeScript 1.10.0
(function() {
Tram.XMPPInterface = (function() {
XMPPInterface.prototype.conn = null;
function XMPPInterface() {}
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, onConnect) {
var jid;
this._prepareConnection();
jid = node + "@" + Tram.config.domain;
return this.conn.connect(jid, pass, onConnect);
};
XMPPInterface.prototype.disconnect = function(reason) {
if (this.conn == null) {
return;
}
this.conn.disconnect(reason);
this.conn = null;
};
XMPPInterface.prototype.startRegistration = function(onConnect) {
this._prepareConnection();
return this.conn.register.connect(Tram.config.domain, 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.savevCard = function(data) {
var $vcard, b, bi, binval, bl, d, dl, failcb, okcb, 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);
}
okcb = (function(_this) {
return function() {
console.debug('vcard is set!', arguments);
return _this.trigger('v/done');
};
})(this);
failcb = (function(_this) {
return function() {
console.warn('vcard is NOT set!', arguments);
return _this.trigger('v/failed');
};
})(this);
return this.conn.sendIQ($vcard.tree(), okcb, failcb);
};
return XMPPInterface;
})();
_(Tram.XMPPInterface.prototype).extend(Backbone.Events);
}).call(this);
//# sourceMappingURL=xmpp.js.map