diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/action_cable/channel/base.rb | 12 | ||||
-rw-r--r-- | lib/action_cable/connection/base.rb | 2 |
2 files changed, 9 insertions, 5 deletions
diff --git a/lib/action_cable/channel/base.rb b/lib/action_cable/channel/base.rb index cc9580ec52..c18593bf6f 100644 --- a/lib/action_cable/channel/base.rb +++ b/lib/action_cable/channel/base.rb @@ -35,12 +35,16 @@ module ActionCable run_subscribe_callbacks end - def receive_data(data) + def perform_action(data) if authorized? - if respond_to?(:receive) - receive(data) + action = (data['action'].presence || :receive).to_sym + signature = "#{self.class.name}##{action}: #{data}" + + if self.class.instance_methods(false).include?(action) + logger.info "Processing #{signature}" + public_send action, data else - logger.error "#{self.class.name} received data (#{data}) but #{self.class.name}#receive callback is not defined" + logger.error "Failed to process #{signature}" end else unauthorized diff --git a/lib/action_cable/connection/base.rb b/lib/action_cable/connection/base.rb index 5c2ee14258..e5ed07b5cc 100644 --- a/lib/action_cable/connection/base.rb +++ b/lib/action_cable/connection/base.rb @@ -150,7 +150,7 @@ module ActionCable def process_message(message) if @subscriptions[message['identifier']] - @subscriptions[message['identifier']].receive_data(ActiveSupport::JSON.decode message['data']) + @subscriptions[message['identifier']].perform_action(ActiveSupport::JSON.decode message['data']) else raise "Unable to process message because no subscription was found (#{message.inspect})" end |