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
Constants inherited from Component
Instance Attribute Summary
Attributes inherited from Component
Instance Method Summary (collapse)
- - (Object) collect_executable_elements
- - (Object) continue(event = nil)
- - (Object) execute
- - (Object) play_audio(path)
- - (Object) process_playback_completion
- - (Object) setup
Methods included from StopByRedirect
Methods inherited from Component
#call_id, #execute_command, #initialize, #logger_id, #send_complete_event, #send_event
Constructor Details
This class inherits a constructor from Punchblock::Translator::Asterisk::Component::Component
Instance Method Details
- (Object) collect_executable_elements
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/punchblock/translator/asterisk/component/output.rb', line 72 def collect_executable_elements @component_node.ssml.children.map do |node| case node when RubySpeech::SSML::Audio lambda { current_actor.play_audio! node.src } when String raise UnrenderableDocError, 'The provided document could not be rendered.' if node.include?(' ') lambda { current_actor.play_audio! node } else raise UnrenderableDocError, 'The provided document could not be rendered.' end end.compact rescue raise UnrenderableDocError, 'The provided document could not be rendered.' end |
- (Object) continue(event = nil)
97 98 99 |
# File 'lib/punchblock/translator/asterisk/component/output.rb', line 97 def continue(event = nil) signal :continue, event end |
- (Object) execute
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 |
# File 'lib/punchblock/translator/asterisk/component/output.rb', line 18 def execute @call.answer_if_not_answered raise OptionError, 'An SSML document is required.' unless @component_node.ssml raise OptionError, 'An interrupt-on value of speech is unsupported.' if @component_node.interrupt_on == :speech [:start_offset, :start_paused, :repeat_interval, :repeat_times, :max_time].each do |opt| raise OptionError, "A #{opt} value is unsupported on Asterisk." if @component_node.send opt end case @media_engine when :asterisk, nil raise OptionError, "A voice value is unsupported on Asterisk." if @component_node.voice @execution_elements = collect_executable_elements @pending_actions = @execution_elements.count send_ref @interrupt_digits = if [:any, :dtmf].include? @component_node.interrupt_on '0123456789*#' else nil end @execution_elements.each do |element| element.call wait :continue process_playback_completion end when :unimrcp send_ref output_component = current_actor @call.send_agi_action! 'EXEC MRCPSynth', escaped_doc, do |complete_event| pb_logger.debug "MRCPSynth completed with #{complete_event}." output_component.send_complete_event! success_reason end when :swift doc = escaped_doc doc << "|1|1" if [:any, :dtmf].include? @component_node.interrupt_on doc.insert 0, "#{@component_node.voice}^" if @component_node.voice send_ref output_component = current_actor @call.send_agi_action! 'EXEC Swift', doc do |complete_event| pb_logger.debug "Swift completed with #{complete_event}." output_component.send_complete_event! success_reason end end rescue UnrenderableDocError => e with_error 'unrenderable document error', e. rescue OptionError => e with_error 'option error', e. end |
- (Object) play_audio(path)
101 102 103 104 105 106 107 108 |
# File 'lib/punchblock/translator/asterisk/component/output.rb', line 101 def play_audio(path) pb_logger.debug "Playing an audio file (#{path}) via STREAM FILE" op = current_actor @call.send_agi_action! 'STREAM FILE', path, @interrupt_digits do |complete_event| pb_logger.debug "STREAM FILE completed with #{complete_event}. Signalling to continue execution." op.continue! complete_event end end |
- (Object) process_playback_completion
88 89 90 91 92 93 94 95 |
# File 'lib/punchblock/translator/asterisk/component/output.rb', line 88 def process_playback_completion @pending_actions -= 1 pb_logger.debug "Received action completion. Now waiting on #{@pending_actions} actions." if @pending_actions < 1 pb_logger.debug "Sending complete event" send_complete_event success_reason end end |
- (Object) setup
14 15 16 |
# File 'lib/punchblock/translator/asterisk/component/output.rb', line 14 def setup @media_engine = @call.translator.media_engine end |