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

Attach to existing session #17

Open
baliganikhil opened this issue Aug 14, 2012 · 4 comments
Open

Attach to existing session #17

baliganikhil opened this issue Aug 14, 2012 · 4 comments

Comments

@baliganikhil
Copy link

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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
Copy link

@maxpowel can you elaborate more on your approach?

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

3 participants