Skip to content
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

Open
songrunyu926 opened this issue Aug 16, 2022 · 8 comments
Open

useWebSocket的onOpen问题 #1817

songrunyu926 opened this issue Aug 16, 2022 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@songrunyu926
Copy link

songrunyu926 commented Aug 16, 2022

在调用onOpen方法时,使用sendMessage失败 发现在onOpen中readyState 状态还是 connecting 0的状态

@crazylxr crazylxr added the needs more info Needs more information to continue label Aug 16, 2022
@github-actions
Copy link

Hi, songrunyu926.

It seems that this issue is a bit vague and lacks some necessary information.

看起来这条 issue 描述得有些模糊,缺少一些必要的信息。

@crazylxr
Copy link
Collaborator

有 demo 么?

@songrunyu926
Copy link
Author

songrunyu926 commented Aug 31, 2022

// 在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,
  })

@crazylxr
Copy link
Collaborator

麻烦给一个在线运行的 demo 呢,比如 codesandbox

@github-actions
Copy link

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,若有任何问题,可评论回复。

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 23, 2022
@xmsz-stu
Copy link

我也遇到这个问题
image

image

@liuyib liuyib added bug Something isn't working and removed needs more info Needs more information to continue labels Oct 24, 2023
@liuyib liuyib reopened this Oct 24, 2023
@aioros2016
Copy link

这个问题我也遇到了,在首次连接socket成功后,调用disconnect方法断开连接,然后调用connect方法重新连接。此时,onpen回调中的readyState为0。可能是该hook中的某个异步环节的处理出现了问题。

@haobarry
Copy link

2022年就提出来了 到现在也没改
明显是个bug 状态还是0的时候就触发了 onOpen了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants