fulljid is empty after connection to BOSH service with XMPHP

Tag: strophe , bosh , xmpphp Author: xyjdream Date: 2012-11-13

I am trying to pre-bind an XMPP session via XMPHP and pass the rid/sid/jid to a strophe client to attach to the session.

connection code here:

$conn = new CIRCUIT_BOSH('server.com', 7070, $username, $pass, $resource, 'server.com', $printlog=true, $loglevel=XMPPHP_Log::LEVEL_VERBOSE);
$conn->autoSubscribe();

try{
  $conn->connect('http://xmpp.server.com/http-bind', 1, true);
  $log->lwrite('Connected!');
}catch(XMPPHP_Exception $e){
  die($e->getMessage());
}

I am getting the rid and sid but the fulljid in the $conn object stays empty and I cant see a session started on my openfire admin console.

If I create the jid manually by using the given resource and passing jid/rid/sid to strophe to use in attach, I get the ATTACHED status and I see calls from the client to the BOSH ip but I still dont see a session and I cant use the connection.

Strophe Client Code:

Called on document ready:

var sid = $.cookie('sid');
var rid = $.cookie('rid');
var jid = $.cookie('jid');
    $(document).trigger('attach', {
      sid: sid,
      rid: rid,
      jid: jid,
    });

$(document).bind('attach', function (ev, data) {

    var conn = new Strophe.Connection(
        "http://xmpp.server.com/http-bind");

    conn.attach(data.jid, data.sid, data.rid, function (status) {
        if (status === Strophe.Status.CONNECTED) {
            $(document).trigger('connected');
        } else if (status === Strophe.Status.DISCONNECTED) {
            $(document).trigger('disconnected');
        } else if (status === Strophe.Status.ATTACHED){
            $(document).trigger('attached');
        }
    });

    Object.connection = conn;

}); 

I think the problem starts on the XMPPHP side which is not creating the session properly. 'attached' is triggered but never 'connected', is status 'connected' supposed to be sent? What am I missing?

When attaching to a session only the ATTACHED status will be returned. You can check to see what is being sent and received by providing functions for xmlOutput and xmlInput. Something like conn.xmlOutput = function (body) { console.log(body); }
Thanks. I just figured that this behavior is as expected.

Best Answer

Ok, solved, I saw that XMPPHP lib didn't create a session at all on the openfire server, so I wrote a simple test for the XMPP class which was good and created the session, and for the XMPP_BOSH class that didn't manage create one. Then I saw the issue report here: http://code.google.com/p/xmpphp/issues/detail?id=47 comment no.9 worked, it fixed the issue by copying the processUntil() function from the XMLStream.php to BOSH.php, still can't figure out why this is working. Then I found I had an overlapping bug also with some of the passwords set for users on the openfire server. These passwords contained these ! # % ^ characters, for some reason the XMPP_BOSH is sending the password corrupted or changed so I got Auth Failed exception. Changing the password fixed the issue and I can now attach to the session XMPPHP created with the Strophe.js library.