I'm using Bun + Elysia and they are using uWebSockets.js. I use Postman to test, when i make connection it opens with one id number but when i close it closes with other ID number.
Should the ID's be the same?
export const ws = new Elysia().ws('/ws', {
body: t.Object({
message: t.String(),
}),
open: (ws) => {
console.log(' ~ open:', ws.id);
},
message: (ws) => {
console.log(' ~ message:', ws.id);
},
close: (ws) => {
console.log(' ~ close:', ws.id);
},
error: (c) => {
console.log(' ~ error:', JSON.stringify(c));
},
});

So I've handed in an PR to fix this issues, but a solution for now looks like this:
This works because uWebSockets (the underlaying websockets library used by Bunjs and Elysiajs) hands in the correct websocket for the
closecallback. Elysia stores this in therawprop.EDIT: Almost forgot, for the ID, use
crypto.randomInt(), Elysia's usingDate.now(), which is bad for randomness, I already tested, if you are creating a lot of connections,Date.now()performs extremely poorly. In my test, out of 100 iterations I only had 2 unique IDs.PR: https://github.com/elysiajs/elysia/issues/381