Rails: Action cable When is a unsubscribed called?

Viewed 130

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

  1. When is unsubscribed called? (Tab close / signout / shutdown / machine going to sleep)
  2. Is there a way to detect a subscription idle period? i.e. how long has a subscription been not active?
0 Answers
Related