diff options
| author | Thibaut Horel <thibaut.horel@gmail.com> | 2011-01-02 15:31:30 +0100 |
|---|---|---|
| committer | Thibaut Horel <thibaut.horel@gmail.com> | 2011-01-02 15:31:30 +0100 |
| commit | 2527ad301546ef2104db8f0e76f6f1cb462a3d73 (patch) | |
| tree | 1dcc6b98098bcfd368defab0b5d057e60e452acc | |
| parent | d90aec17e2201f256783a531c548dcc9857c889d (diff) | |
| download | alias-2527ad301546ef2104db8f0e76f6f1cb462a3d73.tar.gz | |
Get the roster when connected.
| -rw-r--r-- | webclient/basic.html | 9 | ||||
| -rw-r--r-- | webclient/lib/basic.js | 47 |
2 files changed, 41 insertions, 15 deletions
diff --git a/webclient/basic.html b/webclient/basic.html index 1d6d16f..c612c3c 100644 --- a/webclient/basic.html +++ b/webclient/basic.html @@ -16,7 +16,12 @@ <input type='button' id='connect' value='connect'> </form> </div> - <hr> - <div id='log'></div> + <hr/> + <div id='contacts' style="float:left; width:40%; height:100%"> + <h2>Contacts :</h2> + <ul> + </ul> + </div> + <div id='log' style="position:fixed; bottom:0px; width:100%; height:200px; overflow:scroll; border-top:1px solid black"></div> </body> </html> 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; |
