【发布时间】:2015-08-25 07:59:53
【问题描述】:
我正在使用 node-xmpp-server 作为聊天应用程序的 xmpp 服务器。作为客户端,我正在使用 Spark。我想将联系人添加到名册。我该怎么做?我在 ejabbberd 上运行并且它可以工作,但我需要实现一个代码。感谢您的任何建议!
我的服务器代码:
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() {
})
【问题讨论】:
标签: javascript node.js xmpp