Strophe在页面卸载时发送双重请求 [英] Strophe sending double request on page unload

查看:117
本文介绍了Strophe在页面卸载时发送双重请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用jQuery + Strophe编写了一个XMPP客户端。一切运作良好(1对1,存在,MUC等),并包含在jQuery插件中。但是,当页面卸载时,它会发送2个具有相同rid的最终请求。当我开始处理会话附件时,它最近才出现问题。

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.

以下是Firebug控制台的示例:

Here is an example of the Firebug console:

在此处,我刚刚登录并立即刷新了页面。您看到的第一个帖子是登录后的初始状态节。在该请求之后,新的BOSH请求已开始保持与服务器的连接。刷新页面时,此请求将中止。到目前为止,一切都按照我的预期进行。

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.

然而,在中止请求之后,strophe发送另一个具有完全相同RID的请求。最后的请求是从strophe发送的(我想)良好的举止,与问题无关。但是它的响应表明openfire(XMPP服务器)在尝试保护帐户时终止了会话。

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.

我查看了我的代码但无法找到任何请求我代表。我相当肯定strophe会发送这个请求。但是,它必须来自我做的事情,因为我的初始原型没有那个问题(实际上,我经常不得不手动杀死管理面板上的会话,因为我忘了通过客户端关闭它们)。

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?

推荐答案

我回到工作原型但发现它也有同样的错误。经过一些测试后,我发现只有在我立即刷新页面后才会发生。如果在刷新页面之前发出了请求,则不会发生错误。我向开发者通报了这个问题并做了一个黑客工作,直到它被修复为止。

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.

我发现这只只发生在上。 Safari甚至IE都正确地做到了(即不做双重帖子)。所以也许它的Firefox表现得很糟糕!

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!

我收到一封邮件要求提供我做的修改。他们在这里。

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

在第2566行左右的strophe.js中,更改

In strophe.js at around line 2566, change

sendFunc();

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

这篇关于Strophe在页面卸载时发送双重请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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