honojs / hono

Web framework built on Web Standards
https://hono.dev
MIT License
20.01k stars 569 forks source link

The onOpen method of upgradeWebSocket cannot be triggered #3610

Open TinsFox opened 2 hours ago

TinsFox commented 2 hours ago

What version of Hono are you using?

4.6.8

What runtime/platform is your app running on?

cloudflare workers

What steps can reproduce the bug?

Just clone my repo https://github.com/TinsFox/webrtc-worker and run it

open http://localhost:3001/client

What is the expected behavior?

The onOpen method runs normally and I can get the newly established link

What do you see instead?

The onOpen method is unresponsive, as if it doesn't exist.

Can't see any output from the onOpen method.

   onOpen(evt, ws) {
          console.log("WebSocket opened")
          console.log("ws: ", ws)
          console.log("evt: ", evt)
          try {
            clients.add(ws)
            console.log("Client connected. Total clients:", clients.size)
          } catch (error) {
            console.error("Error in onOpen:", error)
          }
        },
image

Additional information

I'm building a small project to share projects, here is an example of implementation using node express, I want to implement it using hono, and that's using Cloudflare worders

The principle of implementation is to initialize a parameter in the client and then propagate it to the admin through ws. The admin uses this parameter to create an instance to display the client's screen.

TinsFox commented 2 hours ago

Additional info, what I'm trying to accomplish is to build a ws server using hono and exchange data via ws.

client => ws => client