Class: EventsChannel
- Inherits:
-
ApplicationCable::Channel
- Object
- ActionCable::Channel::Base
- ApplicationCable::Channel
- EventsChannel
- Defined in:
- app/channels/events_channel.rb
Overview
Be sure to restart your server when you modify this file. Action Cable runs in a loop that does not support auto reloading.
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.name_of(event) ⇒ Object
4 5 6 |
# File 'app/channels/events_channel.rb', line 4 def self.name_of(event) "events_#{event.gsub(":", "_")}" end |
Instance Method Details
#subscribed ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/channels/events_channel.rb', line 8 def subscribed events = [params[:event]] if params.key?(:event) events = params[:events] if params.key?(:events) events.each do |event| unless Houston.events.registered?(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 |
#unsubscribed ⇒ Object
23 24 25 |
# File 'app/channels/events_channel.rb', line 23 def unsubscribed # Any cleanup needed when channel is unsubscribed end |