Anton Shestakov <av6@dwimlabs.net>, Fri, 08 Apr 2016 22:13:02 +0800
register: progress bar on top
js/index.js
Permissions: -rw-r--r--
// Generated by CoffeeScript 1.10.0 var $form, ConnectionData, connectfn, getChat, getContact, getContactProfile, getText, getVersion, onChatMessage, onConnected, onDisconnected, onGetLast, onGetTime, onGetVersion, onPing, onPresence, onProfileUpdate, onWebRTC, sendMessage, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty, indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; Strophe.addNamespace('LAST', 'jabber:iq:last'); Strophe.addNamespace('TIME', 'urn:xmpp:time'); Strophe.addNamespace('VCARD_UPDATE', 'vcard-temp:x:update'); window.Tram.ClientState = (function(superClass) { extend(ClientState, superClass); return ClientState.__super__.constructor.apply(this, arguments); ClientState.prototype.defaults = { window.contacts = new Tram.Contacts(); window.contactsApp = new Tram.ContactsApp({ el: $('[data-app="contacts"]'), window.calls = new Tram.Calls(); window.callsApp = new Tram.CallsApp({ el: $('[data-app="calls"]'), window.clientState = new Tram.ClientState(); window.faviconApp = new Tram.FaviconApp({ window.sidebarApp = new Tram.SidebarApp({ el: $('[data-app="sidebar"]'), contacts.on('change:show', function(model) { if (model.get('type') === 'self') { return clientState.set('show', model.get('show')); clientState.on('action/show', function(show, status) { return X.conn.send($pres().c('priority').t('1').up().c('show').t(show).up().c('status').t(status).tree()); clientState.on('action/disconnect', function() { return X.disconnect('Logged out'); clientState.on('change:contact', function() { contact = clientState.get('contact'); $logs = $('[data-app="logs"]'); $logs.children().detach(); $logs.append(contact.chat.render().el); return $('[data-form="send"]').toggleClass('uk-hidden', !clientState.has('contact')); onConnected = function() { X.conn.addHandler(onPresence, null, 'presence'); X.conn.addHandler(onProfileUpdate, Strophe.NS.VCARD_UPDATE, 'presence'); X.conn.addHandler(onChatMessage, null, 'message', 'chat'); X.conn.addHandler(onWebRTC, Tram.NS.WEBRTC, 'message', 'chat'); X.conn.addHandler(onGetLast, Strophe.NS.LAST, 'iq', 'get'); X.conn.addHandler(onGetTime, Strophe.NS.TIME, 'iq', 'get'); X.conn.addHandler(onGetVersion, Strophe.NS.VERSION, 'iq', 'get'); X.conn.ping.addPingHandler(onPing); X.conn.disco.addIdentity('client', 'web', Tram.info.client); X.conn.disco.addFeature(Strophe.NS.DISCO_INFO); X.conn.disco.addFeature(Strophe.NS.LAST); X.conn.disco.addFeature(Strophe.NS.PING); X.conn.disco.addFeature(Strophe.NS.TIME); X.conn.disco.addFeature(Strophe.NS.VERSION); X.conn.disco.addFeature(Tram.NS.WEBRTC); X.conn.send($pres().c('priority').t('1').up().c('status').t('Online').tree()); return X.conn.roster.get(); onDisconnected = function() { return location.reload(); var i, len, node, ref, str; if (el.childNodes.length === 0 && el.nodeType === Strophe.ElementType.TEXT) { for (i = 0, len = ref.length; i < len; i++) { if (node.nodeType === Strophe.ElementType.TEXT) { getVersion = function() { id: X.conn.getUniqueId('version'), xmlns: Strophe.NS.VERSION okcb = function(stanza) { name = getText(stanza.getElementsByTagName('name')[0]); version = getText(stanza.getElementsByTagName('version')[0]); os = getText(stanza.getElementsByTagName('os')[0]); 'server/version': version, failcb = function(stanza) { return console.error("couldn't get version", stanza != null ? stanza.innerHTML : void 0); return X.conn.sendIQ(iq.tree(), okcb, failcb, 5000); onGetLast = function(stanza) { id = stanza.getAttribute('id'); from = stanza.getAttribute('from'); xmlns: Strophe.NS.VERSION, onGetTime = function(stanza) { id = stanza.getAttribute('id'); from = stanza.getAttribute('from'); }).c('tzo').t(now.format('Z')).up().c('utc').t(now.toISOString()); onGetVersion = function(stanza) { id = stanza.getAttribute('id'); from = stanza.getAttribute('from'); xmlns: Strophe.NS.VERSION }).c('name').t(Tram.info.client).up().c('version').t(Tram.info.version); onPing = function(stanza) { X.conn.ping.pong(stanza); getChat = function(jid) { return chats[jid] != null ? chats[jid] : chats[jid] = new Tram.LogApp({ collection: new Tram.Messages() getContact = function(from) { contact = contacts.get(from); self = from === X.conn.jid; contacts.each(function(model) { return model.set('type', 'contact'); bjid = Strophe.getBareJidFromJid(from); type: self ? 'self' : 'contact' contact.chat = getChat(bjid); contact.on('action/chat', function() { return clientState.set('contact', contact); contact.on('action/authorize', function() { return X.conn.roster.authorize(contact.get('bjid')); contact.on('action/unauthorize', function() { X.conn.roster.unauthorize(contact.get('bjid')); return contacts.remove(contact); contact.on('action/remove', function() { if (X.conn.roster.findItem(contact.get('bjid'))) { return X.conn.roster.remove(contact.get('bjid'), function() { return contacts.remove(contact); return contacts.remove(contact); contact.w = new Tram.WebRTCInterface(contact); contact.on('action/call', function(media) { contact.set('callstate', 'outgoing'); return contact.w.init(true, { audio: indexOf.call(media, 'a') >= 0, video: indexOf.call(media, 'v') >= 0 contact.on('action/accept', function(media) { return contact.w.init(false, { audio: indexOf.call(media, 'a') >= 0, video: indexOf.call(media, 'v') >= 0 contact.on('action/decline action/hangup', function() { contact.w.sendIntent('terminate'); return contact.unset('callstate'); getContactProfile(contact); getContactProfile = function(contact) { okcb = function(stanza) { vcard = stanza.getElementsByTagName('vCard')[0]; console.warn("no vcard in response", stanza); nickname: getText(vcard.querySelector('NICKNAME')), fullname: getText(vcard.querySelector('FN')), firstname: getText(vcard.querySelector('N > GIVEN')), lastname: getText(vcard.querySelector('N > FAMILY')) mime = getText(vcard.querySelector('PHOTO > TYPE')); data = getText(vcard.querySelector('PHOTO > BINVAL')); return contact.set('avatar', { return contact.unset('avatar'); failcb = function(stanza) { return console.warn("couldn't get vcard", stanza); bjid = contact.get('bjid'); if (bjid === Strophe.getBareJidFromJid(X.conn.jid)) { return X.conn.vcard.get(okcb, bjid, failcb); onPresence = function(stanza) { var contact, delay, from, priority, ref, show, stamp, status, type; type = (ref = stanza.getAttribute('type')) != null ? ref : 'available'; from = stanza.getAttribute('from'); console.warn("not handling <presence type=\"" + type + "\">", stanza); X.conn.roster.subscribe(from); X.conn.roster.unsubscribe(from); console.error('got <presence type="error">', stanza); contact = getContact(from); show = getText(stanza.getElementsByTagName('show')[0]); status = getText(stanza.getElementsByTagName('status')[0]); priority = getText(stanza.getElementsByTagName('priority')[0]); if (type === 'unavailable') { if ((type === 'available' || type === 'unavailable') && contact.get('type') !== 'self') { delay = stanza.getElementsByTagName('delay')[0]; stamp = delay != null ? new Date(delay.getAttribute('stamp')) : new Date(); contact.chat.collection.add({ id: stanza.getAttribute('id'), text: status != null ? status : "is now " + show onProfileUpdate = function(stanza) { from = stanza.getAttribute('from'); contact = getContact(from); getContactProfile(contact); onChatMessage = function(stanza) { var contact, delay, from, stamp, text, thread, type; from = stanza.getAttribute('from'); type = stanza.getAttribute('type'); text = getText(stanza.getElementsByTagName('body')[0]); thread = getText(stanza.getElementsByTagName('thread')[0]); delay = stanza.getElementsByTagName('delay')[0]; stamp = delay != null ? new Date(delay.getAttribute('stamp')) : new Date(); contact = getContact(from); contact.chat.collection.add({ id: stanza.getAttribute('id'), onWebRTC = function(stanza) { var contact, delay, from, intent, payload, stamp; from = stanza.getAttribute('from'); contact = getContact(from); intent = stanza.getElementsByTagName('intent')[0]; payload = stanza.getElementsByTagName('payload')[0]; delay = stanza.getElementsByTagName('delay')[0]; stamp = delay != null ? new Date(delay.getAttribute('stamp')) : new Date(); switch (getText(intent)) { contact.set('callstate', 'incoming'); contact.chat.collection.add({ id: stanza.getAttribute('id'), contact.unset('callstate'); contact.w.onPayload(stanza); window.X = new Tram.XMPPInterface(); X.on('connecting', function() { return connData.unset('auth-errors'); X.on('authfail', function() { return connData.set('auth-errors', ['Invalid username or password.']); X.on('disconnected', function() { $('[data-step="login"]').removeClass('uk-hidden'); $('[data-step="main"]').addClass('uk-hidden'); X.on('connected attached', function() { $('[data-step="login"]').addClass('uk-hidden'); $('[data-step="main"]').removeClass('uk-hidden'); $(window).on('beforeunload unload', function() { return X.disconnect('Window closed'); ConnectionData = (function(superClass) { extend(ConnectionData, superClass); function ConnectionData() { return ConnectionData.__super__.constructor.apply(this, arguments); ConnectionData.prototype.defaults = { ConnectionData.prototype.validate = function(attrs, options) { this.unset('username-errors'); this.unset('password-errors'); this.unset('auth-errors'); if (((ref = attrs.username) != null ? ref : '').trim() === '') { this.set('username-errors', ['This field is required.']); if (((ref1 = attrs.password) != null ? ref1 : '') === '') { this.set('password-errors', ['This field is required.']); return this.has('username-errors') || this.has('password-errors'); window.connData = new ConnectionData(); if (connData.isValid()) { return X.connect(connData.get('username').trim(), connData.get('password')); $form = $('[data-form="connect"]'); window.connRivet = rivets.bind($form.get(0), { $form.find('input').on('keydown', function(e) { if ((!this.required || this.value !== '') && e.keyCode === 13) { index = $form.find('input').index(this); $next = $form.find('input').eq(index + 1); if ($next.length !== 0) { return $form.find('button').trigger('click'); sendMessage = function() { if (text !== '' && clientState.has('contact')) { contact = clientState.get('contact'); }).c('body').t(text).tree()); contact.chat.collection.add({ contact: contacts.findWhere({ return $('#msg').val(''); $('[data-send-button]').on('click', sendMessage); $('#msg').on('keypress', function(e) { $('[data-add-button]').on('click', function() { jid = $('#new-contact').val().trim(); if (indexOf.call(jid, '@') < 0) { jid = jid + "@" + Tram.config.domain; $('#new-contact').val(''); return X.conn.roster.add(jid, null, [], function() { return X.conn.roster.subscribe(jid, 'I want to chat', null); $('#new-contact').on('keypress', function(e) { return $('[data-add-button]').trigger('click'); window.setInterval(function() { return $('time[datetime]').each(function() { return $this.text(moment($this.attr('datetime')).fromNow()); //# sourceMappingURL=index.js.map