I am trying to implement online feature in our application using Action Cable. This is working well for most part but i see that the users who are not active are also shown. Below is the relevant code for your reference.
class OnlineChannel < ApplicationCable::Channel
def subscribed
ActionCable.server.pubsub.redis_connection_for_subscriptions.sadd "online", current_user.id
end
def unsubscribed
ActionCable.server.pubsub.redis_connection_for_subscriptions.srem "online", current_user.id
end
end
I see in the list users who have used the application 2 days back in here. Below are couple of the questions
- When is unsubscribed called? (Tab close / signout / shutdown / machine going to sleep)
- Is there a way to detect a subscription idle period? i.e. how long has a subscription been not active?