From 6a35fe6789f0c772833497b9b5e4a72354c94ad2 Mon Sep 17 00:00:00 2001 From: Matthieu Lalonde Date: Sun, 8 Aug 2010 21:16:40 +0200 Subject: [PATCH] more decent doc --- README.md | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/README.md b/README.md index 7da206f..f1b6543 100644 --- a/README.md +++ b/README.md @@ -38,3 +38,62 @@ You have to edit a new file in `test/conf.js` : Then, you can launch test : node test/test.js + +API +--- + +Client handle all the xmpp stack with object, callback, event and handlers. All in async. + +### Client ### + +The first object is the client : + + var c = new Client({ + jid: 'bob@jabber.org', + password: 'beuha' + }, function() { + sys.debug("I'm connected"); + }); +You instiante it with xmpp params and callback, tirggered when connection is done, and roster fetched. All your work should be inside the callback, outside, you don't know your state. + +The client throw events : + + * _presence_ + * _presence:error_ + * _message_ + +### IQ ### +Iq is handled quietly. You can ask someone with a callback, for the response. + + var jabber = this; + this.iq(new xmpp.Element('query', {xmlns: 'jabber:iq:roster'}), function(iq) { + iq.getChild('query', 'jabber:iq:roster').children.forEach(function(child) { + //iterating over evrybody + sys.debug(child.attrs.jid); + }); + }); + +Answering a distant iq is handled with an handler. Default object handles : + + * _http://jabber.org/protocol/disco#info_ + * _jabber:iq:last_ + * _jabber:iq:version_ + +Here is an example : + + var jabber = this; + this.registerIqHandler('jabber:iq:last', function(stanza) { + jabber.resultIq(stanza, new xmpp.Element('query', { + xmlns: 'jabber:iq:last', seconds:'1'}) + .tree() + ); + }); + + +Not handled iq throws an event : _iq:unknow_ + +### Room ### + +Just like Client, room is created with a callback, triggered when presence is return from the server. + + this.room('beuha', function(status) {})