maxpowel / jQuery-XMPP-plugin

Javascript library for the XMMP protocol
http://plugins.jquery.com/project/xmpp-lib
163 stars 50 forks source link

Attach to existing session #17

Open baliganikhil opened 12 years ago

baliganikhil commented 12 years ago

Let's assume that I open the chat application in one tab and login and connect. I am now connected and able to chat. Now, I will open the same chat page in another tab of the same browser - Naturally I expect to stay connected and continue chatting from the new tab as well.

I am not sure of how to proceed to achieve this. I assumed that the 'attach' function should be used for this. If yes, then I did try that. What I did was, in the first tab, whatever jid, sid and rid were found, were passed to the attach function in the second tab as well. However, I got some error (post error). Am I doing something wrong? How do we achieve this?

maxpowel commented 12 years ago

Hi! I was thinking about your problem. The first problem is comunication is now allowed between tabs (for security reasons). Your post error could be caused by an invalid RID (a number that increases when you do a request). To continue the session you should be able to send the actual RID and SID (connection idenficator) but I don't know how.

Other option is entablish a new connection in background and fetch last messages from server (like gmail does)

baliganikhil commented 12 years ago

Hi, Actually I am sending the same rid and other details. What I was doing was, in tab 1, I was storing all the Id's in the browser by using localStorage and in tab 2, I was retrieving them from localStorage. So no matter what was stored, I was getting the same details. It was still failing.

Setting a new connection would also not be a bad idea, but you are asking for the username and password in the new tab as well, right? How do we bypass that?

maxpowel commented 12 years ago

Sync two "sessions" will cause you a lot of headache since the plugin will do request every 60 seconds (or the defined wait time) and on every request you should "sync" all tabs.

To set a new connection I usually generates a token that is saved into a cookie. The most easy way is save the encrypted password (wich is a step in md5-digest login) and the use it directly in a custom login method. You can save this token: var A1 = MD5.hash(username + ":" + realm + ":" + options.password) + ":" + nonce + ":" + cnonce;

A better way is configure your server to allow custom tokens. This is when you login, you receive a token wich authenticates the user (with a expiration time). Then save it in a cookie and make a custon login method. I used this method with openfire

majimboo commented 10 years ago

@maxpowel can you elaborate more on your approach?