I'm using node-XMPP for a chat application where two clients can chat with each other. but the problem is I'm getting data from one client to the server, but I don't know how to send data from the server to another client.
my server code is:
'use strict';
var xmpp = require('../index')
, c2s = null
, Client = require('node-xmpp-client')
, ltx = require('node-xmpp-core').ltx
, util = require('util');
var startServer = function(done) {
c2s = new xmpp.C2SServer({
port: 5222,
domain: 'localhost',
preferred: 'PLAIN'
})
c2s.on('connect', function(client) {
c2s.on('register', function(opts, cb) {
console.log("REGISTER");
cb(true);
});
client.on('authenticate', function(opts, cb) {
if ('secret' === opts.password) {
return cb(null, opts)
}
console.log('FAIL')
cb(false)
});
client.on('online', function() {
console.log('ONLINE')
});
client.on('stanza', function(stanza) {
console.log('STANZA', stanza.root().toString())
var from = stanza.attrs.from
stanza.attrs.from = stanza.attrs.to
stanza.attrs.to = from
client.send(stanza)
});
client.on('disconnect', function(jid) {
console.log("client DISCONNECT=>");
});
});
if (done) done()
};
startServer(function() {})
my client code is:
var Client = require('../index.js')
,util = require('util');
var client = new Client({
jid: process.argv[2],
password: process.argv[3],
host :"localhost",
port:5222,
reconnect :true
});
client.on('online', function() {
console.log('online');
});
client.on('error',function(err){
console.log("error=>"+err);
});
client.on('stanza', function(stanza) {
console.log('Incoming stanza: ', stanza.toString())
});
client.on('disconnect',function(){
console.log("server diconnected");
});
when I'm sending data from another client data come to the server but server Is not sending the data to the client.
Thanks in advance.
});