-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useWebSocket的onOpen问题 #1817
Comments
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 |
这个问题我也遇到了,在首次连接socket成功后,调用disconnect方法断开连接,然后调用connect方法重新连接。此时,onpen回调中的readyState为0。可能是该hook中的某个异步环节的处理出现了问题。 |
2022年就提出来了 到现在也没改 |
我也遇到这个问题,连接断开后重新连接,readyState 为1 ,但是报错: 代码如下: const ReadyState = {
Connecting: 0,
Open: 1,
Closing: 2,
Closed: 3
};
const { readyState, sendMessage, latestMessage } = useWebSocket(url);
useEffect(() => {
switch (readyState) {
// 连接成功
case ReadyState.Open:
sendMessage('data');
break;
default:
break;
}
}, [readyState, sendMessage]); |
我在onOpen( webSocket 连接成功回调)里调用sendMessage 提示我没有连接成功 确实是有问题,到现在还没解决 |
Hello @songrunyu926. We totally like your proposal/feedback, welcome to send us a Pull Request for it. Please send your Pull Request to proper branch (feature branch for the new feature, master for bugfix and other changes), fill the Pull Request Template here, provide changelog/TypeScript/documentation/test cases if needed and make sure CI passed, we will review it soon. We appreciate your effort in advance and looking forward to your contribution! 你好 @songrunyu926,我们完全同意你的提议/反馈,欢迎直接在此仓库 创建一个 Pull Request 来解决这个问题。请将 Pull Request 发到正确的分支(新特性发到 feature 分支,其他发到 master 分支),务必填写 Pull Request 内的预设模板,提供改动所需相应的 changelog、TypeScript 定义、测试用例、文档等,并确保 CI 通过,我们会尽快进行 Review,提前感谢和期待您的贡献。 |
在调用onOpen方法时,使用sendMessage失败 发现在onOpen中readyState 状态还是 connecting 0的状态
The text was updated successfully, but these errors were encountered: