lib/anycable/rails/actioncable/connection.rb in anycable-rails-0.4.7 vs lib/anycable/rails/actioncable/connection.rb in anycable-rails-0.5.0.rc1
- old
+ new
@@ -1,6 +1,7 @@
# frozen_string_literal: true
+
require "action_cable/connection"
require "anycable/rails/refinements/subscriptions"
require "anycable/rails/actioncable/channel"
module ActionCable
@@ -9,11 +10,11 @@
using Anycable::Refinements::Subscriptions
attr_reader :socket
class << self
- def create(socket, **options)
+ def call(socket, **options)
new(socket, **options)
end
def identified_by(*identifiers)
super
@@ -37,17 +38,22 @@
# Initialize channels if any
subscriptions.each { |id| @subscriptions.fetch(id) }
end
def handle_open
+ logger.info started_request_message if access_logs?
+
connect if respond_to?(:connect)
send_welcome_message
rescue ActionCable::Connection::Authorization::UnauthorizedError
+ logger.info finished_request_message('Rejected') if access_logs?
close
end
def handle_close
+ logger.info finished_request_message if access_logs?
+
subscriptions.unsubscribe_from_all
disconnect if respond_to?(:disconnect)
end
# rubocop:disable Metrics/MethodLength
@@ -99,10 +105,35 @@
GlobalID::Locator.locate(val) || val
end
end
def logger
- Anycable::Rails.logger
+ Anycable.logger
+ end
+
+ private
+
+ def started_request_message
+ 'Started "%s"%s for %s at %s' % [
+ request.filtered_path,
+ " [Anycable]",
+ request.ip,
+ Time.now.to_s
+ ]
+ end
+
+ def finished_request_message(reason = "Closed")
+ 'Finished "%s"%s for %s at %s (%s)' % [
+ request.filtered_path,
+ " [Anycable]",
+ request.ip,
+ Time.now.to_s,
+ reason
+ ]
+ end
+
+ def access_logs?
+ Anycable.config.access_logs_disabled == false
end
end
end
end