aboutsummaryrefslogtreecommitdiffstats
path: root/lib/action_cable
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2015-06-21 19:48:25 +0200
committerDavid Heinemeier Hansson <david@loudthinking.com>2015-06-21 19:48:25 +0200
commitb7ce9b652e2de0f724941b076078370e4c7590bc (patch)
tree678c06feaabbbcc753a3f54cf9fc7501368a535c /lib/action_cable
parente2a5a323fd1764c8a2b8d34ebfde65e527a1aedd (diff)
downloadrails-b7ce9b652e2de0f724941b076078370e4c7590bc.tar.gz
rails-b7ce9b652e2de0f724941b076078370e4c7590bc.tar.bz2
rails-b7ce9b652e2de0f724941b076078370e4c7590bc.zip
Add logging for when data is received without a live web socket
And make cleanup_subscriptions private
Diffstat (limited to 'lib/action_cable')
-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