aboutsummaryrefslogtreecommitdiffstats
path: root/webclient/lib/basic.js
diff options
context:
space:
mode:
authorThibaut Horel <thibaut.horel@gmail.com>2011-01-02 15:31:30 +0100
committerThibaut Horel <thibaut.horel@gmail.com>2011-01-02 15:31:30 +0100
commit2527ad301546ef2104db8f0e76f6f1cb462a3d73 (patch)
tree1dcc6b98098bcfd368defab0b5d057e60e452acc /webclient/lib/basic.js
parentd90aec17e2201f256783a531c548dcc9857c889d (diff)
downloadalias-2527ad301546ef2104db8f0e76f6f1cb462a3d73.tar.gz
Get the roster when connected.
Diffstat (limited to 'webclient/lib/basic.js')
-rw-r--r--webclient/lib/basic.js47
1 files changed, 34 insertions, 13 deletions
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('<li>'+name+'</li>');
+ });
+ return true;
}
+
+
$(document).ready(function () {
connection = new Strophe.Connection(BOSH_SERVICE);
connection.rawInput = rawInput;