Finding Problem with get the session
jitui2i opened this issue Β· comments
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 ...