如果刷新页面,则重置XMPP连接 [英] reset the XMPP connection if the page gets refreshed

查看:119
本文介绍了如果刷新页面,则重置XMPP连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的ejabberd服务器上使用javascript与XMPP建立strophe连接,我能够在页面加载时建立连接,并且在单击断开连接按钮时能够断开连接。

I am trying to create a strophe connection with XMPP using javascript with my ejabberd server , i am able to make a connection when the page loads and able to disconnect when the disconnect button is clicked.

现在的问题是,连接仍然有效,如果用户不小心刷新了页面,则我的JavaScript试图再次建立连接,并对此做出响应。 (仅是因为以前的连接可能仍然存在)

now the problem is , the connection is alive and if a user accidently refresh the page , then my javascript is trying to make the connect again , and in response to that i am getting. (its just because the previous connection might be still alive )

<body xmlns='http://jabber.org/protocol/httpbind'>
    <failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
            <not-authorized/>
    </failure>
</body>

过一会儿,如果我再次刷新页面,则连接将成功建立,那么我怎么能如果页面被意外刷新,请重置连接,以便用户获得无缝连接。

and after a while if i refresh the page again then connection will get established successfully, so how can i reset the connection in case if the page is accidently refreshed so that a user get a seamless connection.

推荐答案

该连接在整个页面刷新过程中都有效,请保持 jid sid rid 变量,以及您需要的任何其他状态,例如sessionStorage。然后,您可以使用 attach() 恢复XMPP会话。

If you want to have the connection survive across a page refresh, keep the jid, sid and rid variables, along with any other state you need, in something like sessionStorage. You can then use attach() to resume the XMPP session.

这篇关于如果刷新页面,则重置XMPP连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆