class Punchblock::Translator::Freeswitch::Component::Record

Constants

RECORDING_BASE_PATH

Public Instance Methods

execute() click to toggle source
# File lib/punchblock/translator/freeswitch/component/record.rb, line 14
def execute
  max_duration = @component_node.max_duration || -1
  initial_timeout = @component_node.initial_timeout || -1
  final_timeout = @component_node.final_timeout || -1

  raise OptionError, 'A start-beep value of true is unsupported.' if @component_node.start_beep
  raise OptionError, 'A start-paused value of true is unsupported.' if @component_node.start_paused
  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 :es, :event_name => 'RECORD_STOP', [:[], :record_file_path] => filename do |event|
    component.finished
  end

  record_args = ['start', filename]
  record_args << max_duration/1000 unless max_duration == -1

  direction = case @component_node.direction
  when :send then :RECORD_WRITE_ONLY
  when :recv then :RECORD_READ_ONLY
  else            :RECORD_STEREO
  end
  setvar direction, true

  setvar :RECORD_INITIAL_TIMEOUT_MS, initial_timeout > -1 ? initial_timeout : 0
  setvar :RECORD_FINAL_TIMEOUT_MS, final_timeout > -1 ? final_timeout : 0

  call.uuid_foo :record, record_args.join(' ')
  send_ref
rescue OptionError => e
  with_error 'option error', e.message
end
execute_command(command) click to toggle source
# File lib/punchblock/translator/freeswitch/component/record.rb, line 49
def execute_command(command)
  case command
  when Punchblock::Component::Stop
    call.uuid_foo :record, "stop #{filename}"
    @complete_reason = stop_reason
    command.response = true
  else
    super
  end
end
finished() click to toggle source
# File lib/punchblock/translator/freeswitch/component/record.rb, line 60
def finished
  send_complete_event(@complete_reason || max_duration_reason)
end
setup() click to toggle source
# File lib/punchblock/translator/freeswitch/component/record.rb, line 10
def setup
  @complete_reason = nil
end

Private Instance Methods

filename() click to toggle source
# File lib/punchblock/translator/freeswitch/component/record.rb, line 70
def filename
  File.join RECORDING_BASE_PATH, [id, @format].join('.')
end
max_duration_reason() click to toggle source
# File lib/punchblock/translator/freeswitch/component/record.rb, line 82
def max_duration_reason
  Punchblock::Component::Record::Complete::MaxDuration.new
end
recording() click to toggle source
# File lib/punchblock/translator/freeswitch/component/record.rb, line 74
def recording
  Punchblock::Component::Record::Recording.new :uri => "file://#{filename}"
end
send_complete_event(reason) click to toggle source
# File lib/punchblock/translator/freeswitch/component/record.rb, line 86
def send_complete_event(reason)
  super reason, recording
end
setvar(key, value) click to toggle source
# File lib/punchblock/translator/freeswitch/component/record.rb, line 66
def setvar(key, value)
  call.uuid_foo :setvar, "#{key} #{value}"
end
stop_reason() click to toggle source
# File lib/punchblock/translator/freeswitch/component/record.rb, line 78
def stop_reason
  Punchblock::Event::Complete::Stop.new
end