Class: Signalwire::Relay::Calling::Tap

Inherits:
ControlComponent show all
Defined in:
lib/signalwire/relay/calling/component/tap.rb

Instance Attribute Summary collapse

Attributes inherited from Component

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

Instance Method Summary collapse

Methods inherited from ControlComponent

#control_id, #execute_subcommand, #setup_handlers, #stop

Methods inherited from Component

#after_execute, #check_for_waiting_events, #create_blocker, #execute, #execute_params, #handle_execute_result, #has_blocker?, #payload, #setup_handlers, #setup_waiting_events, #terminate, #unblock, #wait_for, #wait_on_blocker

Methods included from Logger

#level=, #logger, logger

Constructor Details

#initialize(call:, tap:, device:) ⇒ Tap

Returns a new instance of Tap.



7
8
9
10
11
# File 'lib/signalwire/relay/calling/component/tap.rb', line 7

def initialize(call:, tap:, device:)
  super(call: call)
  @tap = tap
  @device = device
end

Instance Attribute Details

#deviceObject

Returns the value of attribute device.



5
6
7
# File 'lib/signalwire/relay/calling/component/tap.rb', line 5

def device
  @device
end

Instance Method Details

#broadcast_event(event) ⇒ Object



56
57
58
59
# File 'lib/signalwire/relay/calling/component/tap.rb', line 56

def broadcast_event(event)
  @call.broadcast "tap_#{@state}".to_sym, event
  @call.broadcast :tap_state_change, event
end

#event_typeObject



17
18
19
# File 'lib/signalwire/relay/calling/component/tap.rb', line 17

def event_type
  Relay::CallNotification::TAP
end

#inner_paramsObject



27
28
29
30
31
32
33
34
35
# File 'lib/signalwire/relay/calling/component/tap.rb', line 27

def inner_params
  {
    node_id: @call.node_id,
    call_id: @call.id,
    control_id: control_id,
    tap: @tap,
    device: @device
  }
end

#methodObject



13
14
15
# File 'lib/signalwire/relay/calling/component/tap.rb', line 13

def method
  Relay::ComponentMethod::TAP
end

#notification_handler(event) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/signalwire/relay/calling/component/tap.rb', line 41

def notification_handler(event)
  @state = event.call_params[:state]
  @device = event.call_params[:device]
  @tap = event.call_params[:tap]

  @completed = @state == Relay::CallTapState::FINISHED
  if @completed
    @successful = true
    @event = event
  end

  broadcast_event(event)
  check_for_waiting_events
end

#source_deviceObject



21
22
23
24
25
# File 'lib/signalwire/relay/calling/component/tap.rb', line 21

def source_device
  return unless @execute_result

  @execute_result.dig(:result, :result, :source_device)
end

#tap_mediaObject



37
38
39
# File 'lib/signalwire/relay/calling/component/tap.rb', line 37

def tap_media
  @tap
end