Class: Librevox::Listener::Inbound

Inherits:
Base
  • Object
show all
Defined in:
lib/librevox/listener/inbound.rb

Instance Attribute Summary

Attributes inherited from Base

#response

Instance Method Summary collapse

Methods inherited from Base

#api, #command, event, #handle_response, hooks, #on_event, #post_init, #receive_request

Constructor Details

#initialize(args = {}) ⇒ Inbound

Returns a new instance of Inbound.



6
7
8
9
10
11
12
13
# File 'lib/librevox/listener/inbound.rb', line 6

def initialize args={}
  super

  @auth = args[:auth] || "ClueCon"
  @host, @port = args.values_at(:host, :port)

  EventMachine.add_shutdown_hook {@shutdown = true}
end

Instance Method Details

#connection_completedObject



15
16
17
18
19
20
# File 'lib/librevox/listener/inbound.rb', line 15

def connection_completed
  Librevox.logger.info "Connected."
  super
  send_data "auth #{@auth}\n\n"
  send_data "event plain ALL\n\n"
end

#unbindObject



22
23
24
25
26
27
# File 'lib/librevox/listener/inbound.rb', line 22

def unbind
  if !@shutdown
    Librevox.logger.error "Lost connection. Reconnecting in 1 second."
    EM.add_timer(1) {reconnect(@host, @port.to_i)}
  end
end