Class: Librevox::CommandSocket

Inherits:
Object
  • Object
show all
Includes:
Commands
Defined in:
lib/librevox/command_socket.rb

Instance Method Summary collapse

Methods included from Commands

#fsctl, #hash, #hupall, #originate, #status, #uuid_bridge, #uuid_park

Constructor Details

#initialize(args = {}) ⇒ CommandSocket

Returns a new instance of CommandSocket.



10
11
12
13
14
15
16
# File 'lib/librevox/command_socket.rb', line 10

def initialize(args = {})
  @server   = args[:server] || "127.0.0.1"
  @port     = args[:port] || "8021"
  @auth     = args[:auth] || "ClueCon"

  connect unless args[:connect] == false
end

Instance Method Details

#application(uuid, app, args = nil, **params) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/librevox/command_socket.rb', line 40

def application(uuid, app, args = nil, **params)
  headers = params
    .merge(
      event_lock:       true,
      call_command:     "execute",
      execute_app_name: app,
      execute_app_arg:  args,
    )
    .map { |key, value| "#{key.to_s.tr('_', '-')}: #{value}" }

  send_message "sendmsg #{uuid}\n#{headers.join("\n")}"
end

#closeObject



53
54
55
# File 'lib/librevox/command_socket.rb', line 53

def close
  @connection.close
end

#command(*args) ⇒ Object



30
31
32
# File 'lib/librevox/command_socket.rb', line 30

def command(*args)
  send_message(super(*args))
end

#connectObject



18
19
20
21
22
23
# File 'lib/librevox/command_socket.rb', line 18

def connect
  socket = TCPSocket.open(@server, @port)
  stream = IO::Stream(socket)
  @connection = Protocol::Connection.new(stream)
  send_message "auth #{@auth}"
end

#read_responseObject



34
35
36
37
38
# File 'lib/librevox/command_socket.rb', line 34

def read_response
  while msg = @connection.read_message
    return msg if msg.command_reply? || msg.api_response?
  end
end

#send_message(msg) ⇒ Object



25
26
27
28
# File 'lib/librevox/command_socket.rb', line 25

def send_message(msg)
  @connection.send_message(msg)
  read_response
end