Node-XMPP C2SSERVER连接问题



我正在使用node-xmpp库与安装在ubuntu上的ejabberd服务器进行通信。

我有以下脚本要在服务器中注册和执行操作。

var xmpp          = require("node-xmpp");
var c2s = new xmpp.C2SServer({
    port: 5223,
    domain: 'domain.com'
});
c2s.on('connect', function(client) {
    console.log('connect ??? ++++++++');
    c2s.on('register', function(opts, cb) {
        console.log('REGISTER')
        cb(true)
    })
    client.on('authenticate', function(opts, cb) {
        console.log('AUTH' + opts.jid + ' -> ' +opts.password)
        cb(null) // cb(false)
    })
    client.on('disconnect', function() {
        console.log('DISCONNECT')
    })
});

我可以在服务器中看到连接消息。但是它没有调用注册活动。

但是,我在5222端口中有另一个Ejabberd实例,该实例可用于Autium XMPP客户端的注册。

只需使用cb(false) ..在寄存器事件中更改cb(true)

xmpp.C2SServer是您编写自己的服务器的构建块。

如果要连接到现有的XMPP服务器,则需要使用:

import xmpp from 'node-xmpp-client'
const client = new xmpp.Client( ... )

然后关注XEP-0077在服务器上注册一个帐户。

最新更新