config from file

This commit is contained in:
2023-10-21 14:34:10 -04:00
parent f4ac82de05
commit 180e4d2bf4
3 changed files with 36 additions and 8 deletions

View File

@@ -9,10 +9,18 @@ object Main {
// Create a queue to send ops coming in from DBUS to OBS.
val q:BlockingQueue<Op> = LinkedBlockingQueue()
val config = CONFIG_FILE.properties()
// Listen for DBUS signals and send to q.
DBus(q)
// Send requests to OBS
Obs(q) // forks a non-daemon thread.
// Send requests to OBS. Forks a non-daemon thread.
Obs(
q,
host = config.getProperty("host") ?: "localhost",
port = config.getProperty("port")?.toInt() ?: 4455,
password = config.getProperty("password") ?: error("config missing \"password\""),
connectionTimeout = config.getProperty("connectionTimeout")?.toInt() ?: 5
)
}
}

View File

@@ -19,7 +19,13 @@ import org.slf4j.LoggerFactory
*
* protocol docs: https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md
*/
class Obs(private val q:BlockingQueue<Op>): AutoCloseable {
class Obs(
private val q:BlockingQueue<Op>,
host:String = "localhost",
port:Int = 4455,
password:String,
connectionTimeout:Int = 5 // seconds
): AutoCloseable {
/** How much to pan. */
private val panAmount = 50F
@@ -36,12 +42,11 @@ class Obs(private val q:BlockingQueue<Op>): AutoCloseable {
private val ready = AtomicBoolean(false)
private val controller = OBSRemoteController.builder()
// TODO: configure these
.host("localhost")
.port(4455)
.password("R3tRkVXhFofJ2wRF")
.host(host)
.port(port)
.password(password)
.autoConnect(true)
.connectionTimeout(3)
.connectionTimeout(connectionTimeout)
.lifecycle()
.onReady(::onReady)
.onClose(::onClose)

View File

@@ -0,0 +1,15 @@
package net.eksb.obsdc
import java.io.File
import java.util.Properties
val HOME:File = System.getProperty("user.home")?.let(::File) ?: error("No user.home")
val CONFIG_HOME:File = System.getenv("XDG_CONFIG_HOME")?.let(::File) ?: File(HOME, ".config")
val CONFIG_FILE:File = File(CONFIG_HOME,"net.eksb.obsdc/config.properties")
fun File.properties(): Properties = Properties()
.also { properties ->
if (isFile) {
inputStream().use(properties::load)
}
}