-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Description
Hey,
I've been having trouble while trying to setup proper reconnecting using your gem (using it through action_cable_client, but I believe that's irrelevant). Anyway, event machine supports reconnecting, but the method is not exposed in WebSocket::EventMachine::Client and due to this: eventmachine/eventmachine#218 implementing it is not straight forward.
This is what I've had to do in order to get stable reconnects:
require 'websocket-eventmachine-client'
EventMachine.run do
ws = WebSocket::EventMachine::Client.connect(uri: 'ws://localhost:3000/websocket')
ws.onclose do |code, reason|
puts "Disconnected with status code: #{code}"
EM.add_timer(2) do
EventMachine.reconnect "localhost", 3000, ws
ws.post_init
end
end
end
It should be pretty easy to remember the host and port and implement a simple reconnect method that will take care of firing post_init callback for the user. Let me know if this is something you'd like to see in your gem, I'll prepare a PR.
Metadata
Metadata
Assignees
Labels
No labels