我正在选择一个XMPP服务器,目前正在尝试NodeXMPP。
我安装了完整的NodeXMPP(核心,服务器,客户端,组件,依赖项...)。
让我感到惊奇的是我必须做所有的后端工作:让客户端彼此交流等。其他XMPP服务器(如tigase ejabberd等)从头开始处理这些东西。
我的微小实例: 我创建一个服务器并将客户端存储在一个数组中,然后在另一个客户端尝试发言时搜索一个客户端:
让我感到惊奇的是我必须做所有的后端工作:让客户端彼此交流等。其他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 的意义是什么呢?也许它是用于在其他 XMPP 服务器(如 prosody)上使用 NodeJS 的?