0
votes

I have used the example from crossdomain to connect to my local openfire xmpp service. Just changes the BOSH url to accomodate my local openfire service.

What I tested so I know openfire itself works. I can successfully connect with Pidgin.

(The site runs within jetty)

The (actual) openfire installation runs on localhost

The strophe javascript gets executed after the form is submitted form field: #jid = 'admin@localhost' form field: #pass = 'mypassword'

The functions rawInput and rawOutput are omitted they are simply logging what is transferred.

var BOSH_SERVICE=http://localhost:8080/xmpp-bosh

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

There is an error when connecting the example gives me the following log output:

Strophe is connecting.
SENT: <body rid='4005617322' xmlns='http://jabber.org/protocol/httpbind' to='localhost' 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'/>
RECV: <body xmlns='http://jabber.org/protocol/httpbind' authid='' condition='remote-stream-error' inactivity='600' polling='10' requests='2' secure='false' sid='orw55e6kuyZ0F-CFgnxXWMzG' type='terminate' wait='60'><starttls xmlns=''/><mechanisms xmlns=''><mechanism>DIGEST-MD5</mechanism><mechanism>PLAIN</mechanism><mechanism>CRAM-MD5</mechanism></mechanisms><compression xmlns=''><method>zlib</method></compression><auth xmlns=''/><register xmlns=''/></body>
Strophe failed to connect.
Strophe is disconnected.

Any ideas how to overcome this issue? ( have tested with pidgin IM and works )

2

2 Answers

0
votes

Try enabling the Strophe debugging to see more log entries

Strophe.log = function(level, msg) {
    console.log(level + ' : ' + msg);
};

then check the Openfire's error, warn and even info logs.

0
votes

You can probably overcome this issue by getting the Openfire developers to fix their BOSH implementation. (Or maybe just update your Openfire installation.)

The Server response is just wrong.

<body xmlns='http://jabber.org/protocol/httpbind' authid='' condition='remote-stream-error' inactivity='600' polling='10' requests='2' secure='false' sid='orw55e6kuyZ0F-CFgnxXWMzG' type='terminate' wait='60'>
    <starttls xmlns=''/>
    <mechanisms xmlns=''>
        <mechanism>DIGEST-MD5</mechanism>
        <mechanism>PLAIN</mechanism>
        <mechanism>CRAM-MD5</mechanism>
    </mechanisms>
    <compression xmlns=''>
        <method>zlib</method>
    </compression>
    <auth xmlns=''/>
    <register xmlns=''/>
</body>

These are contents of a stream:features tag inside of a body tag. The body tag has type='terminate', so it tells the client to close the connection, which Strophe does. Also, all namespaces are missing.

What Openfire SHOULD have sent is something like this:

<body xmlns='http://jabber.org/protocol/httpbind' xmlns:xmpp='urn:xmpp:xbosh' xmlns:stream='http://etherx.jabber.org/streams' sid='0630f9b79631f5ecb66d26313d34ce227262cf5d' wait='60' requests='2' inactivity='30' maxpause='120' polling='2' ver='1.8' from='localhost' secure='false' authid='2869001480' xmpp:version='1.0'>
    <stream:features xmlns:stream='http://etherx.jabber.org/streams'>
        <mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
            <mechanism>DIGEST-MD5</mechanism>
            <mechanism>PLAIN</mechanism>
            <mechanism>SCRAM-SHA-1</mechanism>
        </mechanisms>
        <compression xmlns=''>
            <method>zlib</method>
        </compression>
        <register xmlns='http://jabber.org/features/iq-register'/>
    </stream:features>
</body>

(stream:features inside of the body tag).

tl;dr StropheJS closing the connection is the expected behaviour, The BOSH plugin of your Openfire version is probably broken.