diff options
| -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; |
