diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2016-02-18 18:17:17 -0600 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2016-02-23 09:37:49 -0600 |
commit | 426676e8d0fdde079406e35f6bc13c8c20bd8a92 (patch) | |
tree | cbd1d50d4c449515e9cf3b05033987edad603ccf | |
parent | 725c913c902902d84a595760cd9fdb933cfa824d (diff) | |
download | rails-426676e8d0fdde079406e35f6bc13c8c20bd8a92.tar.gz rails-426676e8d0fdde079406e35f6bc13c8c20bd8a92.tar.bz2 rails-426676e8d0fdde079406e35f6bc13c8c20bd8a92.zip |
Confirm connection monitor subscription on open
-rw-r--r-- | actioncable/lib/action_cable/connection/base.rb | 9 | ||||
-rw-r--r-- | actioncable/test/connection/base_test.rb | 2 |
2 files changed, 9 insertions, 2 deletions
diff --git a/actioncable/lib/action_cable/connection/base.rb b/actioncable/lib/action_cable/connection/base.rb index 1acef93025..ea7513e72b 100644 --- a/actioncable/lib/action_cable/connection/base.rb +++ b/actioncable/lib/action_cable/connection/base.rb @@ -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 diff --git a/actioncable/test/connection/base_test.rb b/actioncable/test/connection/base_test.rb index e2b017a9a1..3bef9e95a1 100644 --- a/actioncable/test/connection/base_test.rb +++ b/actioncable/test/connection/base_test.rb @@ -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 |