aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/lib/action_cable/connection/base.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actioncable/lib/action_cable/connection/base.rb')
-rw-r--r--actioncable/lib/action_cable/connection/base.rb32
1 files changed, 12 insertions, 20 deletions
diff --git a/actioncable/lib/action_cable/connection/base.rb b/actioncable/lib/action_cable/connection/base.rb
index 0016d1a1a4..bb8850aaa0 100644
--- a/actioncable/lib/action_cable/connection/base.rb
+++ b/actioncable/lib/action_cable/connection/base.rb
@@ -49,14 +49,14 @@ module ActionCable
include Authorization
attr_reader :server, :env, :subscriptions, :logger
- delegate :stream_event_loop, :worker_pool, :pubsub, to: :server
+ delegate :worker_pool, :pubsub, to: :server
def initialize(server, env)
@server, @env = server, env
@logger = new_tagged_logger
- @websocket = ActionCable::Connection::WebSocket.new(env, self, stream_event_loop)
+ @websocket = ActionCable::Connection::WebSocket.new(env)
@subscriptions = ActionCable::Connection::Subscriptions.new(self)
@message_buffer = ActionCable::Connection::MessageBuffer.new(self)
@@ -70,6 +70,10 @@ module ActionCable
logger.info started_request_message
if websocket.possible? && allow_request_origin?
+ websocket.on(:open) { |event| send_async :on_open }
+ websocket.on(:message) { |event| on_message event.data }
+ websocket.on(:close) { |event| send_async :on_close }
+
respond_to_successful_request
else
respond_to_invalid_request
@@ -117,22 +121,6 @@ module ActionCable
transmit ActiveSupport::JSON.encode(identifier: ActionCable::INTERNAL[:identifiers][:ping], message: Time.now.to_i)
end
- def on_open # :nodoc:
- send_async :handle_open
- end
-
- def on_message(message) # :nodoc:
- message_buffer.append message
- end
-
- def on_error(message) # :nodoc:
- # ignore
- end
-
- def on_close # :nodoc:
- send_async :handle_close
- end
-
protected
# The request that initiated the WebSocket connection is available here. This gives access to the environment, cookies, etc.
def request
@@ -151,7 +139,7 @@ module ActionCable
attr_reader :message_buffer
private
- def handle_open
+ def on_open
connect if respond_to?(:connect)
subscribe_to_internal_channel
beat
@@ -162,7 +150,11 @@ module ActionCable
respond_to_invalid_request
end
- def handle_close
+ def on_message(message)
+ message_buffer.append message
+ end
+
+ def on_close
logger.info finished_request_message
server.remove_connection(self)