Strophe.js注册插件不起作用

时间:2014-01-16 08:55:33

标签: javascript xmpp strophe

我在远程位置托管了Ejabberd服务器。我试图使用Strophe.js注册插件注册新帐户我找不到为什么这不起作用。以下是我写的代码

    var connection = new Strophe.Connection("http://ip-address:5222/http-bind");
    var callback = function (status) {
        alert(Strophe.Status.REGISTER); // Returning me 10
        if (status === Strophe.Status.REGISTER) {
            alert("Entered");
            connection.register.fields.username = "hello";
            connection.register.fields.password = "hello";
            connection.register.submit();
        } else if (status === Strophe.Status.REGISTERED) {
            alert("registered!");
            connection.authenticate();
        } else if (status === Strophe.Status.CONNECTED) {
            alert("logged in!");
        } else {
            // Sometimes execution entering into this block.
            document.body.innerHTML = (JSON.stringify(status));
        }
    };
    connection.register.connect("localhost", callback);

要添加到此的任何额外代码或我必须执行的任何修复都可以使其工作。请帮帮我。 Strophe.js文档很糟糕。

2 个答案:

答案 0 :(得分:2)

strophe.register.js 中,转到第215行并根据以下代码进行更改。

 /*if (register.length === 0) {
            that._changeConnectStatus(Strophe.Status.REGIFAIL, null);
            return;
        } else */
this.enabled = true;

尝试上面一个。

答案 1 :(得分:2)

var connection = new Strophe.Connection("http://ip-address:5222/http-bind/");

最后需要进行尾随斜杠。