Module: Hector::Concerns::KeepAlive

Included in:
Session
Defined in:
lib/hector/concerns/keep_alive.rb

Instance Method Summary collapse

Instance Method Details

#destroy_keep_aliveObject



19
20
21
# File 'lib/hector/concerns/keep_alive.rb', line 19

def destroy_keep_alive
  @heartbeat.stop
end

#initialize_keep_aliveObject



4
5
6
7
# File 'lib/hector/concerns/keep_alive.rb', line 4

def initialize_keep_alive
  @received_pong = true
  @heartbeat = Hector::Heartbeat.new { on_heartbeat }
end

#on_heartbeatObject



9
10
11
12
13
14
15
16
17
# File 'lib/hector/concerns/keep_alive.rb', line 9

def on_heartbeat
  if @received_pong
    @received_pong = false
    respond_with(:ping, Hector.server_name)
  else
    @quit_message = "Ping timeout"
    connection.close_connection(true)
  end
end