Resuming XMPP connection upon page refresh

2019-06-10 10:58发布

问题:

I am not able to maintain the connection on page refresh.

Initially upon every refresh Strophe connection object is lost. So, the first approach I took was reconnecting on refresh.

I am saving the JID, SID and RID in localStorage send the strophe attach call with saved details.

AuthHandler.attach_params(jid_frm_storage, sid_frm_storage, rid_frm_storage);

The attach callback is in actual AuthHandler Object that I have created and is logging perfectly that means it is okay to assume that my attach was successful but still I am not able to send or receive any messages

My second approach I saved the latest RID in locastorage and used it to attach as I came to know upon researching on already posted problems online that RID changes frequently. (Although please note I am saving RID only when either i send message or receive a message).

I also tried sending presence.

ConnectionHandler.connection.send($pres());

But no luck here either!

In my last approach I re-authorized, .i.e I connected and re-logged in and then sent the auth, still no luck.

How can I resume my connection upon refresh. What are the things That I need to do from Strophes end in order to reconnect and resume the same conversation.

NOTE: I am not that clear with how XMPP works internally but I have been able to push this far by learning-by-doing approach. I know it would be great to wait and learn a bit on xmpp before rushing forward but I can't afford that right now as we are prototyping fast.

Will really appreciate if steps required to accomplish this can be explained in detail.

回答1:

Solved this:

The best way to solve this is by saving the login credentials in localStorage (mind you it might not meet your security requirements, met mine though) and then make a proper connection again, but this time with same credentials as before.