通过 Bosh 进行的 Openfire 带内注册无法与 Strophe/Strophe.register.js 一起使用

Posted

技术标签:

【中文标题】通过 Bosh 进行的 Openfire 带内注册无法与 Strophe/Strophe.register.js 一起使用【英文标题】:Openfire in-band-registration via Bosh not working with Strophe/Strophe.register.js 【发布时间】:2014-09-18 15:18:45 【问题描述】:

我之前问过一个关于 ejabberd 的类似问题,但是 ejabberd 给出了其他问题,所以我切换到了 openfire。为了不让最初的问题变得混乱,我决定创建一个新问题,因为这个问题与 openfire 相关,并且与我遇到的 ejabberd 问题不同。

那么问题来了:

我有一个 strophe.js xmpp 客户端,它连接到在亚马逊云上运行的 openfire 3.10.0 alpha 服务器。我需要 3.10.0 alpha 超过 3.9.3,因为前者包含 bfix,但后者不包含。无论如何,由于这是一个 strophe 客户端,我启用了 bosh,我可以看到它在 myAWSDNS.com 上运行:7070。我可以使用这个 bosh 服务和现有帐户通过我的客户端连接到服务器,并来回发送消息,因此它似乎运行正常。

我还想添加带内注册,为此我使用 strophe.register.js

这是我使用的代码:

 var tempConn = new Strophe.Connection("http//myAWSDNS.com:7070/http-bind/");
    tempConn.register.connect("myAWSDNS.com", function (status) 
    if (status === Strophe.Status.REGISTER) 
        // fill out the fields
        connection.register.fields.username = "juliet";
        connection.register.fields.password = "R0m30";
        // calling submit will continue the registration process
        connection.register.submit();
     else if (status === Strophe.Status.REGISTERED) 
        console.log("registered!");
        // calling login will authenticate the registered JID.
        connection.authenticate();
     else if (status === Strophe.Status.CONFLICT) 
        console.log("Contact already existed!");
     else if (status === Strophe.Status.NOTACCEPTABLE) 
        console.log("Registration form not properly filled out.")
     else if (status === Strophe.Status.REGIFAIL) 
        console.log("The Server does not support In-Band Registration")
     else if (status === Strophe.Status.CONNECTED) 
        // do something after successful authentication
     else 
        // Do other stuff
    
);

这似乎工作正常,因为它进入第一个 if 括号 (status === Strophe.Status.REGISTER),并尝试设置 connection.register.fields.username = "juliet";

但是,在这里,当执行该行时,它会跳转到 strophe.js 第 2476 行:

if (this.connect_callback) 
        try 
            this.connect_callback(status, condition);
         catch (err) 
            Strophe.error("User connection callback caused an " +
                          "exception: " + err);
        
    

其中 2476 是 catch(err) ...... 括号中的代码。

如果我检查err,这就是我得到的:

所以消息:connection is not defined 很明显,注册不起作用,我不知道为什么。有人对此有意见吗?

谢谢,最好的问候,

克里斯

【问题讨论】:

【参考方案1】:

您可能不喜欢这个答案...connection == undefined 的原因是因为您将其命名为tempConn

【讨论】:

我不喜欢或不喜欢它,我不明白。 tempConn 是某种保留名称吗?所以你是说我只需要给它另一个名字? 哦,哎呀,我想明白了哈哈 哈哈,很公平,这可能是阻止您尝试使用 ejabberd 工作的原因。另外,不要忘记将答案标记为已接受,干杯! 是的,我会看看 ejabberd 是否也能正常工作,尽管我确实遇到了与带内注册无关的奇怪行为。感谢您的帮助!

以上是关于通过 Bosh 进行的 Openfire 带内注册无法与 Strophe/Strophe.register.js 一起使用的主要内容,如果未能解决你的问题,请参考以下文章

带内账户注册后怎么办

Bosh 使用 openfire 设置

Strophe 与 bosh 和 openfire 的连接错误

Strophe 无法通过 BOSH 服务器连接到 Facebook

strophe 无法通过 websocket 连接 openfire

使用 Openfire 中的用户服务通过 iOS 的 xmpp 框架注册新用户