Store WebSocket user data in upgrade handler #860
-
Hello 👋 I was wondering if it could be possible to store some user data in the upgrade handler. I guess I could do something like let roomID;
app.ws("/:roomID/", {
upgrade: (res, req, context) => {
roomID = req.getParameter(0);
res.upgrade(
{ url: req.getUrl() },
req.getHeader('sec-websocket-key'),
req.getHeader('sec-websocket-protocol'),
req.getHeader('sec-websocket-extensions'),
context
);
},
open: (ws) => {
ws.getUserData().roomID = roomID;
},
}); According to the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
https://unetworking.github.io/uWebSockets.js/generated/interfaces/HttpResponse.html#upgrade |
Beta Was this translation helpful? Give feedback.
https://unetworking.github.io/uWebSockets.js/generated/interfaces/HttpResponse.html#upgrade