Class: Signalwire::Relay::Calling::Play

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

Instance Attribute Summary

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:, play:, volume: nil) ⇒ Play

Returns a new instance of Play.



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

def initialize(call:, play:, volume: nil)
  super(call: call)
  @play = play
  @volume = volume
end

Instance Method Details

#broadcast_event(event) ⇒ Object



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

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

#event_typeObject



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

def event_type
  Relay::CallNotification::PLAY
end

#inner_paramsObject



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

def inner_params
  prm = {
    node_id: @call.node_id,
    call_id: @call.id,
    control_id: control_id,
    play: @play
  }

  prm[:volume] = @volume unless @volume.nil?
  prm
end

#methodObject



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

def method
  Relay::ComponentMethod::PLAY
end

#notification_handler(event) ⇒ Object



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

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

  @completed = @state != Relay::CallPlayState::PLAYING

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

  broadcast_event(event)
  check_for_waiting_events
end

#pauseObject



50
51
52
# File 'lib/signalwire/relay/calling/component/play.rb', line 50

def pause
  execute_subcommand '.pause', Signalwire::Relay::Calling::PlayPauseResult
end

#resumeObject



54
55
56
# File 'lib/signalwire/relay/calling/component/play.rb', line 54

def resume
  execute_subcommand '.resume', Signalwire::Relay::Calling::PlayResumeResult
end

#volume(setting) ⇒ Object



58
59
60
# File 'lib/signalwire/relay/calling/component/play.rb', line 58

def volume(setting)
  execute_subcommand '.volume', Signalwire::Relay::Calling::PlayVolumeResult, { volume: setting }
end