Method: AGI#stream_file

Defined in:
lib/AGI.rb

#stream_file(file, digits = '', offset = nil) ⇒ Object

Signals Asterisk to stream the given audio file to the channel starting at an optional offset until either the entire file has been streamed or the user provides one of a set of DTMF digits.

Returns an AGIResponse including the DTMF digit provided by the channel.



885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
# File 'lib/AGI.rb', line 885

def stream_file(file, digits='', offset=nil)
  digits.gsub!(/['"]/, '')
  response = AGIResponse.new
  if offset.nil? then
    command_str = "STREAM FILE #{file} '#{digits}'"
  else
    command_Str = "STREAM FILE #{file} ''#{digits}' #{offset}"
  end
  begin
    response.native = execute(command_str)
  rescue AGITimeoutError, AGICommandError, AGIHangupError
    raise
  end
  if response.native == -1 then
    raise AGIChannelError.new(@last_response, "Channel Failure in (#{command_str})")
  elsif response.native == 0
    response.success = true
  else
    response.success = true
    response.data = response.native.chr
  end
  return response
end