class Signalwire::Relay::Calling::Detect

Constants

FINISHED_EVENTS
MACHINE_EVENTS
READY_EVENTS

Attributes

result[R]
type[R]

Public Class Methods

new(call:, detect:, wait_for_beep: false, timeout: 30) click to toggle source
Calls superclass method
# File lib/signalwire/relay/calling/component/detect.rb, line 26
def initialize(call:, detect:, wait_for_beep: false, timeout: 30)
  super(call: call)
  @detect = detect
  @timeout = timeout
  @wait_for_beep = wait_for_beep
  @received_events = Concurrent::Array.new
  @waiting_for_ready = false
end

Public Instance Methods

broadcast_event(event) click to toggle source
# File lib/signalwire/relay/calling/component/detect.rb, line 76
def broadcast_event(event)
  @call.broadcast "detect_#{@state}".to_sym, event
  @call.broadcast :detect_state_change, event
end
event_type() click to toggle source
# File lib/signalwire/relay/calling/component/detect.rb, line 39
def event_type
  Relay::CallNotification::DETECT
end
inner_params() click to toggle source
# File lib/signalwire/relay/calling/component/detect.rb, line 43
def inner_params
  {
    node_id: @call.node_id,
    call_id: @call.id,
    control_id: control_id,
    detect: @detect,
    timeout: @timeout
  }
end
method() click to toggle source
# File lib/signalwire/relay/calling/component/detect.rb, line 35
def method
  Relay::ComponentMethod::DETECT
end
notification_handler(event) click to toggle source
# File lib/signalwire/relay/calling/component/detect.rb, line 53
def notification_handler(event)
  detect_result = event.call_params[:detect]
  @type = detect_result[:type]
  params = detect_result[:params]
  @state = params[:event]

  # if we are detecting digits we are done
  return complete(event) if @type == Relay::CallDetectType::DIGIT

  if @type == 'machine'
    if @wait_for_beep
      return complete(event) if READY_EVENTS.include?(@state)
    else
      return complete(event) if FINISHED_EVENTS.include?(@state)
    end
  else
    check_for_waiting_events
  end
  
  @received_events << @state
  broadcast_event(event)
end

Private Instance Methods

complete(event) click to toggle source
# File lib/signalwire/relay/calling/component/detect.rb, line 83
def complete(event)
  @completed = true
  @event = event
  @result = @state

  @successful = @state != Relay::CallDetectState::ERROR
  unblock(event) if has_blocker?
end