Strophe sending double request on page unload

2019-04-10 05:59发布

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:

enter image description here

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条回答
劫难
2楼-- · 2019-04-10 06:24

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();
}
查看更多
登录 后发表回答