Replies: 1 comment 1 reply
-
let id = 0;
const wsMap = new Map();
app.ws('/', {
open: (ws) => {
ws.id = ++id;
wsMap.set(ws.id, ws);
},
close: (ws) => {
wsMap.delete(ws.id);
},
});
app.get('/', res => {
const ws = wsMap.get(id);
ws.publish(msg);
}); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
igneous8k
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi , im trying to create backend solution which requires multiple servers each to handle thousands on websockets connections which will be publishing event based on http api handler.
In usual app we can use socket.io and do io.to(-idhere-, data) io is available in other http routes through attaching it in req via middleware so in result we can emit events on specific socket I'd with some data from http api handler .
I'm trying to achieve same using websocketjs , im not sure how can I access ws in get request after ws handlers are done .
I appreciate the time and help ❤️
Beta Was this translation helpful? Give feedback.
All reactions