tSIP: updating settings from Lua
In tSIP 0.1.65 UpdateSettings(jsonText) Lua function was added. It was preceded by rewriting function reading configuration so preceding values would be used consistently as default values. This way argument passed to UpdateSettings function does not need to be complete configuration - partial configuration is accepted and would be preferred way of updating specific settings.
My primary reason for adding method of updating settings from script is particular problem with my setup: EX-03 USB phone is randomly enumerated by Windows 10 either as "USB Phone" or as "2 - USB Phone" at startup. If name under which device is enumerated is not matching configured device name then default device is used and it's pretty startling on the first call after powering on PC.
Following script (used as "on startup" script) searches through input and output devices lists for devices with names containing specified string and selects them in configuration:
RefreshAudioDevicesList()
local name, valid
local id
local moduleName = "winwave"
local needle = "USB Phone" -- note: JSON-escaping is skipped below
local inputDev = nil
local outputDev = nil
print(string.format("Devices for %s module:\n", moduleName))
print(" Input devices:\n")
id = 0
repeat
name, valid = GetAudioDevice(moduleName, "in", id)
if valid == 1 then
print(string.format(" #%d: %s\n", id, name))
if string.find(name, needle, 1, true) then
inputDev = name
break
end
end
id = id + 1
until valid == 0
print(" Output devices:\n")
id = 0
repeat
name, valid = GetAudioDevice(moduleName, "out", id)
if valid == 1 then
print(string.format(" #%d: %s\n", id, name))
if string.find(name, needle, 1, true) then
outputDev = name
break
end
end
id = id + 1
until valid == 0
if inputDev ~= nil or outputDev ~= nil then
local config = "{ \"uaConf\" : {"
if inputDev ~= nil then
local str = string.format([[
"audioCfgAlert" : {
"dev" : "%s",
"mod" : "%s"
},
"audioCfgPlay" : {
"dev" : "%s",
"mod" : "%s"
},
"audioCfgPlayIntercom" : {
"dev" : "%s",
"mod" : "%s"
},
"audioCfgRing" : {
"dev" : "%s",
"mod" : "%s"
}
]],
outputDev, moduleName,
outputDev, moduleName,
outputDev, moduleName,
outputDev, moduleName)
config = config .. str
end
if inputDev ~= nil and outputDev ~= nil then
config = config .. ","
end
if outputDev ~= nil then
local str = string.format([[
"audioCfgSrc" : {
"dev" : "%s",
"mod" : "%s"
}
]], inputDev, moduleName)
config = config .. str
end
config = config .. "}}"
print(string.format("Updating config:\n%s\n", config))
local res = UpdateSettings(config)
if res ~= 0 then
print("Error updating configuration\n")
end
end
Combination of external tool like curl, ShellExecute() function, io Lua module and UpdateSettings() function can be also used for provisioning.
Back to howto list.