Class: Punchblock::Connection::Freeswitch

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from GenericConnection

#connected?, #not_ready!, #ready!

Constructor Details

#initialize(options = {}) ⇒ Freeswitch

Returns a new instance of Freeswitch.



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

def initialize(options = {})
  @translator = Translator::Freeswitch.new self
  @stream_options = options.values_at(:host, :port, :password)
  @stream = new_fs_stream
  super()
end

Instance Attribute Details

#event_handlerObject

Returns the value of attribute event_handler.



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

def event_handler
  @event_handler
end

#streamObject (readonly)

Returns the value of attribute stream.



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

def stream
  @stream
end

#translatorObject (readonly)

Returns the value of attribute translator.



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

def translator
  @translator
end

Instance Method Details

#handle_event(event) ⇒ Object



33
34
35
# File 'lib/punchblock/connection/freeswitch.rb', line 33

def handle_event(event)
  event_handler.call event if event_handler.respond_to?(:call)
end

#runObject

Raises:



18
19
20
21
22
# File 'lib/punchblock/connection/freeswitch.rb', line 18

def run
  pb_logger.debug "Starting the RubyFS stream"
  start_stream
  raise DisconnectedError
end

#stopObject



24
25
26
27
# File 'lib/punchblock/connection/freeswitch.rb', line 24

def stop
  stream.shutdown
  translator.terminate
end

#write(command, options) ⇒ Object



29
30
31
# File 'lib/punchblock/connection/freeswitch.rb', line 29

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