diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2015-10-08 14:30:58 -0500 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2015-10-08 15:50:11 -0500 |
commit | b099a7d2705428a4434813079f399dec54ec7611 (patch) | |
tree | 481ff38b1db2939f32a8ecb639f4e3b118f66417 /lib/action_cable/connection/base.rb | |
parent | 91d6db34357634eaa0903b5c05a5db8b10066366 (diff) | |
download | rails-b099a7d2705428a4434813079f399dec54ec7611.tar.gz rails-b099a7d2705428a4434813079f399dec54ec7611.tar.bz2 rails-b099a7d2705428a4434813079f399dec54ec7611.zip |
Run a single eventmachine timer to send heartbeats
Diffstat (limited to 'lib/action_cable/connection/base.rb')
-rw-r--r-- | lib/action_cable/connection/base.rb | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/action_cable/connection/base.rb b/lib/action_cable/connection/base.rb index 08a75156a3..de1369f009 100644 --- a/lib/action_cable/connection/base.rb +++ b/lib/action_cable/connection/base.rb @@ -59,7 +59,6 @@ module ActionCable @logger = new_tagged_logger @websocket = ActionCable::Connection::WebSocket.new(env) - @heartbeat = ActionCable::Connection::Heartbeat.new(self) @subscriptions = ActionCable::Connection::Subscriptions.new(self) @message_buffer = ActionCable::Connection::MessageBuffer.new(self) @@ -115,6 +114,10 @@ module ActionCable { identifier: connection_identifier, started_at: @started_at, subscriptions: subscriptions.identifiers } end + def beat + transmit({ identifier: '_ping', message: Time.now.to_i }.to_json) + end + protected # The request that initiated the websocket connection is available here. This gives access to the environment, cookies, etc. @@ -133,14 +136,14 @@ module ActionCable private attr_reader :websocket - attr_reader :heartbeat, :subscriptions, :message_buffer + attr_reader :subscriptions, :message_buffer def on_open server.add_connection(self) connect if respond_to?(:connect) subscribe_to_internal_channel - heartbeat.start + beat message_buffer.process! rescue ActionCable::Connection::Authorization::UnauthorizedError @@ -159,7 +162,6 @@ module ActionCable subscriptions.unsubscribe_from_all unsubscribe_from_internal_channel - heartbeat.stop disconnect if respond_to?(:disconnect) end |