Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

πŸ› Bug Report β€” Websocket server doesn't emit the open event #2513

Closed
jbb494 opened this issue Aug 10, 2024 · 1 comment
Closed

Comments

@jbb494
Copy link

jbb494 commented Aug 10, 2024

The websocket server doesn't emit the open event ever.
So the following code:

const webSocketPair = new WebSocketPair();
  const [client, server] = Object.values(webSocketPair);

  server.accept();

  server.addEventListener("open", async (event) => {
    console.log("Open");
  });

Never runs.
Even though the close and message events do get emitted.

@jbb494 jbb494 changed the title Websocket server doesn't emit the open event πŸ› Bug Report β€” Websocket server doesn't emit the open event Aug 10, 2024
@MellowYarker
Copy link
Contributor

An open event is only necessary on the client side, as it informs the client that the server has established the connection and is ready to communicate.

In this example, you are in control of the server side of the connection and have received a request from a client to use WebSockets. The moment your application calls server.accept() your server websocket is ready to send messages, so there's no point in dispatching an "open" event -- the connection is already ready from the servers POV.

Basically, if you're a client, you have to "wait" for the server to say it's ready before you send any messages with your websocket. If you're a server, you have nothing to wait for (websocket comms are bi-directional), so you can start sending messages immediately.

@cloudflare cloudflare locked and limited conversation to collaborators Aug 10, 2024
@MellowYarker MellowYarker converted this issue into discussion #2514 Aug 10, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants