Class: Signalwire::Relay::Calling::Record

Inherits:
ControlComponent show all
Defined in:
lib/signalwire/relay/calling/component/record.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

#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:, record:) ⇒ Record

Returns a new instance of Record.



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

def initialize(call:, record:)
  super(call: call)
  @record = record
end

Instance Attribute Details

#durationObject (readonly)

Returns the value of attribute duration.



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

def duration
  @duration
end

#sizeObject (readonly)

Returns the value of attribute size.



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

def size
  @size
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#after_execute(execute_event) ⇒ Object



53
54
55
# File 'lib/signalwire/relay/calling/component/record.rb', line 53

def after_execute(execute_event)
  @url = execute_event.dig(:params, :params, :params, :url) if execute_event
end

#broadcast_event(event) ⇒ Object



48
49
50
51
# File 'lib/signalwire/relay/calling/component/record.rb', line 48

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

#event_typeObject



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

def event_type
  Relay::CallNotification::RECORD
end

#inner_paramsObject



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

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

#methodObject



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

def method
  Relay::ComponentMethod::RECORD
end

#notification_handler(event) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/signalwire/relay/calling/component/record.rb', line 28

def notification_handler(event)
  @state = event.call_params[:state]
  url = event.call_params[:url]
  duration = event.call_params[:duration]
  size = event.call_params[:size]

  @completed = @state != Relay::CallRecordState::RECORDING

  if @completed
    @successful = @state == Relay::CallRecordState::FINISHED
    @url = url
    @duration = duration
    @size = size
    @event = event
  end

  broadcast_event(event)
  check_for_waiting_events
end