In my Rails view I’m using turbo_stream_from to subscribe to a turbo stream broadcast to display a list of patients:
<%= turbo_stream_from :all_patients %>
I want this list to be updated when a new patient is created, so I call:
constly_method
Turbo::StreamsChannel.broadcast_update_to(:all_patients,...)
However, I want to run this code only if there are any clients that are actually subscribed to :all_patients at the moment, because this code takes some computing resources. So, I want something like
if Turbo::StreamsChannel.broadcast_subscribed?(:all_patients)
constly_method
Turbo::StreamsChannel.broadcast_update_to(:all_patients,...)
end
Is there any way to check that?
ActionCanble data can be accessed with query. For Example
Documentation: https://api.rubyonrails.org/v7.0/classes/ActionCable/RemoteConnections.html
It good to play around with the query to solve the problem. (If you will find accurate query. Message me to comment. I will enrich my post with it). Hope this help