Sha256: c26a0997268cf228823cfa9959f6b039ded3d5acd091a20d797f6bd8c096af1b

Contents?: true

Size: 791 Bytes

Versions: 6

Compression:

Stored size: 791 Bytes

Contents

# Be sure to restart your server when you modify this file. Action Cable runs in a loop that does not support auto reloading.
class EventsChannel < ApplicationCable::Channel

  def self.name_of(event)
    "events_#{event.gsub(":", "_")}"
  end

  def subscribed
    events = [params[:event]] if params.key?(:event)
    events = params[:events] if params.key?(:events)

    events.each do |event|
      unless Houston.registered_event?(event)
        Rails.logger.info "\e[31m[subscriber] \e[1m#{event}\e[0;31m is not a registered event\e[0m"
        next
      end

      Rails.logger.info "\e[34m[subscriber] Subscribing to \e[1m#{event}\e[0m"
      stream_from EventsChannel.name_of(event)
    end
  end

  def unsubscribed
    # Any cleanup needed when channel is unsubscribed
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
houston-core-0.8.4 app/channels/events_channel.rb
houston-core-0.8.3 app/channels/events_channel.rb
houston-core-0.8.2 app/channels/events_channel.rb
houston-core-0.8.1 app/channels/events_channel.rb
houston-core-0.8.0 app/channels/events_channel.rb
houston-core-0.8.0.pre2 app/channels/events_channel.rb