Confirm connection monitor subscription on open

This commit is contained in:
Pratik Naik 2016-02-18 18:17:17 -06:00
parent 725c913c90
commit 426676e8d0
2 changed files with 9 additions and 2 deletions

View File

@ -154,7 +154,7 @@ module ActionCable
def handle_open
connect if respond_to?(:connect)
subscribe_to_internal_channel
beat
confirm_connection_monitor_subscription
message_buffer.process!
server.add_connection(self)
@ -173,6 +173,13 @@ module ActionCable
disconnect if respond_to?(:disconnect)
end
def confirm_connection_monitor_subscription
# Send confirmation message to the internal connection monitor channel.
# This ensures the connection monitor state is reset after a successful
# websocket connection.
transmit ActiveSupport::JSON.encode(identifier: ActionCable::INTERNAL[:identifiers][:ping], type: ActionCable::INTERNAL[:message_types][:confirmation])
end
def allow_request_origin?
return true if server.config.disable_request_forgery_protection

View File

@ -56,7 +56,7 @@ class ActionCable::Connection::BaseTest < ActionCable::TestCase
run_in_eventmachine do
connection = open_connection
connection.websocket.expects(:transmit).with(regexp_matches(/\_ping/))
connection.websocket.expects(:transmit).with({ identifier: "_ping", type: "confirm_subscription" }.to_json)
connection.message_buffer.expects(:process!)
connection.process