hooks
hooks copied to clipboard
useWebSocket的onOpen问题
在调用onOpen方法时,使用sendMessage失败 发现在onOpen中readyState 状态还是 connecting 0的状态
Hi, songrunyu926.
It seems that this issue is a bit vague and lacks some necessary information.
看起来这条 issue 描述得有些模糊,缺少一些必要的信息。
有 demo 么?
// 在onOpen方法中直接使用sendMessage会有问题 加上定时就好了
const { readyState, sendMessage, latestMessage, connect } = useWebSocket(url, {
onOpen(event, instance) {
console.log(readyState) // 0
sendMessage(JSON.stringify({ socketType: 0, message: 'keep-alive' }))
setInterval(() => {
sendMessage(JSON.stringify({ socketType: 0, message: 'keep-alive' }))
}, 15000)
},
manual: true,
})
麻烦给一个在线运行的 demo 呢,比如 codesandbox
Since the issue was labeled with needs more info
, but no response in 3 days. This issue will be closed. If you have any questions, you can comment and reply.
由于该 issue 被标记为需要更多信息,却 3 天未收到回应。现关闭 issue,若有任何问题,可评论回复。
我也遇到这个问题
这个问题我也遇到了,在首次连接socket成功后,调用disconnect方法断开连接,然后调用connect方法重新连接。此时,onpen回调中的readyState为0。可能是该hook中的某个异步环节的处理出现了问题。
2022年就提出来了 到现在也没改
明显是个bug 状态还是0的时候就触发了 onOpen了