From 2527ad301546ef2104db8f0e76f6f1cb462a3d73 Mon Sep 17 00:00:00 2001 From: Thibaut Horel Date: Sun, 2 Jan 2011 15:31:30 +0100 Subject: Get the roster when connected. --- webclient/lib/basic.js | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) (limited to 'webclient/lib/basic.js') diff --git a/webclient/lib/basic.js b/webclient/lib/basic.js index 8a5d4e3..8ea5b5b 100644 --- a/webclient/lib/basic.js +++ b/webclient/lib/basic.js @@ -1,4 +1,4 @@ -var BOSH_SERVICE = 'http://alias.fr.nf/http-bind/' +var BOSH_SERVICE = 'http://alias.fr.nf/http-bind/'; var connection = null; function log(msg) @@ -18,22 +18,43 @@ function rawOutput(data) function onConnect(status) { + var jid = $('#jid').get(0).value; if (status == Strophe.Status.CONNECTING) { - log('Strophe is connecting.'); - } else if (status == Strophe.Status.CONNFAIL) { - log('Strophe failed to connect.'); - $('#connect').get(0).value = 'connect'; - } else if (status == Strophe.Status.DISCONNECTING) { - log('Strophe is disconnecting.'); - } else if (status == Strophe.Status.DISCONNECTED) { - log('Strophe is disconnected.'); - $('#connect').get(0).value = 'connect'; - } else if (status == Strophe.Status.CONNECTED) { - log('Strophe is connected.'); - connection.disconnect(); + log('Strophe is connecting.'); } + else if (status == Strophe.Status.CONNFAIL) { + log('Strophe failed to connect.'); + $('#connect').get(0).value = 'connect'; + } + else if (status == Strophe.Status.DISCONNECTING) { + log('Strophe is disconnecting.'); + } + else if (status == Strophe.Status.DISCONNECTED) { + log('Strophe is disconnected.'); + $('#connect').get(0).value = 'connect'; + } + else if (status == Strophe.Status.CONNECTED) { + log('Strophe is connected.'); + connection.addHandler(onRoster,Strophe.NS.ROSTER,'iq','result',null, null); + connection.send($pres().tree()); + var roster = $iq({type:'get'}).c('query',{xmlns: Strophe.NS.ROSTER }); + connection.send(roster.tree()); + } +} + +function onRoster(iq) +{ + var elems = iq.getElementsByTagName('query'); + var query = elems[0]; + Strophe.forEachChild(query,'item',function (item){ + var name = item.getAttribute('jid'); + $('#contacts > ul').append('
  • '+name+'
  • '); + }); + return true; } + + $(document).ready(function () { connection = new Strophe.Connection(BOSH_SERVICE); connection.rawInput = rawInput; -- cgit v1.2.3-70-g09d2