config from file
This commit is contained in:
@@ -9,10 +9,18 @@ object Main {
|
|||||||
// Create a queue to send ops coming in from DBUS to OBS.
|
// Create a queue to send ops coming in from DBUS to OBS.
|
||||||
val q:BlockingQueue<Op> = LinkedBlockingQueue()
|
val q:BlockingQueue<Op> = LinkedBlockingQueue()
|
||||||
|
|
||||||
|
val config = CONFIG_FILE.properties()
|
||||||
|
|
||||||
// Listen for DBUS signals and send to q.
|
// Listen for DBUS signals and send to q.
|
||||||
DBus(q)
|
DBus(q)
|
||||||
|
|
||||||
// Send requests to OBS
|
// Send requests to OBS. Forks a non-daemon thread.
|
||||||
Obs(q) // 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
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,13 @@ import org.slf4j.LoggerFactory
|
|||||||
*
|
*
|
||||||
* protocol docs: https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md
|
* 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. */
|
/** How much to pan. */
|
||||||
private val panAmount = 50F
|
private val panAmount = 50F
|
||||||
@@ -36,12 +42,11 @@ class Obs(private val q:BlockingQueue<Op>): AutoCloseable {
|
|||||||
private val ready = AtomicBoolean(false)
|
private val ready = AtomicBoolean(false)
|
||||||
|
|
||||||
private val controller = OBSRemoteController.builder()
|
private val controller = OBSRemoteController.builder()
|
||||||
// TODO: configure these
|
.host(host)
|
||||||
.host("localhost")
|
.port(port)
|
||||||
.port(4455)
|
.password(password)
|
||||||
.password("R3tRkVXhFofJ2wRF")
|
|
||||||
.autoConnect(true)
|
.autoConnect(true)
|
||||||
.connectionTimeout(3)
|
.connectionTimeout(connectionTimeout)
|
||||||
.lifecycle()
|
.lifecycle()
|
||||||
.onReady(::onReady)
|
.onReady(::onReady)
|
||||||
.onClose(::onClose)
|
.onClose(::onClose)
|
||||||
|
|||||||
15
src/main/kotlin/net/eksb/obsdc/Util.kt
Normal file
15
src/main/kotlin/net/eksb/obsdc/Util.kt
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user