Class: Librevox::Listener::Inbound

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

Class Attribute Summary collapse

Attributes inherited from Base

#response

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#api, #disconnect, event, #handle_response, hooks, #on_event, #receive_message, #send_message

Constructor Details

#initialize(connection, args = {}) ⇒ Inbound

Returns a new instance of Inbound.



27
28
29
30
# File 'lib/librevox/listener/inbound.rb', line 27

def initialize(connection, args = {})
  super(connection)
  @auth = args[:auth] || "ClueCon"
end

Class Attribute Details

.subscribe_eventsObject (readonly)

Returns the value of attribute subscribe_events.



9
10
11
# File 'lib/librevox/listener/inbound.rb', line 9

def subscribe_events
  @subscribe_events
end

.subscribe_filtersObject (readonly)

Returns the value of attribute subscribe_filters.



10
11
12
# File 'lib/librevox/listener/inbound.rb', line 10

def subscribe_filters
  @subscribe_filters
end

Class Method Details

.events(events) ⇒ Object



12
13
14
# File 'lib/librevox/listener/inbound.rb', line 12

def events(events)
  @subscribe_events = events
end

.filters(filters) ⇒ Object



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

def filters(filters)
  @subscribe_filters = filters
end

.run(barrier, host: "localhost", port: 8021, **options) ⇒ Object



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

def self.run(barrier, host: "localhost", port: 8021, **options)
  endpoint = IO::Endpoint.tcp(host, port)
  client = Client.new(self, endpoint, **options)
  barrier.async { client.run }
end

Instance Method Details

#connection_completedObject



50
51
# File 'lib/librevox/listener/inbound.rb', line 50

def connection_completed
end

#run_sessionObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/librevox/listener/inbound.rb', line 32

def run_session
  Librevox.logger.info "Connected."

  send_message "auth #{@auth}"

  events = self.class.subscribe_events || ['ALL']
  send_message "event plain #{events.join(' ')}"

  filters = self.class.subscribe_filters || {}
  filters.each do |header, values|
    [*values].each do |value|
      send_message "filter #{header} #{value}"
    end
  end

  connection_completed
end