lib/punchblock/translator/freeswitch/component/record.rb in punchblock-1.9.4 vs lib/punchblock/translator/freeswitch/component/record.rb in punchblock-2.0.0.beta1
- old
+ new
@@ -11,15 +11,15 @@
@complete_reason = nil
end
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, 'An initial-timeout value is unsupported.' if @component_node.initial_timeout && @component_node.initial_timeout != -1
- raise OptionError, 'A final-timeout value is unsupported.' if @component_node.final_timeout && @component_node.final_timeout != -1
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
@@ -27,20 +27,22 @@
component.finished
end
record_args = ['start', filename]
record_args << max_duration/1000 unless max_duration == -1
- case @component_node.direction
- when :send
- call.uuid_foo :setvar, "RECORD_WRITE_ONLY true"
- when :recv
- call.uuid_foo :setvar, "RECORD_READ_ONLY true"
- else
- call.uuid_foo :setvar, "RECORD_STEREO true"
+
+ direction = case @component_node.direction
+ when :send then :RECORD_WRITE_ONLY
+ when :recv then :RECORD_READ_ONLY
+ else :RECORD_STEREO
end
- call.uuid_foo :record, record_args.join(' ')
+ 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
@@ -54,15 +56,19 @@
super
end
end
def finished
- send_complete_event(@complete_reason || success_reason)
+ send_complete_event(@complete_reason || max_duration_reason)
end
private
+ def setvar(key, value)
+ call.uuid_foo :setvar, "#{key} #{value}"
+ end
+
def filename
File.join RECORDING_BASE_PATH, [id, @format].join('.')
end
def recording
@@ -71,11 +77,11 @@
def stop_reason
Punchblock::Event::Complete::Stop.new
end
- def success_reason
- Punchblock::Component::Record::Complete::Success.new
+ def max_duration_reason
+ Punchblock::Component::Record::Complete::MaxDuration.new
end
def send_complete_event(reason)
super reason, recording
end