node.jsejabberdnode-xmpp

how to receive message from ejabberd client to node-xmpp


how to use node-xmpp to receive message from client...?

i already known how to sent message

here the sample code how to send message...

var net = require("net");
var xmpp = require('node-xmpp');

var server = net.createServer(
        function(socket) {

                socket.setEncoding("utf8");
                socket.on('data',function(data) {
                        chat(data,socket);
                }); 
        }
);
server.listen(3000);

var chat = function(data,socket) {
        var cl = new xmpp.Client({ jid: 'admin@mine',password: '12345' });

        cl.on('online',
               function() {
                           cl.send(new xmpp.Element('message',
                                                    { to: 'test@mine',
                                                      type: 'chat'}).
                                   c('body').
                                   t(data));


                   // nodejs has nothing left to do and will exit
                   cl.end();
               });
}

Solution

  • cl.addListener('stanza', function(stanza) {
        connection.write(stanza.children[1].children);
        console.log(stanza.children[1].children);
    });