lib/anycable/rails/actioncable/connection.rb in anycable-rails-1.0.1 vs lib/anycable/rails/actioncable/connection.rb in anycable-rails-1.0.2
- old
+ new
@@ -29,11 +29,11 @@
def call(socket, **options)
new(socket, nil, options)
end
end
- def initialize(socket, env, identifiers: "{}", subscriptions: [])
+ def initialize(socket, env, identifiers: "{}", subscriptions: nil)
if env
# If env is set, then somehow we're in the context of Action Cable
# Return and print a warning in #process
@request = ActionDispatch::Request.new(env)
return
@@ -49,12 +49,19 @@
@cached_ids = {}
@coder = ActiveSupport::JSON
@socket = socket
@subscriptions = ActionCable::Connection::Subscriptions.new(self)
- # Initialize channels if any
- subscriptions.each { |id| @subscriptions.fetch(id) }
+ return unless subscriptions
+
+ # Initialize channels (for disconnect)
+ subscriptions.each do |id|
+ channel = @subscriptions.fetch(id)
+ next unless socket.istate[id]
+
+ channel.__istate__ = ActiveSupport::JSON.decode(socket.istate[id])
+ end
end
def process
# Use Rails logger here to print to stdout in development
logger.error invalid_request_message
@@ -62,10 +69,10 @@
[404, {"Content-Type" => "text/plain"}, ["Page not found"]]
end
def invalid_request_message
"You're trying to connect to Action Cable server while using AnyCable. " \
- "See https://docs.anycable.io/v1/#/troubleshooting?id=server-raises-an-argumenterror-exception-when-client-tries-to-connect"
+ "See https://docs.anycable.io/#/troubleshooting?id=server-raises-an-argumenterror-exception-when-client-tries-to-connect"
end
def handle_open
logger.info started_request_message if access_logs?