title: Action Cable: How to get the client's subscription name when the client unsubscribes?
body: <p>I am implementing a chat in Rails 5 API Action Cable using Devise and gem 'devise_token_auth'.</p>
  
  <p>I have a <code>ChatRequestChannel</code> with parameterized subscriptions:</p>
  
  <p><code>stream_from "chat_request_#{chat_request_chanel_token}_channel"</code></p>
  
  <p>I need to somehow reliably retrieve the <code>chat_request_chanel_token</code> value inside the <code>unsubscribed</code> hook - to send a message to other subscribers. Here's my code:</p>
  
  <pre><code>class ChatRequestChannel &lt; ApplicationCable::Channel
    def subscribed 
  
      answerer = params["answerer"]
  
      chat_request_chanel_token = answerer
  
      answerer_user = User.find_by email: answerer
  
      if answerer_user
  
        stream_from "chat_request_#{chat_request_chanel_token}_channel"
  
      else
  # http://api.rubyonrails.org/classes/ActionCable/Channel/Base.html#class-ActionCable::Channel::Base-label-Rejecting+subscription+requests
        reject
  
      end
  
    end
  
    def unsubscribed
      # Any cleanup needed when channel is unsubscribed
  
        chat_request_chanel_token = "What to put here????"
  
        message = "Client disconnected"  
  
        ActionCable.server.broadcast "chat_request_#{chat_request_chanel_token}_channel",
                                     disconnected: message
  
    end
  end
  </code></pre>
  
  <p>All the clients subscribe to <code>ChatRequestChannel</code> and with the command like this (<code>answerer</code> param varies from client to client):</p>
  
  <pre><code>{"command":"subscribe","identifier":"{\"channel\":\"ChatRequestChannel\",\"answerer\":\"client1@example.com\"}"}
  </code></pre>
  
  <p>The <code>unsubscribed</code> hook actually gets called when a client disconnects from Action Cable. So I can't provide any params to <code>unsubscribed</code>.</p>
  
  <p>I suggest that every client should have only <strong>one (per parameter)</strong> parameterized subscription to the <code>ChatRequestChannel</code>. Is it stored somewhere inside Action Cable and can be retrieved?</p>