Class: Punchblock::Translator::Asterisk::Component::Record

Inherits:
Component show all
Defined in:
lib/punchblock/translator/asterisk/component/record.rb

Constant Summary collapse

RECORDING_BASE_PATH =
'/var/punchblock/record'

Constants inherited from Component

Component::OptionError

Instance Attribute Summary

Attributes inherited from Component

#call, #call_id, #id, #internal

Instance Method Summary collapse

Methods inherited from Component

#call_ended, #initialize, #logger_id, #send_event

Methods included from DeadActorSafety

#safe_from_dead_actors

Constructor Details

This class inherits a constructor from Punchblock::Translator::Asterisk::Component::Component

Instance Method Details

#executeObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/punchblock/translator/asterisk/component/record.rb', line 14

def execute
  max_duration = @component_node.max_duration || -1

  raise OptionError, 'Record cannot be used on a call that is not answered.' unless @call.answered?
  raise OptionError, 'A start-paused value of true is unsupported.' if @component_node.start_paused
  raise OptionError, 'An initial-timeout value is unsupported.' if @component_node.initial_timeout && @component_node.initial_timeout != -1
  raise OptionError, 'A final-timeout value is unsupported.' if @component_node.final_timeout && @component_node.final_timeout != -1
  raise OptionError, 'A max-duration value that is negative (and not -1) is invalid.' unless max_duration >= -1

  @format = @component_node.format || 'wav'


  component = current_actor
  call.register_handler :ami, :name => 'MonitorStop' do |event|
    component.finished
  end

  send_ref

  if @component_node.start_beep
    pb_logger.debug "Playing a beep via STREAM FILE before recording"
    @call.send_agi_action! 'STREAM FILE', 'beep', '""' do
      component.signal! :beep_finished
    end
    wait :beep_finished
  end

  call.send_ami_action! 'Monitor', 'Channel' => call.channel, 'File' => filename, 'Format' => @format, 'Mix' => true
  unless max_duration == -1
    after max_duration/1000 do
      pb_logger.trace "Max duration encountered, stopping recording"
      call.send_ami_action! 'StopMonitor', 'Channel' => call.channel
    end
  end
rescue OptionError => e
  with_error 'option error', e.message
end

#execute_command(command) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/punchblock/translator/asterisk/component/record.rb', line 52

def execute_command(command)
  case command
  when Punchblock::Component::Stop
    command.response = true
    a = current_actor
    call.send_ami_action! 'StopMonitor', 'Channel' => call.channel do |complete_event|
      @complete_reason = stop_reason
    end
  when Punchblock::Component::Record::Pause
    a = current_actor
    call.send_ami_action! 'PauseMonitor', 'Channel' => call.channel do |complete_event|
      command.response = true
    end
  when Punchblock::Component::Record::Resume
    a = current_actor
    call.send_ami_action! 'ResumeMonitor', 'Channel' => call.channel do |complete_event|
      command.response = true
    end
  else
    super
  end
end

#finishedObject



75
76
77
# File 'lib/punchblock/translator/asterisk/component/record.rb', line 75

def finished
  send_complete_event(@complete_reason || success_reason)
end

#setupObject



10
11
12
# File 'lib/punchblock/translator/asterisk/component/record.rb', line 10

def setup
  @complete_reason = nil
end