Closed Gianthard-cyh closed 1 year ago
The docs https://github.com/fastify/fastify-websocket/blob/1e41ac4aa3ce21a69e6718977509fee8c5d0f22e/README.md do not mention an open
event. They only mention a message
event.
The docs https://github.com/fastify/fastify-websocket/blob/1e41ac4aa3ce21a69e6718977509fee8c5d0f22e/README.md do not mention an
open
event. They only mention amessage
event.
so how can i do if i want to send a message immediately after the connection is open?
You can just send right in the request handler!
fastify.get('/', { websocket: true }, (connection /* SocketStream */, req /* FastifyRequest */) => {
connection.socket.send("synchronous message on connection open")
})
When you reach the handler, it is already open.
@fastify/websocket
is server side, once it reach. It means the connection already there.
Prerequisites
Fastify version
4.10.0
Plugin version
7.1.1
Node.js version
19.1.0
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
ubuntu 20.04
Description
test.js
I've tried postman and my browser to create ws connection but none works. message and close events are properly handled, but open is not.
Steps to Reproduce
Expected Behavior
No response