Strophe sending double request on page unload

断了今生、忘了曾经 提交于 2019-12-21 19:30:13

问题


I have written an XMPP client with jQuery+Strophe. It all works well (1-on-1, presence, MUC, etc) and is contained within a jQuery-plugin. However, when the page unloads, it sends 2 final requests with the same rid. It only recently became a problem when I started working on session attachment.

Here is an example of the Firebug console:

Here, I just logged in and immediately refreshed the page. The first post you see is the initial presence stanza after the login. After that request, a new BOSH request has started to keep a connection open to the server. This request is aborted when I refresh the page. So far, everything goes as I expected.

However, after the aborted request, strophe sends yet another request with that exact same RID. The final request is sent from strophe for (I suppose) good manners and not relevant to the problem. However its response indicates that openfire (the XMPP server) killed the session in an attempt to protect the account.

I have looked at my code and cannot find any request made on my behalf. I'm fairly certain that strophe sends this request. However, it must come from something I did since my initial prototype did not have that problem (in fact, I often had to manually kill sessions on the admin panel because I forgot to close them via client).

Are there any known issues that I should check before I post the offending code?


回答1:


I went back to the working prototype but discovered that it also had this very same bug. After a bit of testing, I found out that it only occurs after I immediately refreshed the page. If a request was made before refreshing the page, the bug does not happen. I informed the dev about this and made a hack to make it work until it is fixed on their side.

UPDATE:

I found out that this only happens with Firefox. Safari and even IE do it correctly (i.e. don't do the double post). So maybe it's Firefox that is behaving bad after all!

UPDATE 2:

I received a mail requesting the modifications I made. Here they are.

In strophe.js at around line 2566, change

sendFunc();

to

if (req.sends == 0) {
   sendFunc();
}


来源:https://stackoverflow.com/questions/7752475/strophe-sending-double-request-on-page-unload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!