sstrigler / JSJaC

JavaScript Jabber Client Library
Other
295 stars 86 forks source link

inherit throws javascript error #23

Closed ghost closed 13 years ago

ghost commented 13 years ago

I'm trying to bind to a connection that I've already created in PHP and it's not working. (Sadly, there are no examples anywhere that I could find on how to do this.)

Every time I try to connect, firebug returns:

this._keys is null reqstr += "key='"+this._keys.getKey()+"' ";

This is on line 4104 in the uncompressed version. The code I have to make this connection looks like this:

www.chat.attach = function (jid, sid, rid, url) {
    try {
        www.chat.jid = jid;
        www.chat.url = url;

        // get all the pieces of the jid separated
        var jid_object = new JSJaCJID(jid);
        www.chat.username = jid_object.getNode();
        www.chat.domain = jid_object.getDomain();
        www.chat.resource = jid_object.getResource();
        www.chat.id = www.chat.username + '@' + www.chat.domain;

        // generic args method for passing to jsjac
        var args = null;

        args = new Object();
        args.httpbase = www.chat.url;
        args.timerval = 2000;
        www.chat.connection = new JSJaCHttpBindingConnection(args);

        // register listeners
        www.chat.connection.registerHandler('message', function () {});
        www.chat.connection.registerHandler('presence', function () {});
        www.chat.connection.registerHandler('iq', function () {});
        www.chat.connection.registerHandler('onconnect', function () {});
        www.chat.connection.registerHandler('onerror', function () {});
        www.chat.connection.registerHandler('status_changed', function () {});
        www.chat.connection.registerHandler('ondisconnect', function () {});

        // attach to the existing session that we've been given by php
        args = new Object();
        args.username = www.chat.username;
        args.domain = www.chat.domain;
        args.resource = www.chat.resource;
        args.sid = sid;
        args.rid = rid;
        www.chat.connection.inherit(args);
    } catch (e) {
        console.log(e.toString());
    } finally {
        return false;
    }
}
sstrigler commented 13 years ago

inherit() does not work with keys enabled. To disable the key protection algorithm within JSJaCConfig.js set JSJaC_HAVEKEYS to false.

Sorry for the lack of documentation, trying to fill the gap soon.

Am 28.08.2011 um 16:35 schrieb paullckby reply@reply.github.com:

I'm trying to bind to a connection that I've already created in PHP and it's not working. (Sadly, there are no examples anywhere that I could find on how to do this.)

Every time I try to connect, firebug returns:

this._keys is null reqstr += "key='"+this._keys.getKey()+"' ";

This is on line 4104 in the uncompressed version. The code I have to make this connection looks like this:

www.chat.attach = function (jid, sid, rid, url) { try { www.chat.jid = jid; www.chat.url = url;

       // get all the pieces of the jid separated
       var jid_object = new JSJaCJID(jid);
       www.chat.username = jid_object.getNode();
       www.chat.domain = jid_object.getDomain();
       www.chat.resource = jid_object.getResource();
       www.chat.id = www.chat.username + '@' + www.chat.domain;

       // generic args method for passing to jsjac
       var args = null;

       args = new Object();
       args.httpbase = www.chat.url;
       args.timerval = 2000;
       www.chat.connection = new JSJaCHttpBindingConnection(args);

       // register listeners
       www.chat.connection.registerHandler('message', function () {});
       www.chat.connection.registerHandler('presence', function () {});
       www.chat.connection.registerHandler('iq', function () {});
       www.chat.connection.registerHandler('onconnect', function () {});
       www.chat.connection.registerHandler('onerror', function () {});
       www.chat.connection.registerHandler('status_changed', function () {});
       www.chat.connection.registerHandler('ondisconnect', function () {});

       // attach to the existing session that we've been given by php
       args = new Object();
       args.username = www.chat.username;
       args.domain = www.chat.domain;
       args.resource = www.chat.resource;
       args.sid = sid;
       args.rid = rid;
       www.chat.connection.inherit(args);
   } catch (e) {
       console.log(e.toString());
   } finally {
       return false;
   }

}

Reply to this email directly or view it on GitHub: https://github.com/sstrigler/JSJaC/issues/23

ghost commented 13 years ago

Thanks for the insanely fast feedback! Just for the records, so someone else searching this can find it, here's how I got it work with your advice. The only other change was that the RID had to be decremented once -- this is with ejabberd ad JAXL doing the initial connection.

www.chat.attach = function (jid, sid, rid, url) {
    try {
        www.chat.jid = jid;
        www.chat.url = url;

        // get all the pieces of the jid separated
        var jid_object = new JSJaCJID(jid);
        www.chat.username = jid_object.getNode();
        www.chat.domain = jid_object.getDomain();
        www.chat.resource = jid_object.getResource();
        www.chat.id = www.chat.username + '@' + www.chat.domain;

        // disable JSJAC keys for an inherit request
        JSJAC_HAVEKEYS = false;

        // generic args method for passing to jsjac
        var args = null;

        args = new Object();
        args.httpbase = www.chat.url;
        args.timerval = 2000;
        www.chat.connection = new JSJaCHttpBindingConnection(args);

        // register listeners
        www.chat.connection.registerHandler('message', function () {});
        www.chat.connection.registerHandler('presence', function () {});
        www.chat.connection.registerHandler('iq', function () {});
        www.chat.connection.registerHandler('onconnect', function () {
            // send a presence argument
            www.chat.connection.send(new JSJaCPresence());
        });
        www.chat.connection.registerHandler('onerror', function () {});
        www.chat.connection.registerHandler('status_changed', function () {});
        www.chat.connection.registerHandler('ondisconnect', function () {});

        // attach to the existing session that we've been given by php
        args = new Object();
        args.username = www.chat.username;
        args.domain = www.chat.domain;
        args.resource = www.chat.resource;
        args.sid = sid;
        args.rid = parseInt(rid) - 1;
        www.chat.connection.inherit(args);
    } catch (e) {
        console.log(e.toString());
    } finally {
        return false;
    }
}