我正在选择 XMPP 服务器,目前正在尝试 NodeXMPP。我安装了完整的 NodeXMPP(核心、服务器、客户端、组件、依赖项...)。
令我吃惊的是,我必须做所有的后端工作:让客户端相互交谈等。其他 XMPP 服务器(tigase ejabberd ...)从头开始做这些工作。
我的小实例:我创建了一个服务器并将客户端存储在一个数组中,然后在另一个尝试说话时搜索一个客户端:
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.'))
})
})
还有我的问题:我真的需要自己编写这些基本操作吗?如果是这样,Node-XMPP 的意义何在?也许是在像 prosody 这样的其他 XMPP 服务器上使用 NodeJS?