Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finding Problem with get the session #114

Open
jitui2i opened this issue Apr 3, 2014 · 0 comments
Open

Finding Problem with get the session #114

jitui2i opened this issue Apr 3, 2014 · 0 comments

Comments

@jitui2i
Copy link

jitui2i commented Apr 3, 2014

I Have A login page and chat page in another tab so when i m going to there the connection object seems to be null how could we get that connection object there

Here Is Below My code 👍
var Connection = (function(self, $) {
var obj = null, connection = null;
console.log(self);
self.connect = function(options) {
connection = new Strophe.Connection(options.url);
connection.connect(options.jUserId, options.password, self.onConnect);
console.log(connection);
alert(connection);
};
self.onConnect = function (status) {
if (status == Strophe.Status.CONNECTING) {
self.debug('Strophe is connecting.');
} else if (status == Strophe.Status.CONNFAIL) {
self.debug('Strophe failed to connect.');
} else if (status == Strophe.Status.DISCONNECTING) {
self.debug('Strophe is disconnecting.');
} else if (status == Strophe.Status.DISCONNECTED) {
self.debug('Strophe is disconnected.');
} else if (status == Strophe.Status.CONNECTED) {
self.debug('Strophe is connected.');
//get roster

        connection.addHandler(messageReceived, null, "message", "chat");

        // handle presence
        connection.addHandler(presenceReceived, null, "presence");  
        console.log(connection);


        //self.connection.disconnect();
    }
}
function messageReceived(msg) {
    console.log(msg);
}
function presenceReceived(presence) {
    console.log(presence);
}
self.debug = function(txt) {
    if(window.console && console.debug) {
        console.log(txt);
    }
}
self.getConnection = function () {
    console.log( connection);
    return self.connection;
}
$(window).unload(function() {
    console.log("----this is the hell out of m");
    connection.pause();
    console.log(connection);
      if( connection != null ){
            $.cookie("jid",connection.jid);
            $.cookie("sid", connection.sid);
            $.cookie("rid", connection.rid);
       } else {
           $.cookie.del("jid");
            $.cookie.del("sid");
            $.cookie.del("rid");
       }
    });

return self;

}(Connection || {}, jQuery));

and while chat there is my js beeing like that 👍

$(document).ready(function() {

alert($('#jid').val());
alert( $.cookie("connection") );
var connection = null;
$.cookie.raw = true;
var jid = $.cookie("jid");
var sid =  $.cookie("sid");
var rid = $.cookie("rid");
console.log(decodeURIComponent(jid)+"====="+rid+"====="+sid);
connection = new Strophe.Connection("http://localhost:7070/http-bind");
rid = 2599162309;
// uncomment for extra debugging
// Strophe.log = function (lvl, msg) { log(msg); };
connection.rawInput = rawInput; 
connection.rawOutput = rawOutput; 
connection.attach(jid, sid, rid, onConnect) 
//debugging 
function rawInput(data) {
    console.log('RECV: ' + data);
};
function rawOutput(data) {
    console.log('SEND: ' + data);
}

    // set up handler

function onConnect(status) {
        console.log("----on Connect status is here");
        console.log(status);
        alert(status);
    }

});

But here the response is been empty here while retrieving can you please help me out of this ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant