I'm using node-xmpp-server as a xmpp server for a chat application.As a client i'm using Spark.I want to add contacts to roster.How can i do this?I've run on ejabbberd and iti work but i need to implement a code.Thanks for any advice!
My server code:
var startServer = function(done) {
// Sets up the server.
server = new xmpp.C2S.TCPServer({
port: 5222,
domain: 'localhost'
})
// On connection event. When a client connects.
server.on('connection', function(client) {
// That's the way you add mods to a given server.
// Allows the developer to register the jid against anything they want
client.on('register', function(opts, cb) {
console.log('REGISTER')
console.log(cb);
cb(false)
})
// Allows the developer to authenticate users against anything they want.
client.on('authenticate', function(opts, cb) {
//console.log('server:', opts.username, opts.password, 'AUTHENTICATING')
if (opts.password === 'secret') {
//console.log('server:', opts.username, 'AUTH OK')
cb(null, opts)
}
else {
//console.log('server:', opts.username, 'AUTH FAIL')
cb(false)
}
})
client.on('online', function() {
console.log('ONLINE')
})
// Stanza handling
client.on('stanza', function(stanza) {
console.log('server:', client.jid.local, 'stanza', stanza.toString())
//var from = stanza.attrs.from
// stanza.attrs.from = stanza.attrs.to
//stanza.attrs.to = from
if (stanza.is('message') && (stanza.attrs.type !== 'error')) {
client.send(stanza);
}
else {
client.send(stanza);
}
})
// On Disconnect event. When a client disconnects
client.on('disconnect', function() {
console.log('server:', client.jid.local, 'DISCONNECT')
})
})
server.on('listening', done)
}
startServer(function() {
})