Class: SignalWire::Relay::DetectAction

Inherits:
Action
  • Object
show all
Defined in:
lib/signalwire/relay/action.rb

Overview

Handle for an active detect operation.

Instance Attribute Summary

Attributes inherited from Action

#call, #completed, #control_id, #result

Instance Method Summary collapse

Methods inherited from Action

#_resolve, #_set_on_completed, #done?, #on_completed, #wait

Constructor Details

#initialize(call, control_id) ⇒ DetectAction

Returns a new instance of DetectAction.



144
145
146
# File 'lib/signalwire/relay/action.rb', line 144

def initialize(call, control_id)
  super(call, control_id, EVENT_CALL_DETECT, %w[finished error])
end

Instance Method Details

#_check_event(event) ⇒ Object

Detect delivers results continuously. Resolve on first result or when finished/error.



150
151
152
153
154
155
156
# File 'lib/signalwire/relay/action.rb', line 150

def _check_event(event)
  detect = event.params['detect'] || {}
  state  = event.params['state'] || ''
  if (!detect.empty? || @terminal_states.include?(state)) && !@completed
    _resolve(event)
  end
end

#stopObject



158
159
160
# File 'lib/signalwire/relay/action.rb', line 158

def stop
  @call._execute('detect.stop', { 'control_id' => @control_id })
end