Not able to count how many listeners are there for a channel
I am relying on the imperative API to subscribe to the channels channel?.subscribe(eventName, ...). I am trying to control the lifecycle of my application so as soon as there are no more subscriptions on a given channel, I want to detach it. The problem is that channel.listeners() when called without the eventName parameter does not return the listeners which are not "any" listeners. This seems counter intuitive. Additionally, knowing how many subscriptions are there for a given channel is very useful to control attaching/detaching of channels.
Are there alternative ways of knowing how many subscriptions are there without having to track all possible events to which users may have subscribed to?
Hey @luizoppy,
Thank you very much for raising this. I agree that the channel.listeners() method contract can be a bit confusing. We don't want to change the implementation right now because it will introduce breaking changes, and other clients may rely on the current implementation. We will think about adding a new method, something like channel.allListeners(), with the behavior you desire. This improvement in our high priority list and we'll keep you posted.
Meanwhile, I can only suggest you add your own listener counter that will be responsible for calculating active listeners for the channel.