diff --git a/src/main/kotlin/net/eksb/obsdc/Main.kt b/src/main/kotlin/net/eksb/obsdc/Main.kt index 8b9961d..2e1bb71 100644 --- a/src/main/kotlin/net/eksb/obsdc/Main.kt +++ b/src/main/kotlin/net/eksb/obsdc/Main.kt @@ -9,10 +9,18 @@ object Main { // Create a queue to send ops coming in from DBUS to OBS. val q:BlockingQueue = 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 + ) } } \ No newline at end of file diff --git a/src/main/kotlin/net/eksb/obsdc/Obs.kt b/src/main/kotlin/net/eksb/obsdc/Obs.kt index fc3a4d2..761df42 100644 --- a/src/main/kotlin/net/eksb/obsdc/Obs.kt +++ b/src/main/kotlin/net/eksb/obsdc/Obs.kt @@ -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): AutoCloseable { +class Obs( + private val q:BlockingQueue, + 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): 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) diff --git a/src/main/kotlin/net/eksb/obsdc/Util.kt b/src/main/kotlin/net/eksb/obsdc/Util.kt new file mode 100644 index 0000000..1c08f24 --- /dev/null +++ b/src/main/kotlin/net/eksb/obsdc/Util.kt @@ -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) + } + } \ No newline at end of file