Class: Signalwire::Relay::Calling::ControlComponent

Inherits:
Component
  • Object
show all
Defined in:
lib/signalwire/relay/calling/control_component.rb

Direct Known Subclasses

BaseFax, Detect, Play, Prompt, Record, SendDigits, Tap

Instance Attribute Summary

Attributes inherited from Component

#blocker, #call, #completed, #event, #execute_result, #state, #successful

Instance Method Summary collapse

Methods inherited from Component

#after_execute, #check_for_waiting_events, #create_blocker, #event_type, #execute, #execute_params, #handle_execute_result, #has_blocker?, #initialize, #method, #notification_handler, #payload, #setup_waiting_events, #terminate, #unblock, #wait_for, #wait_on_blocker

Methods included from Logger

#level=, #logger, logger

Constructor Details

This class inherits a constructor from Signalwire::Relay::Calling::Component

Instance Method Details

#control_idObject



7
8
9
# File 'lib/signalwire/relay/calling/control_component.rb', line 7

def control_id
  @control_id ||= SecureRandom.uuid
end

#execute_subcommand(suffix, result_klass, extra_params = {}) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/signalwire/relay/calling/control_component.rb', line 30

def execute_subcommand(suffix, result_klass, extra_params = {})
  @call.relay_execute execute_params('.stop', extra_params) do |event, outcome|
    succeeded = outcome == :success
    terminate(event) unless succeeded

    return result_klass.new(succeeded)
  end
end

#inner_paramsObject



11
12
13
14
15
16
17
18
# File 'lib/signalwire/relay/calling/control_component.rb', line 11

def inner_params
  {
    nodeid: @call.node_id,
    callid: @call.id,
    control_id: control_id,
    params: payload
  }
end

#setup_handlersObject



20
21
22
23
24
# File 'lib/signalwire/relay/calling/control_component.rb', line 20

def setup_handlers
  @call.on :event, event_type: event_type, control_id: control_id do |evt|
    notification_handler(evt)
  end
end

#stopObject



26
27
28
# File 'lib/signalwire/relay/calling/control_component.rb', line 26

def stop
  execute_subcommand '.stop', Signalwire::Relay::Calling::StopResult
end