Class: Punchblock::Connection::Asterisk

Inherits:
GenericConnection show all
Defined in:
lib/punchblock/connection/asterisk.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from GenericConnection

#connected?, #not_ready!, #ready!

Constructor Details

#initialize(options = {}) ⇒ Asterisk

Returns a new instance of Asterisk.



11
12
13
14
15
# File 'lib/punchblock/connection/asterisk.rb', line 11

def initialize(options = {})
  @ami_client = RubyAMI::Client.new options.merge(:event_handler => lambda { |event| translator.handle_ami_event! event }, :logger => pb_logger)
  @translator = Translator::Asterisk.new @ami_client, self, options[:media_engine]
  super()
end

Instance Attribute Details

#ami_clientObject (readonly)

Returns the value of attribute ami_client.



8
9
10
# File 'lib/punchblock/connection/asterisk.rb', line 8

def ami_client
  @ami_client
end

#event_handlerObject

Returns the value of attribute event_handler.



9
10
11
# File 'lib/punchblock/connection/asterisk.rb', line 9

def event_handler
  @event_handler
end

#translatorObject (readonly)

Returns the value of attribute translator.



8
9
10
# File 'lib/punchblock/connection/asterisk.rb', line 8

def translator
  @translator
end

Instance Method Details

#handle_event(event) ⇒ Object



31
32
33
# File 'lib/punchblock/connection/asterisk.rb', line 31

def handle_event(event)
  event_handler.call event
end

#runObject

Raises:



17
18
19
20
# File 'lib/punchblock/connection/asterisk.rb', line 17

def run
  ami_client.start
  raise DisconnectedError
end

#stopObject



22
23
24
25
# File 'lib/punchblock/connection/asterisk.rb', line 22

def stop
  translator.shutdown!
  ami_client.stop
end

#write(command, options) ⇒ Object



27
28
29
# File 'lib/punchblock/connection/asterisk.rb', line 27

def write(command, options)
  translator.execute_command! command, options
end