在调用onOpen方法时,使用sendMessage失败 发现在onOpen中readyState 状态还是 connecting 0的状态
2ic8powd1#
Hi, songrunyu926.
It seems that this issue is a bit vague and lacks some necessary information.
看起来这条 issue 描述得有些模糊,缺少一些必要的信息。
9ceoxa922#
有 demo 么?
wf82jlnq3#
// 在onOpen方法中直接使用sendMessage会有问题 加上定时就好了const { readyState, sendMessage, latestMessage, connect } = useWebSocket(url, {onOpen(event, instance) {console.log(readyState) // 0sendMessage(JSON.stringify({ socketType: 0, message: 'keep-alive' }))setInterval(() => {sendMessage(JSON.stringify({ socketType: 0, message: 'keep-alive' }))}, 15000)},manual: true,})
k5ifujac4#
麻烦给一个在线运行的 demo 呢,比如 codesandbox
4条答案
按热度按时间2ic8powd1#
Hi, songrunyu926.
It seems that this issue is a bit vague and lacks some necessary information.
看起来这条 issue 描述得有些模糊,缺少一些必要的信息。
9ceoxa922#
有 demo 么?
wf82jlnq3#
// 在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,
})
k5ifujac4#
麻烦给一个在线运行的 demo 呢,比如 codesandbox