I am trying to join a session, so if the page reloads, a new connection is not created:
// In the "Ready for document" document, check if jid.sid is set and cookies are deleted: If yes: conn.attach. Else connect:
$(document).ready(function() { var cookie_data = { jid: $.cookie('xmpp_jid'), sid: $.cookie('xmpp_sid'), rid: $.cookie('xmpp_rid') }; if(cookie_data.jid && cookie_data.sid && cookie_data.rid) { console.log("Cookies exists"); var conn = new Strophe.Connection('/xmpp-httpbind'); conn.attach(cookie_data.jid, cookie_data.sid, cookie_data.rid,function(status){ console.log(status); }); }else{ connect(); } }); function connect() { var conn = new Strophe.Connection('/xmpp-httpbind'); conn.connect('xxxxx','yyyyy',function(status) { if(status === Strophe.Status.CONNECTED) { var iq = $iq({type:'get'}).c('query',{xmlns:'jabber:iq:roster'}); Chat.connection.sendIQ(iq,Chat.on_roster); Chat.connection.addHandler(Chat.handle_message,null, "message", "chat"); Chat.connection.send($pres()); $.cookie('xmpp_jid', conn.jid, {path: '/'}); $.cookie('xmpp_sid', conn.sid, {path: '/'}); $.cookie('xmpp_rid', conn.rid+1, {path: '/'}); } }); Chat.connection = conn; } var Chat = { connection: null }
So:
1) Download the page, - Cookies created successfully - go to connect () - connection created successfully
2) Load the page again - Cookie values ββexist. The conn.attach callback returns the following:
Status-Code 8: ATTACHED then INVALID SID ERROR (404) then Status-Code 7: DISCONNECTING then Status-Code 6: DISCONNECTED
The problem is the "INVALID SID" error. Any solution?
source share