Closed Vincz closed 1 year ago
Yeah this is a problem, I like how it was before the change. Maybe there needs to be two close events: closing and closed. In case someone needs to know the topics before they are gone, they need to look in closing callback.
A simple unsubscribed(topic) callback would do, right? It gets called whenever you or the library unsubscribes from one topic.
unsubscribed(ws, topic, remainingSubscribers)
That's a good callback - remainingSubscribers would be 0 when it is time to close Redis subscription
Probably don't need one for subscribe since it's always explicit
No wait what you need is a callback for when a topic is removed due to no websockets subscribing to it anymore?
Both you and the referenced issue is pretty much about getting a callback whenever a topic lost all its subscribers. You just have small variations of the problem
To make it as generic as possible, it could be called topic(name, number) and be called whenever a topic changes number of subscribers. Then you can use 0 as destroy and 1 as create and whatever else as statistics or whatnot
Hi @uNetworkingAB!
On my side, I keep a value in redis with the number of subscribers for each channel. When a user subscribe, I increment and when a user unsubscribe, I decrement. The problem is when the connection is closed, I don't know what channel they were subscribed to. So for me, it was to be able to access this subscribed channels in the close
event.
Hey guys! Any update about this?
No news but this is definitely a high prio item (pretty low hanging fruit
This should be implemented now.
It works like so: .subscription = [](websocket, topic name, new count, old count) {}
Any time a websocket is subscribed or unsubscribed for any reason (whether explicit by call to subscribe, or implicit by socket close) it will emit this, so you can keep track of external (Redis?) subscriptions this way.
Can you provide an example of this please? I'm trying to search for .subscription
in the documentation but I couldn't find anything.
It's a handler just like for instance .open, .close.
Thank you! It looks like the .subscription
handler is missing in Elysia.js bun framework, so it has nothing to do with this library.
Hi! First of all, thank for this wonderful library. My problem is the opposite of uNetworking/uWebSockets.js#647 . I need to know the topics the ws was subscribed to when it closed. Accessing
ws.getTopics()
in the close handler return an invalid access.Would it be possible to give the close handler an extra parameter containing the topics the ws was subscribed to when it closed? Something like:
close: (ws, code, message, topics)
As an alternative, it would be great to have access to the list of active topics with the number of subscribers from the app object.
Have a wonderful day!