I can not close my socket manually. It quits only when I close a tab in the browser.
Finished "/cable/" [WebSocket] for 127.0.0.1 at 2016-10-29 16:55:49 +0200
But when I call either
App.cable.subscriptions.remove(App.subscription)
or
App.subscription.unsubscribe()
the method "unsubscribed" in CommunityChannel
is being called, but the cable is still present and I can still print it in my function "print_socket"
How to manually close the connection?
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
def connect
self.current_user = find_verified_user
end
protected
def find_verified_user
if current_user = User.find_by(id: cookies.signed[:user_id])
current_user
else
reject_unauthorized_connection
end
end
end
end
App.cable.subscriptions.remove(App.subscription)
will unsubscribe you from "CommunityChannel", but won't close your connection,
If you want to disconnect, then just do:
App.cable.disconnect()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With