Anton Shestakov <av6@dwimlabs.net>, Mon, 21 Mar 2016 10:29:04 +0800
register: move onConnect to XMPPInterface
js/xmpp.js
Permissions: -rw-r--r--
// Generated by CoffeeScript 1.10.0 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() { 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) { this._prepareConnection(); jid = node + "@" + Tram.config.domain; return this.conn.connect(jid, pass, onConnect); XMPPInterface.prototype.disconnect = function(reason) { this.conn.disconnect(reason); 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.savevCard = function(data) { var $vcard, b, bi, binval, bl, d, dl, failcb, okcb, type; $vcard.c('NICKNAME').t(data.nickname).up(); $vcard.c('FN').t(data.fullname).up(); 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) { console.debug('vcard is set!', arguments); return _this.trigger('v/done'); failcb = (function(_this) { console.warn('vcard is NOT set!', arguments); return _this.trigger('v/failed'); return this.conn.sendIQ($vcard.tree(), okcb, failcb); XMPPInterface.prototype.onConnect = function(status, error) { case Strophe.Status.CONNECTING: return console.debug('Strophe is connecting.'); case Strophe.Status.AUTHENTICATING: return console.debug('Strophe is authenticating.'); case Strophe.Status.AUTHFAIL: return console.debug('Strophe failed to authenticate:', error); case Strophe.Status.ERROR: return console.debug('Strophe received an error:', error); case Strophe.Status.CONNFAIL: return console.debug('Strophe failed to connect:', error); case Strophe.Status.DISCONNECTING: return console.debug('Strophe is disconnecting.'); case Strophe.Status.DISCONNECTED: return console.debug('Strophe is disconnected.'); case Strophe.Status.CONNECTED: console.debug('Strophe is connected.'); console.info('My jid:', this.conn.jid); return this.trigger('v/start'); case Strophe.Status.REGISTER: console.debug('Got registration prompt.'); return this.trigger('r/start'); case Strophe.Status.REGISTERED: console.debug('Registered!'); return this.trigger('r/done'); case Strophe.Status.CONFLICT: console.debug('Contact already exists!'); return this.trigger('r/conflict'); case Strophe.Status.NOTACCEPTABLE: console.debug('Registration form not properly filled out.'); return this.trigger('r/failed'); case Strophe.Status.REGIFAIL: console.debug('The server does not support In-Band Registration.'); return this.trigger('r/closed'); _(Tram.XMPPInterface.prototype).extend(Backbone.Events); //# sourceMappingURL=xmpp.js.map