class Adhearsion::CallController::Record::Recorder

Handle a recording

Attributes

record_component[RW]
stopper_component[RW]

Public Class Methods

new(controller, options = {}) click to toggle source

@param [Adhearsion::CallController] controller on which to execute the recording @param [Hash] options @option options [Boolean, Optional] :async Execute asynchronously. Defaults to false @option options [Boolean, Optional] :start_beep Indicates whether subsequent record will be preceded with a beep. Default is false. @option options [Boolean, Optional] :start_paused Whether subsequent record will start in PAUSE mode. Default is false. @option options [String, Optional] :max_duration Indicates the maximum duration (seconds) for a recording. @option options [String, Optional] :format File format used during recording. @option options [String, Optional] :initial_timeout Controls how long (seconds) the recognizer should wait after the end of the prompt for the caller to speak before sending a Recorder event. @option options [String, Optional] :final_timeout Controls the length (seconds) of a period of silence after callers have spoken to conclude they finished. @option options [Boolean, Optional] :interruptible Allows the recording to be terminated by any single DTMF key, default is false @option options [Symbol, Optional] :direction Controls which sides of the conversation are recorded: :recv (what the caller hears), :send (what the caller said), or :duplex (both)

# File lib/adhearsion/call_controller/record.rb, line 27
def initialize(controller, options = {})
  @controller = controller

  options = prep_options options

  @async = options.delete :async

  interruptible = options.delete :interruptible
  @stopper_component  = interruptible ? setup_stopper(interruptible) : nil
  @record_component   = Punchblock::Component::Record.new options
end

Public Instance Methods

handle_record_completion(&block) click to toggle source

Set a callback to be executed when recording completes

@yield [Punchblock::Event::Complete] the complete Event for the recording

# File lib/adhearsion/call_controller/record.rb, line 56
def handle_record_completion(&block)
  @record_component.register_event_handler Punchblock::Event::Complete, &block
end
run() click to toggle source

Execute the recorder

@return nil

# File lib/adhearsion/call_controller/record.rb, line 44
def run
  execute_stopper
  execute_recording
  terminate_stopper
  nil
end

Private Instance Methods

execute_recording() click to toggle source
# File lib/adhearsion/call_controller/record.rb, line 78
def execute_recording
  if @async
    @controller.write_and_await_response @record_component
  else
    @controller.execute_component_and_await_completion @record_component
  end
end
execute_stopper() click to toggle source
# File lib/adhearsion/call_controller/record.rb, line 74
def execute_stopper
  @controller.write_and_await_response @stopper_component if @stopper_component
end
prep_options(opts) click to toggle source
# File lib/adhearsion/call_controller/record.rb, line 90
def prep_options(opts)
  opts.dup.tap do |options|
    [:max_duration, :initial_timeout, :final_timeout].each do |k|
      options[k] = options[k] * 1000 if options[k]
    end
  end
end
setup_stopper(interrupt_digits) click to toggle source
# File lib/adhearsion/call_controller/record.rb, line 62
def setup_stopper(interrupt_digits)
  interrupt_digits = interrupt_digits == true ? '0123456789#*' : interrupt_digits.to_s
  @stopper_component = Punchblock::Component::Input.new :mode => :dtmf,
    :grammar => {
      :value => @controller.grammar_accept(interrupt_digits)
    }
  @stopper_component.register_event_handler Punchblock::Event::Complete do |event|
    @record_component.stop! unless @record_component.complete?
  end
  @stopper_component
end
terminate_stopper() click to toggle source
# File lib/adhearsion/call_controller/record.rb, line 86
def terminate_stopper
  @stopper_component.stop! if @stopper_component && !@stopper_component.complete?
end