var BOSH_SERVICE = 'http://alias.fr.nf/http-bind'; var connection = null; jQuery.expr[':'].Contains = function(a,i,m){ return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase())>=0; }; function log(msg, color) { $('#log').append($('
').css('background-color', color).text(msg)); } function rawInput(data) { log('RECV: ' + data, '#FBB6B4'); } function rawOutput(data) { log('SENT: ' + data, '#B5BBFB'); } function getRoster() { var roster = $iq({type : 'get'}).c('query', {xmlns : Strophe.NS.ROSTER}); connection.sendIQ(roster, onRoster); } function getPresence(contact) { if ( contact.hasClass("online") ) return 2; else if ( contact.hasClass("away") ) return 1; else return 0; } function jid_to_id(jid) { return Strophe.getBareJidFromJid(jid).replace(/[@.]/g,'-'); } function getJID(contact) { return contact.find('.roster-jid').text(); } function insertContact(contact) { var presence = getPresence(contact); var jid = getJID(contact); var contacts = $('#roster li'); if (contacts.length > 0) { var inserted = false; contacts.each(function () { var locpres = getPresence($(this)); var locjid = getJID($(this)); if (presence > locpres) { $(this).before(contact); inserted = true; return false; } else if ( (presence == locpres) && (jid < locjid) ) { $(this).before(contact); inserted = true; return false; } }); if (!inserted) $('#roster ul').append(contact); } else $('#roster ul').append(contact); } function onPresence(presence) { var who = $(presence).attr('from'); var type = $(presence).attr('type'); if (type !== 'error') { var contact = $('#'+jid_to_id(who)); contact.removeClass('online away offline'); if (type === 'unavailable') { contact.addClass('offline'); } else { var show = $(presence).find('show').text(); if (show === '' || show === '') { contact.addClass('online'); } else { contact.addClass('away'); } } contact.remove(); insertContact(contact); } return true; } function onRoster(iq) { $('#roster li').remove(); var elems = iq.getElementsByTagName('query'); var query = elems[0]; Strophe.forEachChild(query, 'item', function(item) { var jid = item.getAttribute('jid'); var name = item.getAttribute('name') || jid; var id = jid_to_id(jid); var contact = $("