404 (Invalid SID value) in Strophe while using attach()

Viewed 1281

I have searched in google and some similar questions on stack overflow. But I am not getting any solution.

Basically, I want to persist connection across web pages in my application. For this I am using cookies. I store SID and RID in cookies and use them for attaching the session again.

Below is my code.

this.openConnection = function(){
        if (chatObj.connection != null) return;


        var jid = chatObj.userName + '@' + chatObj.openfireDomainURL; // Bare JID
        var sid = Cookies.get(chatObj.userName + '_sid'); // Session Identifier
        var rid = Cookies.get(chatObj.userName + '_rid'); // Request Identifier

        var connection = new Strophe.Connection(chatObj.xmppHttpBindURL);
        chatObj.connection = connection;

        if(chatObj.isEmpty(sid) && chatObj.isEmpty(rid)){
            connection.connect(jid, chatObj.password, chatObj.onConnection);
        } else {
            // parseInt(rid,10) + 1
            var rid = parseInt(rid) + parseInt(1);
            connection.attach(jid, sid, rid, chatObj.onConnection);
        }
    };

    this.onConnection = function(status) {
        if (status === Strophe.Status.CONNECTED) {
            chatObj.log("CONNECTED ");
            //Cookies.set(chatObj.userName + '_sid', chatObj.connection.sid);
            //Cookies.set(chatObj.userName + '_rid', chatObj.connection.rid);
            jQuery(document).trigger('connected');
        } else if (status === Strophe.Status.DISCONNECTED) {
            jQuery(document).trigger('disconnected');
            chatObj.log("DISCONNECTED ");
        } else if (status === Strophe.Status.CONNFAIL) {
            chatObj.log("CONNFAIL ");
        } else if (status === Strophe.Status.AUTHENTICATING) {
            chatObj.log("AUTHENTICATING ");
        } else if (status === Strophe.Status.AUTHFAIL) {
            chatObj.log("AUTHFAIL ");
        } else if (status === Strophe.Status.ERROR) {
            chatObj.log("ERROR ");
        } else if (status === Strophe.Status.ATTACHED){
            chatObj.log("ATTACHED ");
            jQuery(document).trigger('connected');
        } else if (status === Strophe.Status.CONNFAIL){
            chatObj.log("CONNFAIL ");
        }
    };


$(window).unload(function() {
    console.log("widows unload ");
    if( chatObj.connection != null ){
        console.log("set cookies ");
        Cookies.set(chatObj.userName + '_sid', chatObj.connection.sid);
        Cookies.set(chatObj.userName + '_rid', chatObj.connection.rid);
    } else {
//        Cookies.remove(chatObj.userName + '_sid');
//        Cookies.remove(chatObj.userName + '_rid');
    }
});

404 Invalid SID value in Strophe while using attach()

I tried using windows unload but it does not work. I still get the same error.

2 Answers

I was also facing the same issue while connecting to the XMPP server. *

I was using Strophe version 1.2.2.

*

After using the current version, this issue fixed for me.

Related