2015-01-04 10:29:02 +01:00
|
|
|
--get the argv values
|
2016-09-04 21:05:47 +02:00
|
|
|
local script_name = argv[0];
|
|
|
|
|
local file_name = table.concat(argv, " ");
|
2016-08-13 16:59:37 +02:00
|
|
|
freeswitch.consoleLog("notice", "[streamfile] file_name: " .. file_name .. "\n");
|
2015-01-04 10:29:02 +01:00
|
|
|
|
2015-04-24 04:47:10 +02:00
|
|
|
--include config.lua
|
2015-08-11 04:06:33 +02:00
|
|
|
require "resources.functions.config";
|
2015-04-24 04:47:10 +02:00
|
|
|
|
2016-09-04 21:05:47 +02:00
|
|
|
--load libraries
|
|
|
|
|
local Database = require "resources.functions.database";
|
|
|
|
|
local Settings = require "resources.functions.lazy_settings";
|
|
|
|
|
local file = require "resources.functions.file";
|
|
|
|
|
local log = require "resources.functions.log".streamfile;
|
2015-04-24 04:47:10 +02:00
|
|
|
|
|
|
|
|
--get the variables
|
2016-09-04 21:05:47 +02:00
|
|
|
local domain_name = session:getVariable("domain_name");
|
|
|
|
|
local domain_uuid = session:getVariable("domain_uuid");
|
2015-04-24 04:47:10 +02:00
|
|
|
|
|
|
|
|
--get the sounds dir, language, dialect and voice
|
2016-09-04 21:05:47 +02:00
|
|
|
local sounds_dir = session:getVariable("sounds_dir");
|
|
|
|
|
local default_language = session:getVariable("default_language") or 'en';
|
|
|
|
|
local default_dialect = session:getVariable("default_dialect") or 'us';
|
|
|
|
|
local default_voice = session:getVariable("default_voice") or 'callie';
|
|
|
|
|
|
|
|
|
|
--set the recordings directory
|
|
|
|
|
local recordings_dir = recordings_dir .. "/" .. domain_name;
|
|
|
|
|
|
|
|
|
|
--parse file name
|
|
|
|
|
local file_name_only = file_name:match("([^/]+)$");
|
2015-04-24 04:47:10 +02:00
|
|
|
|
|
|
|
|
--settings
|
2016-09-04 21:05:47 +02:00
|
|
|
local dbh = Database.new('system');
|
|
|
|
|
local settings = Settings.new(dbh, domain_name, domain_uuid);
|
|
|
|
|
local storage_type = settings:get('recordings', 'storage_type', 'text') or '';
|
2015-08-07 10:11:27 +02:00
|
|
|
|
|
|
|
|
if (not temp_dir) or (#temp_dir == 0) then
|
2016-09-04 21:05:47 +02:00
|
|
|
temp_dir = settings:get('server', 'temp', 'dir') or '/tmp';
|
2015-04-24 04:47:10 +02:00
|
|
|
end
|
|
|
|
|
|
2016-09-04 21:05:47 +02:00
|
|
|
dbh:release()
|
2015-04-24 04:47:10 +02:00
|
|
|
|
2015-01-04 10:29:02 +01:00
|
|
|
--define the on_dtmf call back function
|
2016-09-04 21:05:47 +02:00
|
|
|
-- luacheck: globals on_dtmf, ignore s arg
|
2015-01-04 10:29:02 +01:00
|
|
|
function on_dtmf(s, type, obj, arg)
|
|
|
|
|
if (type == "dtmf") then
|
2015-04-28 19:24:32 +02:00
|
|
|
session:setVariable("dtmf_digits", obj['digit']);
|
2016-09-04 21:05:47 +02:00
|
|
|
log.info("dtmf digit: " .. obj['digit'] .. ", duration: " .. obj['duration']);
|
2015-01-04 10:29:02 +01:00
|
|
|
if (obj['digit'] == "*") then
|
2015-01-23 19:10:48 +01:00
|
|
|
return("false"); --return to previous
|
2015-01-04 10:29:02 +01:00
|
|
|
elseif (obj['digit'] == "0") then
|
|
|
|
|
return("restart"); --start over
|
|
|
|
|
elseif (obj['digit'] == "1") then
|
|
|
|
|
return("volume:-1"); --volume down
|
|
|
|
|
elseif (obj['digit'] == "3") then
|
|
|
|
|
return("volume:+1"); -- volume up
|
|
|
|
|
elseif (obj['digit'] == "4") then
|
|
|
|
|
return("seek:-5000"); -- back
|
|
|
|
|
elseif (obj['digit'] == "5") then
|
|
|
|
|
return("pause"); -- pause toggle
|
|
|
|
|
elseif (obj['digit'] == "6") then
|
|
|
|
|
return("seek:+5000"); -- forward
|
|
|
|
|
elseif (obj['digit'] == "7") then
|
|
|
|
|
return("speed:-1"); -- increase playback
|
|
|
|
|
elseif (obj['digit'] == "9") then
|
|
|
|
|
return("speed:+1"); -- decrease playback
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-24 04:47:10 +02:00
|
|
|
--if base64, get from db, create temp file
|
|
|
|
|
if (storage_type == "base64") then
|
2016-09-04 21:05:47 +02:00
|
|
|
local full_path = recordings_dir .. "/" .. file_name_only
|
|
|
|
|
if not file.exists(full_path) then
|
|
|
|
|
local sql = "SELECT recording_base64 FROM v_recordings "
|
|
|
|
|
.. "WHERE domain_uuid = '" .. domain_uuid .."'"
|
|
|
|
|
.. "AND recording_filename = '".. file_name_only.. "' ";
|
2015-04-24 04:47:10 +02:00
|
|
|
if (debug["sql"]) then
|
2016-09-04 21:05:47 +02:00
|
|
|
log.notice("SQL: " .. sql);
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local dbh = Database.new('system', 'base64/read');
|
|
|
|
|
local recording_base64 = dbh:first_value(sql);
|
|
|
|
|
dbh:release();
|
|
|
|
|
|
|
|
|
|
if recording_base64 and #recording_base64 > 32 then
|
|
|
|
|
file_name = full_path;
|
|
|
|
|
file.write_base64(file_name, recording_base64);
|
2015-04-24 04:47:10 +02:00
|
|
|
end
|
2016-03-11 14:21:52 +01:00
|
|
|
else
|
2016-09-04 21:05:47 +02:00
|
|
|
file_name = full_path;
|
2015-04-24 04:47:10 +02:00
|
|
|
end
|
2016-03-11 14:21:52 +01:00
|
|
|
end
|
2015-04-24 04:47:10 +02:00
|
|
|
|
|
|
|
|
--adjust file path
|
2016-09-04 21:05:47 +02:00
|
|
|
if not file.exists(file_name) then
|
|
|
|
|
file_name = file.exists(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..file_name_only)
|
|
|
|
|
or file.exists(recordings_dir.."/"..file_name_only)
|
|
|
|
|
or file_name
|
2015-04-24 04:47:10 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--stream file if exists
|
2015-01-04 10:29:02 +01:00
|
|
|
if (session:ready()) then
|
2015-04-24 04:47:10 +02:00
|
|
|
session:answer();
|
2016-09-04 21:05:47 +02:00
|
|
|
local slept = session:getVariable("slept");
|
2016-03-11 14:21:52 +01:00
|
|
|
if (slept == nil or slept == "false") then
|
2016-09-04 21:05:47 +02:00
|
|
|
log.notice("sleeping (1s)");
|
2015-04-28 19:24:32 +02:00
|
|
|
session:sleep(1000);
|
2016-03-11 14:21:52 +01:00
|
|
|
if (slept == "false") then
|
2015-04-28 19:24:32 +02:00
|
|
|
session:setVariable("slept", "true");
|
|
|
|
|
end
|
|
|
|
|
end
|
2015-01-04 10:29:02 +01:00
|
|
|
session:setInputCallback("on_dtmf", "");
|
|
|
|
|
session:streamFile(file_name);
|
2016-02-03 13:20:50 +01:00
|
|
|
session:unsetInputCallback();
|
2015-01-04 10:29:02 +01:00
|
|
|
end
|
2015-04-24 04:47:10 +02:00
|
|
|
|
|
|
|
|
--if base64, remove temp file (increases responsiveness when files remain local)
|
2016-09-04 21:05:47 +02:00
|
|
|
-- if (storage_type == "base64") then
|
|
|
|
|
-- if (file.exists(file_name)) then
|
|
|
|
|
-- file.remove(file_name);
|
|
|
|
|
-- end
|
|
|
|
|
-- end
|