Accessing subscribed topics on socket close event #869
-
I've previously been tracking topics that individual sockets subscribe to manually, creating a list for each socket. I felt that this was unnecessary seeing as though you can call On the socket uWS.App().ws('/socket', {
close: socket => emitter.emit('closed', socket)
});
emitter.on('closed', socket => {
const topics = socket.getTopics();
topics.forEach(topic => {
// do something here
});
}); Unfortunately when attempting to call Is calling Documentation states "You may not use WebSocket after this event.", so I'm lead to believe that the above would be undefined behaviour. In that case, is there a better solution to what I'm wanting to implement other than keeping track of subscribed topics manually? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
uWS.App().ws('/socket', {
close: socket => {
socket.topics = socket.getTopics();
emitter.emit('closed', socket);
}
});
emitter.on('closed', socket => {
socket.topics.forEach(topic => {
// do something here
});
}); |
Beta Was this translation helpful? Give feedback.
-
See https://github.com/uNetworking/uWebSockets/releases/tag/v20.32.0 |
Beta Was this translation helpful? Give feedback.
See https://github.com/uNetworking/uWebSockets/releases/tag/v20.32.0