class Punchblock::Connection::Asterisk

Attributes

ami_client[R]
event_handler[RW]
translator[R]

Public Class Methods

new(options = {}) click to toggle source
Calls superclass method
# File lib/punchblock/connection/asterisk.rb, line 11
def initialize(options = {})
  @stream_options = options.values_at(:host, :port, :username, :password)
  @ami_client = new_ami_stream
  @translator = Translator::Asterisk.new @ami_client, self
  super()
end

Public Instance Methods

handle_event(event) click to toggle source
# File lib/punchblock/connection/asterisk.rb, line 36
def handle_event(event)
  event_handler.call event
end
new_ami_stream() click to toggle source
# File lib/punchblock/connection/asterisk.rb, line 40
def new_ami_stream
  stream = RubyAMI::Stream.new(*@stream_options, ->(event) { translator.async.handle_ami_event event }, pb_logger)
  client = (ami_client || RubyAMIStreamProxy.new(stream))
  client.stream = stream
  client
end
new_call_uri() click to toggle source
# File lib/punchblock/connection/asterisk.rb, line 53
def new_call_uri
  Punchblock.new_uuid
end
run() click to toggle source
# File lib/punchblock/connection/asterisk.rb, line 18
def run
  start_ami_client
  raise DisconnectedError
end
send_message(*args) click to toggle source
# File lib/punchblock/connection/asterisk.rb, line 32
def send_message(*args)
  translator.send_message *args
end
start_ami_client() click to toggle source
# File lib/punchblock/connection/asterisk.rb, line 47
def start_ami_client
  @ami_client = new_ami_stream unless ami_client.alive?
  ami_client.async.run
  Celluloid::Actor.join(ami_client)
end
stop() click to toggle source
# File lib/punchblock/connection/asterisk.rb, line 23
def stop
  translator.terminate
  ami_client.terminate
end
write(command, options) click to toggle source
# File lib/punchblock/connection/asterisk.rb, line 28
def write(command, options)
  translator.async.execute_command command, options
end