Class: LiveChannel
- Inherits:
-
ActionCable::Channel::Base
- Object
- ActionCable::Channel::Base
- LiveChannel
- Defined in:
- app/channels/live_channel.rb
Instance Method Summary collapse
-
#broadcast(data) ⇒ Object
Exposes #transmit, which ActionCable keeps private to the channel.
- #receive(data) ⇒ Object
- #subscribed ⇒ Object
- #unsubscribed ⇒ Object
Instance Method Details
#broadcast(data) ⇒ Object
Exposes #transmit, which ActionCable keeps private to the channel.
45 46 47 |
# File 'app/channels/live_channel.rb', line 45 def broadcast(data) transmit(data) end |
#receive(data) ⇒ Object
33 34 35 |
# File 'app/channels/live_channel.rb', line 33 def receive(data) live_connection.receive(component, data) end |
#subscribed ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/channels/live_channel.rb', line 4 def subscribed instance = nil # Build live_id from component and id params live_id = "#{params[:component]}/#{params[:id]}" instance = live_connection.get_component(live_id) rendered = instance.present? unless instance instance = LiveCable.instance_from_string(params[:component], params[:id]) live_connection.add_component(instance) instance.defaults = params[:defaults] instance.apply_defaults end instance.connect(self) if rendered instance.broadcast_subscribe else instance.broadcast_render end @component = instance rescue StandardError => error live_connection.handle_error(instance, error) if instance end |
#unsubscribed ⇒ Object
37 38 39 40 41 42 |
# File 'app/channels/live_channel.rb', line 37 def unsubscribed return unless component component.disconnect @component = nil end |