Is Node-XMPP useless ? Choosing XMPP server

1.2k views Asked by At

I am choosing a XMPP server, and currently trying NodeXMPP. I installed complete NodeXMPP (core,server,client,component,dependencies...).

What is striking me is that I have to do all the back-end stuff : making clients speak to each other etc. Other XMPP servers (tigase ejabberd ...) do this stuff from scratch.

My tiny instance : I create a server and store clients in an array, then search for a client when an other try to speak :

var xmpp = require('../index')

var c2s = new xmpp.C2SServer({
    port: 5222,
    domain: 'localhost'
})

var clients = new Array();

c2s.on('connect', function(client) {
    client.on('authenticate', function(opts, cb) {
        console.log('AUTH' + opts.jid + ' -> ' +opts.password)
        clients.push(client);
    })
    client.on('stanza', function(stanza) {
        if (stanza.is('message') && (stanza.attrs.type !== 'error')) {
            var interlocuteur = getClient(stanza.attrs.to)
            if (interlocuteur)
                interlocuteur.send(stanza)
        }
    })
    client.on('disconnect', function() {
        console.log('DISCONNECT')
    })
    client.on('online', function() {
        console.log('ONLINE')
        client.send(new xmpp.Message({ type: 'chat' }).c('body').t('Hello there, little client.'))
    })
})

And my question : do I really need to code these basic operations by myself ? If so, what is the point of Node-XMPP ? Maybe it's to use NodeJS over an other XMPP server like prosody ?

1

There are 1 answers

0
smokku On

node-xmpp is "just" a library of components that allows you to build your own XMPP client, component or even server.

Being a library, it does not provide a complete solution for particular use case, but a set of building blocks allowing to build one.

If you are in the market of a complete, already made, boxed XMPP server solution, installing Prosody is a good bet. :^)