Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reconnect! method not calling the connected callback? #33

Open
damuz91 opened this issue Feb 8, 2020 · 1 comment
Open

reconnect! method not calling the connected callback? #33

damuz91 opened this issue Feb 8, 2020 · 1 comment

Comments

@damuz91
Copy link

damuz91 commented Feb 8, 2020

Hi,
Just saw the PR that implemented the reconnect! method. I am actually using it but i noticed it doesn't calls back the connected callback. What i am doing to trigger the disconnect the callback is just shutting down the ActionCable server in a different process, then turning it back on immediately.

Here is my sample code:

require 'action_cable_client'

EventMachine.run do

  @connected = false
  device_id = 1
  uri = 'ws://localhost:3001/cable'
  params = {
    channel: 'DevicesChannel'
  }
  headers = {
    :Origin => 'ws://localhost:3001/cable',
    :device_id => device_id
  }

  client = ActionCableClient.new(uri, params, true, headers)

  client.connected do
    @connected = true
    puts 'successfully connected.'
  end

  client.received do |message|
    p message
  end

  client.subscribed do
    puts "-> Subscribed!"
  end

  client.disconnected do
    @connected = false
    while !@connected
      puts "-> Disconnected, trying to reconnect in 5 seconds"
      sleep 5
      client.reconnect!
      puts "-> Client inspect: #{client.inspect}"
    end
  end

  client.errored do |e|
    @connected = false
    puts "-> Errored #{e}."
  end

end

I expected the reconnect method to start over all callbacks again. Maybe i need to subscribe all callbacks again? I think that would cause infinite loops.

Here is my console output:

Davids-MacBook-Air:keypad-firmware damuz91$ ruby app/keypad_socket.rb 
successfully connected.
-> Subscribed!
-> Disconnected, trying to reconnect in 15 seconds
-> Client inspect: #<ActionCableClient:0x00007fd6be9c8a28 @_uri="ws://localhost:3001/cable", @message_queue=[], @_subscribed=false, @_message_factory=#<ActionCableClient::MessageFactory:0x00007fd6be9c8988 @channel={:channel=>"KeypadsChannel"}, @identifier={:channel=>"KeypadsChannel"}>, @_websocket_client=#<WebSocket::EventMachine::Client:0x00007fd6be9c85a0 @signature=3, @args={:uri=>"ws://localhost:3001/cable", :headers=>{:Origin=>"ws://localhost:3001/cable", :keypad_id=>1}, :tls=>{}}, @state=:connecting, @handshake=<WebSocket::Handshake::Client:0x3feb5f83fcb8 @uri="ws://localhost:3001/cable", @headers={:Origin=>"ws://localhost:3001/cable", :device_id=>1}, @tls={}, @state=:new, @handler=#<WebSocket::Handshake::Handler::Client11:0x00007fd6bf07ef48 @handshake=<WebSocket::Handshake::Client:0x3feb5f83fcb8 @uri="ws://localhost:3001/cable", @headers={:Origin=>"ws://localhost:3001/cable", :device_id=>1}, @tls={}, @state=:new, @handler=#<WebSocket::Handshake::Handler::Client11:0x00007fd6bf07ef48 ...>, @data="", @protocols=[], @secure=false, @host="localhost", @port=3001, @path="/cable", @query=nil, @version=13>>, @data="", @protocols=[], @secure=false, @host="localhost", @port=3001, @path="/cable", @query=nil, @version=13>, @onclose=#<Proc:0x00007fd6bf840498@/Users/damuz91/.rvm/gems/ruby-2.6.0/gems/action_cable_client-3.1.0/lib/action_cable_client.rb:64>, @onmessage=#<Proc:0x00007fd6bf84b140@/Users/damuz91/.rvm/gems/ruby-2.6.0/gems/action_cable_client-3.1.0/lib/action_cable_client.rb:92>, @onerror=#<Proc:0x00007fd6bf84a600@app/keypad_socket.rb:52>, @frame=<WebSocket::Frame::Incoming::Client:0x3feb6040d6a8 @decoded=false, @code=nil, @data="", @version=13, @handler=#<WebSocket::Frame::Handler::Handler07:0x00007fd6bf064b70 @frame=<WebSocket::Frame::Incoming::Client:0x3feb6040d6a8 @decoded=false, @code=nil, @data="", @version=13, @handler=#<WebSocket::Frame::Handler::Handler07:0x00007fd6bf064b70 ...>>>>>, @_connected_callback=#<Proc:0x00007fd6bf84b5a0@/Users/damuz91/.rvm/gems/ruby-2.6.0/gems/action_cable_client-3.1.0/lib/action_cable_client.rb:107>, @_subscribed_callback=#<Proc:0x00007fd6bf84afb0@app/keypad_socket.rb:37>, @_disconnected_callback=#<Proc:0x00007fd6bf84aad8@/Users/damuz91/.rvm/gems/ruby-2.6.0/gems/action_cable_client-3.1.0/lib/action_cable_client.rb:143>>
-> Disconnected, trying to reconnect in 5 seconds
@NullVoxPopuli
Copy link
Owner

Would you be willing to submit a PR? :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants