Class: AdhearsionCpa::ToneDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/adhearsion_cpa/tone_detector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ ToneDetector

Returns a new instance of ToneDetector.



6
7
8
# File 'lib/adhearsion_cpa/tone_detector.rb', line 6

def initialize(controller)
  @controller = controller
end

Instance Attribute Details

#timeoutObject

Returns the value of attribute timeout.



4
5
6
# File 'lib/adhearsion_cpa/tone_detector.rb', line 4

def timeout
  @timeout
end

#tonesObject

Returns the value of attribute tones.



4
5
6
# File 'lib/adhearsion_cpa/tone_detector.rb', line 4

def tones
  @tones
end

Instance Method Details

#detect_tones(tones, options) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/adhearsion_cpa/tone_detector.rb', line 10

def detect_tones(tones, options)
  @tones = tones
  process options

  component.register_event_handler Punchblock::Component::Input::Signal do |event|
    yield event if block_given?
  end if async?

  call.write_and_await_response component if call_alive?

  if async?
    call.after(timeout) do
      if component_running?
        component.stop!
      end
    end

    component
  else
    component.complete_event(timeout).reason
  end
rescue Timeout::Error
  component.stop! if component_running?
  nil
end