在哪里捕获"WebSocket is already in CLOSING or CLOSED state."消息



我已经阅读了许多相关的答案,但我没有找到我需要的东西。 这个答案使用库

我正在使用没有库的websockets和一个Redux中间件。

Websocket 不会持续断开连接,只是偶尔会断开连接。

WebSocket is already in CLOSING or CLOSED state.消息不会被 onerror 函数捕获。控制台登录此行socket.onmessage = onMessage(store);

所以我在努力

socket.onmessage = () => {
if (socket.readyState !== 1)  {
console.error('Please try again later.') // this is just a test to try to handle the problem, it will not be the actua implentation
return
}
onMessage(store);
}

IT 不起作用,消息永远不会发送。我真的需要帮助。

您应该在打开、关闭处理程序中捕获打开和关闭就绪状态。

例如:

socket.onclose = () => {
console.error('Please try again later.');        
}

最新更新