aboutsummaryrefslogtreecommitdiffstats
path: root/lib/action_cable/connection/base.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/action_cable/connection/base.rb')
-rw-r--r--lib/action_cable/connection/base.rb39
1 files changed, 21 insertions, 18 deletions
diff --git a/lib/action_cable/connection/base.rb b/lib/action_cable/connection/base.rb
index 2ca284b62f..32f6d0ae91 100644
--- a/lib/action_cable/connection/base.rb
+++ b/lib/action_cable/connection/base.rb
@@ -64,26 +64,22 @@ module ActionCable
end
end
- return unless websocket_alive?
-
- data = ActiveSupport::JSON.decode data
-
- case data['command']
- when 'subscribe'
- subscribe_channel(data)
- when 'unsubscribe'
- unsubscribe_channel(data)
- when 'message'
- process_message(data)
def receive_data(data)
+ if websocket_alive?
+ data = ActiveSupport::JSON.decode data
+
+ case data['command']
+ when 'subscribe'
+ subscribe_channel(data)
+ when 'unsubscribe'
+ unsubscribe_channel(data)
+ when 'message'
+ process_message(data)
+ else
+ logger.error "Received unrecognized command in #{data.inspect}"
+ end
else
- logger.error "Received unrecognized command in #{data.inspect}"
- end
- end
-
- def cleanup_subscriptions
- @subscriptions.each do |id, channel|
- channel.perform_disconnection
+ logger.error "Received data without a live websocket (#{data.inspect})"
end
end
@@ -135,6 +131,13 @@ module ActionCable
disconnect if respond_to?(:disconnect)
end
+ def cleanup_subscriptions
+ @subscriptions.each do |id, channel|
+ channel.perform_disconnection
+ end
+ end
+
+
def transmit_ping_timestamp
transmit({ identifier: '_ping', message: Time.now.to_i }.to_json)
end