Module: ActionCableNotifications::Channel
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/action_cable_notifications/channel.rb,
lib/action_cable_notifications/channel_cache.rb,
lib/action_cable_notifications/channel_actions.rb
Defined Under Namespace
Instance Method Summary collapse
-
#action(data) ⇒ Object
Process actions sent from the client.
- #initialize(*args) ⇒ Object
- #subscribed ⇒ Object
- #unsubscribed ⇒ Object
Methods included from Cache
#update_cache, #validate_packet
Methods included from Actions
#create, #destroy, #fetch, #update
Instance Method Details
#action(data) ⇒ Object
Process actions sent from the client
"publication": "model.model_name.name"
"command": "fetch"
"params": {
}
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/action_cable_notifications/channel.rb', line 25 def action(data) data.deep_symbolize_keys! publication = data[:publication] = @ChannelPublications[publication] if model = [:model] = model.ChannelPublications[publication] params = data[:params] command = data[:command] action_params = { publication: publication, model: model, model_options: , options: , params: params, command: command } case command when "fetch" fetch(action_params) when "create" create(action_params) when "update" update(action_params) when "destroy" destroy(action_params) end else response = { publication: publication, msg: 'error', command: command, error: "Stream for publication '#{publication}' does not exist in channel '#{self.channel_name}'." } # Send error notification to the client transmit response end end |
#initialize(*args) ⇒ Object
68 69 70 71 72 |
# File 'lib/action_cable_notifications/channel.rb', line 68 def initialize(*args) @collections = {} @ChannelPublications = {} super end |
#subscribed ⇒ Object
74 75 76 77 |
# File 'lib/action_cable_notifications/channel.rb', line 74 def subscribed # XXX Check if this is new connection or a reconection of a # previously active client end |
#unsubscribed ⇒ Object
79 80 81 |
# File 'lib/action_cable_notifications/channel.rb', line 79 def unsubscribed stop_all_streams end |