Manish Kumar
Manish Kumar

Reputation: 10492

ejabberd XMPP connection failed using strophejs

I am trying to run THIS XMPP JS code using ejabberd on server side. Here is my connection code:

$(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;
});

I am getting status = 1. and after few time later it starts keep showing : Uncaught Error: 11, flXHR::abort(): Failed, The abort() call failed to complete.

My ejabberd is running on http://localhost:5280/admin/ and admin@ejab is admin user.

Here is full code:

<!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();
    }
    });
});

ouput is :

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'/>

Upvotes: 1

Views: 1660

Answers (1)

pny_hk
pny_hk

Reputation: 141

status = 1 means connecting. It mostly means BOSH server cannot be reached.

Type in http://localhost:5280/http-bind/ at Chrome to see if you can really reach the BOSH server.

If your server is really host at localhost (your computer where hello.html stored), you can comment out the flXHR.js and strophe.flxhr.js at hello.html's header as they are for cross domain access.

e.g. hello.html at your desktop and using a domain(xmpp server) that host at another computer which are not allowed by Chrome due to cross domain access security already.

If both hello.html and xmpp server are located at the same computer, it won't have cross domain issue.

Anyway, these 2 files seem not able to overcome the cross domain access limit set by Chrome browser a few years back. Use Chrome's parameter "--disable-web-security" can provide cross domain access for test.

Lastly, at Chrome browser, right click to select "Inspect Element" -> Network, reload the hello.html and login to check those http-bind access. They should give hint on what goes wrong.

Upvotes: 1

Related Questions