Class: Signalwire::Relay::Calling::Connect

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

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, #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:, devices:, ringback: nil) ⇒ Connect

Returns a new instance of Connect.



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

def initialize(call:, devices:, ringback: nil)
  super(call: call)
  @devices = devices
  @ringback = ringback
end

Instance Method Details

#broadcast_event(event) ⇒ Object



44
45
46
47
# File 'lib/signalwire/relay/calling/component/connect.rb', line 44

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

#event_typeObject



15
16
17
# File 'lib/signalwire/relay/calling/component/connect.rb', line 15

def event_type
  Relay::CallNotification::CONNECT
end

#inner_paramsObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/signalwire/relay/calling/component/connect.rb', line 19

def inner_params
  params = {
    node_id: @call.node_id,
    call_id: @call.id,
    devices: @devices
  }

  params[:ringback] = @ringback unless @ringback.nil?
  params
end

#methodObject



11
12
13
# File 'lib/signalwire/relay/calling/component/connect.rb', line 11

def method
  Relay::ComponentMethod::CONNECT
end

#notification_handler(event) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/signalwire/relay/calling/component/connect.rb', line 30

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

  @completed = @state != Relay::CallConnectState::CONNECTING

  if @completed
    @successful = @state == Relay::CallConnectState::CONNECTED
    @event = event
  end

  broadcast_event(event)
  check_for_waiting_events
end