Class: Punchblock::Translator::Asterisk::Component::Output

Inherits:
Component show all
Includes:
StopByRedirect
Defined in:
lib/punchblock/translator/asterisk/component/output.rb

Constant Summary

UnrenderableDocError =
Class.new OptionError
UniMRCPError =
Class.new Punchblock::Error
PlaybackError =
Class.new Punchblock::Error

Instance Attribute Summary

Attributes inherited from Component

#call, #call_id, #id

Instance Method Summary (collapse)

Methods included from StopByRedirect

#execute_command

Methods inherited from Component

#call_ended, #execute_command, #initialize, #logger_id, #send_complete_event, #send_event, #setup

Constructor Details

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

Instance Method Details

- (Object) execute



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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/punchblock/translator/asterisk/component/output.rb', line 17

def execute
  raise OptionError, 'An SSML document is required.' unless @component_node.render_documents.first.value
  raise OptionError, 'An interrupt-on value of speech is unsupported.' if @component_node.interrupt_on == :voice

  [:start_offset, :start_paused, :repeat_interval, :max_time].each do |opt|
    raise OptionError, "A #{opt} value is unsupported on Asterisk." if @component_node.send opt
  end

  @early = !@call.answered?

  rendering_engine = @component_node.renderer || :asterisk

  repeat_times = @component_node.repeat_times || 1
  repeat_times = 1000 if repeat_times.zero?

  case rendering_engine.to_sym
  when :asterisk
    validate_audio_only
    setup_for_native

    repeat_times.times do
      render_docs.each do |doc|
        playback(filenames(doc).values) || raise(PlaybackError)
      end
    end
  when :native_or_unimrcp
    setup_for_native

    repeat_times.times do
      render_docs.each do |doc|
        doc.value.children.each do |node|
          case node
          when RubySpeech::SSML::Audio
            playback([path_for_audio_node(node)]) || render_with_unimrcp(fallback_doc(doc, node))
          when String
            if node.include?(' ')
              render_with_unimrcp(copied_doc(doc, node))
            else
              playback([node]) || render_with_unimrcp(copied_doc(doc, node))
            end
          else
            render_with_unimrcp(copied_doc(doc, node.node))
          end
        end
      end
    end
  when :unimrcp
    send_progress_if_necessary
    send_ref
    repeat_times.times do
      render_with_unimrcp(*render_docs)
    end
  when :swift
    send_progress_if_necessary
    send_ref
    @call.execute_agi_command 'EXEC Swift', swift_doc
  else
    raise OptionError, "The renderer #{rendering_engine} is unsupported."
  end
  send_finish
rescue ChannelGoneError
  call_ended
rescue PlaybackError
  complete_with_error 'Terminated due to playback error'
rescue UniMRCPError
  complete_with_error 'Terminated due to UniMRCP error'
rescue RubyAMI::Error => e
  complete_with_error "Terminated due to AMI error '#{e.message}'"
rescue UnrenderableDocError => e
  with_error 'unrenderable document error', e.message
rescue OptionError => e
  with_error 'option error', e.message
end

- (Object) stop_by_redirect(*args)



91
92
93
94
# File 'lib/punchblock/translator/asterisk/component/output.rb', line 91

def stop_by_redirect(*args)
  @stopped = true
  super
end