使用strophejs时,ejabberd XMPP连接失败

时间:2015-09-05 16:36:34

标签: xmpp ejabberd strophe

我正在尝试在服务器端使用ejabberd运行THIS XMPP JS代码。这是我的连接代码:

$(document).bind('connect', function (ev, data) {
    console.log("connect "+JSON.stringify(data));
    var conn = new Strophe.Connection("http://localhost:5280/http-bind");

    conn.connect(data.jid, data.password, function (status) {
        console.log("status"+status);
        if (status === Strophe.Status.CONNECTED) {
            $(document).trigger('connected');
        } else if (status === Strophe.Status.DISCONNECTED) {
            $(document).trigger('disconnected');
        }
    });

    Hello.connection = conn;
});

我得到了status = 1。几小时后它开始继续显示: Uncaught Error: 11, flXHR::abort(): Failed, The abort() call failed to complete.

我的ejabberd正在http://localhost:5280/admin/上运行,admin@ejab是管理员用户。

以下是完整代码:

<!DOCTYPE html>
<html>
  <head>
    <title>Strophe.js Basic Example</title>
    <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js'></script>
    <script src='../strophe.js'></script>
<!--    <script src='scripts/flXHR.js'></script>
    <script src='scripts/strophe.flxhr.js'></script>-->
    <script src='basic.js'></script>
  </head>
  <body>
    <div id='login' style='text-align: center'>
      <form name='cred'>
        <label for='jid'>JID:</label>
        <input type='text' id='jid'>
        <label for='pass'>Password:</label>
        <input type='password' id='pass'>
        <input type='button' id='connect' value='connect'>
      </form>
    </div>
    <hr>
    <div id='log'></div>
  </body>
</html>

basic.js

var BOSH_SERVICE = 'http://localhost:5222/http-bind';
var connection = null;

function log(msg) 
{
    $('#log').append('<div></div>').append(document.createTextNode(msg));
}

function rawInput(data)
{
    log('RECV: ' + data);
}

function rawOutput(data)
{
    log('SENT: ' + data);
}

function onConnect(status)
{
    if (status == Strophe.Status.CONNECTING) {
    log('Strophe is connecting.');
    } else if (status == Strophe.Status.CONNFAIL) {
    log('Strophe failed to connect.');
    $('#connect').get(0).value = 'connect';
    } else if (status == Strophe.Status.DISCONNECTING) {
    log('Strophe is disconnecting.');
    } else if (status == Strophe.Status.DISCONNECTED) {
    log('Strophe is disconnected.');
    $('#connect').get(0).value = 'connect';
    } else if (status == Strophe.Status.CONNECTED) {
    log('Strophe is connected.');
    connection.disconnect();
    }
}

$(document).ready(function () {
    connection = new Strophe.Connection(BOSH_SERVICE);
    connection.rawInput = rawInput;
    connection.rawOutput = rawOutput;

    $('#connect').bind('click', function () {
    var button = $('#connect').get(0);
    if (button.value == 'connect') {
        button.value = 'disconnect';

        connection.connect($('#jid').get(0).value,
                   $('#pass').get(0).value,
                   onConnect);
    } else {
        button.value = 'connect';
        connection.disconnect();
    }
    });
});

输出是:

Strophe is connecting.
SENT: <body rid='745165534' xmlns='http://jabber.org/protocol/httpbind' to='ejab' xml:lang='en' wait='60' hold='1' content='text/xml; charset=utf-8' ver='1.6' xmpp:version='1.0' xmlns:xmpp='urn:xmpp:xbosh'/>

0 个答案:

没有答案