-
Hi! Great work with Elysia, feels like a promising tool. Everything was great, I was really satisfied with everything that was already implemented, but there is a question about websockets handling. Looks like the only thing which can give Elysia here - just websocket endpoint and no QOL stuff, like something similar to Is this expected so that developer will implement this event handling system by himself or I missing something in docs? Also talking about docs - looks like Elysia have possibility ( |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
I can't seem to find the docs for it either but I'm pretty sure they say somewhere you can indeed do ws.on('open', () => {
console.log("OPEN")
});
ws.on('close', (event) => {
console.error("CLOSE: ", event.code)
});
ws.on('error', (event) => {
console.log("EVENT: ", event)
}) Also, for the most common events like Elysia has this documentation problem where some things that expectedly should be together in the docs are not, because technically they come from separate categories. |
Beta Was this translation helpful? Give feedback.
Ah I see what you mean now but no, you can't create custom events on a WebSocket, this is not an Elysia thing it's just how WebSockets work.
The closest thing, and generally the accepted way to do what you want, is to use a message format like
[eventname, data_object]
then parse it in themessage
event and run your logic based on the event name.