0
votes

I'm using node-xmpp-client package to connect to an XMPP service. The service publishes messages when it receives them from some external source. My goal:

  1. Connect to the service
  2. Get authenticated
  3. Subscribe to some nodes that I'm interested in. (Node name is known)
  4. Receive stanza from the node to know new message has come in and handle it.

I'm referencing to the sample code here.

I have managed to connect to the service with code below. Does this automatically authenticate me to the server? I don't receive any "authenticate" event. If it doesn't, how do I explicitly request for authentication?

var client = new xmpp.Client({
    jid: '[email protected]',
    password: 'somepassword',
    host:'somehost',
    port:5222
})

Next, how do I subscribe to a publisher node? Should I do a client.send(new xmpp.Message(..))? If yes, how the xmpp.Message should be constructed? I can see the XMPP subscription iq in XMPP's web but have difficulty in mapping it back to node-xmpp's api.

<iq type='set'
    from='[email protected]/barracks'
    to='pubsub.shakespeare.lit'
    id='sub1'>
    <pubsub xmlns='http://jabber.org/protocol/pubsub'>
        <subscribe
            node='princely_musings'
            jid='[email protected]'/>
    </pubsub>
</iq>
1

1 Answers