gpt4 book ai didi

pusher - 了解断开/重新连接过程和错误消息

转载 作者:行者123 更新时间:2023-12-02 12:21:30 29 4
gpt4 key购买 nike

我正在尝试实现一项功能,通知用户推送器断开连接,并指示何时重新连接。我的第一个实验只是将更改的推送器状态记录到控制台:

var pusher = new Pusher('MY_ACCOUNT_STRING');
pusher.connection.bind('state_change', function(states) {
console.log(states.current);
});

然后我刷新页面,获得与 Pusher 的连接,禁用我的互联网连接,等待 Pusher 检测到断开连接,重新启用我的 Internet 连接,然后等待 Pusher 检测到该连接。这是在此过程中 chrome 控制台输出的屏幕截图 ( click here for a larger version ):

chrome console during disconnection

这是我的问题:

  1. 花了超过一分钟,甚至可能是 2-3 分钟,推送器才检测到断开连接。有没有办法减少这个时间,以便 Pusher 在 10 秒左右的时间内检测到断开连接?
  2. 为什么我会看到这些红色错误,它们到底意味着什么?这正常吗?我认为通过正确的设置,错误将得到处理,因为断开连接事件是推送器上下文中的“预期”异常。
  3. 1006 错误是什么?为什么我会看到该错误?

感谢您的帮助!

编辑:

我一直在观察长期连接的输出,并且我也多次看到过这种情况,并且想知道其原因,以及如何捕获它并处理它?

disconnected login.js:146
connecting login.js:146
Pusher : Error : {"type":"WebSocketError","error":{"type":"PusherError","data":{"code":1007,"message":"Server heartbeat missed"}}} pusher.min.js:12
connected

最佳答案

这不是正常行为。您有机会在不同的机器和网络上检查这一点吗?看起来像是网络问题。

问题 1。

当我禁用 wifi 时,推送器需要 4 秒才能注意到并将状态更改为已断开,然后更改为不可用

当我重新启用 wifi 时,我只收到与 http://js.pusher.com/2.1.3/sockjs.js 上相同的错误

我不知道这样做的影响..但您可以尝试更改默认超时:

var pusher = new Pusher('MY_ACCOUNT_STRING',  {
pong_timeout: 6000, //default = 30000
unavailable_timeout: 2000 //default = 10000
});

问题 2。

不知道,我认为库不应该抛出这些错误

问题 3。

错误来自 WebSocket 协议(protocol):https://www.rfc-editor.org/rfc/rfc6455

  1006 is a reserved value and MUST NOT be set as a status code in a
Close control frame by an endpoint. It is designated for use in
applications expecting a status code to indicate that the
connection was closed abnormally, e.g., without sending or
receiving a Close control frame.

1007 indicates that an endpoint is terminating the connection
because it has received data within a message that was not
consistent with the type of the message (e.g., non-UTF-8 [RFC3629]
data within a text message).

关于pusher - 了解断开/重新连接过程和错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18358183/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com