- Added Listen Address config variable.
- Improved config handling with aid of new Config object.
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
package com.tutpro.baresip
|
||||
|
||||
import java.io.File
|
||||
|
||||
object Config {
|
||||
|
||||
private val path = BaresipService.filesPath + "/config"
|
||||
private val file = File(path)
|
||||
private val context = BaresipService.context
|
||||
|
||||
private var config = Utils.getFileContents(file)
|
||||
|
||||
fun initialize() {
|
||||
var write = false
|
||||
if (!config.contains("zrtp_hash")) {
|
||||
config = "${config}zrtp_hash yes\n"
|
||||
write = true
|
||||
}
|
||||
if (config.contains(Regex("#module_app[ ]+mwi.so"))) {
|
||||
config = config.replace(Regex("#module_app[ ]+mwi.so"),
|
||||
"module_app mwi.so")
|
||||
write = true
|
||||
}
|
||||
if (!config.contains("opus_application")) {
|
||||
config = "${config}opus_application voip\n"
|
||||
write = true
|
||||
}
|
||||
if (!config.contains("log_level")) {
|
||||
config = "${config}log_level 2\n"
|
||||
Api.log_level_set(2)
|
||||
Log.logLevel = Log.LogLevel.WARN
|
||||
write = true
|
||||
} else {
|
||||
val ll = variable("log_level")[0].toInt()
|
||||
Api.log_level_set(ll)
|
||||
Log.logLevelSet(ll)
|
||||
}
|
||||
if (!config.contains("prefer_ipv6")) {
|
||||
config = "prefer_ipv6 no\n${config}"
|
||||
write = true
|
||||
}
|
||||
if (!config.contains("call_volume")) {
|
||||
config = "${config}call_volume 0\n"
|
||||
write = true
|
||||
} else {
|
||||
BaresipService.callVolume = variable("call_volume")[0].toInt()
|
||||
}
|
||||
if (write) {
|
||||
Log.e("Baresip", "Writing '$config'")
|
||||
Utils.putFileContents(file, config)
|
||||
}
|
||||
}
|
||||
|
||||
fun variable(name: String): ArrayList<String> {
|
||||
val lines = config.split("\n")
|
||||
val result = ArrayList<String>()
|
||||
for (line in lines) {
|
||||
if (line.startsWith(name))
|
||||
result.add((line.substring(name.length).trim()).split("# \t")[0])
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
fun add(variable: String, value: String) {
|
||||
config += "\n$variable $value\n"
|
||||
}
|
||||
|
||||
fun remove(variable: String) {
|
||||
config = Utils.removeLinesStartingWithName(config, variable)
|
||||
Utils.putFileContents(file, config)
|
||||
}
|
||||
|
||||
fun replace(variable: String, value: String) {
|
||||
remove(variable)
|
||||
add(variable, value)
|
||||
}
|
||||
|
||||
fun reset() {
|
||||
Utils.copyAssetToFile(context!!, "config", path)
|
||||
}
|
||||
|
||||
fun save() {
|
||||
Utils.putFileContents(file, config)
|
||||
Log.d("Baresip", "New config '$config'")
|
||||
// Api.reload_config()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user