All threads / How can I have two connections in ActionCable?

Ask A Question

Notifications

You’re not receiving notifications from this thread.

How can I have two connections in ActionCable?

Colton Hagan asked in Rails

I have Notifications Channel and a Pings Channel. Notifications are identified by my devise modal Agents. But my Pings Channel needs to be identified by my other devise modal, Users. Heres some sudocode to explain better. This would be ideal:

connection.rb
module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_agent
        identified_by :current_user

    def connect
      self.current_agent = find_verfied_agent
            self.current_user = find_verfied_user
    end

    protected

    def find_verfied_agent
      if current_agent = env['warden'].user
        current_agent
      else
        reject_unauthorized_connection
      end
    end

        def find_verfied_user
      if current_user = env['warden'].user
        current_user
      else
        reject_unauthorized_connection
      end
    end
  end
end

After searching I found this on stack overflow:
https://stackoverflow.com/questions/41672673/multiple-connections-in-actioncable

So basically the same question.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 33,399+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.