|
|
|
|
@@ -1,9 +1,11 @@
|
|
|
|
|
package net.eksb.obsdc
|
|
|
|
|
|
|
|
|
|
import io.obswebsocket.community.client.OBSRemoteController
|
|
|
|
|
import io.obswebsocket.community.client.message.event.ui.StudioModeStateChangedEvent
|
|
|
|
|
import org.slf4j.LoggerFactory
|
|
|
|
|
import java.util.concurrent.BlockingQueue
|
|
|
|
|
|
|
|
|
|
// protocol docs: https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md
|
|
|
|
|
class ObsCommunity(private val q:BlockingQueue<Op>): AutoCloseable {
|
|
|
|
|
|
|
|
|
|
private val controller = OBSRemoteController.builder()
|
|
|
|
|
@@ -11,7 +13,17 @@ class ObsCommunity(private val q:BlockingQueue<Op>): AutoCloseable {
|
|
|
|
|
.port(4455)
|
|
|
|
|
.password("R3tRkVXhFofJ2wRF") // TODO put this in a file
|
|
|
|
|
.autoConnect(false)
|
|
|
|
|
.lifecycle().onReady(::ready).and()
|
|
|
|
|
.connectionTimeout(3)
|
|
|
|
|
.lifecycle()
|
|
|
|
|
.onReady(::ready)
|
|
|
|
|
.onClose { code -> log.error("closed:${code}")}
|
|
|
|
|
.onControllerError { e -> log.error("controller error", e ) }
|
|
|
|
|
.onCommunicatorError { e -> log.error("comm error", e ) }
|
|
|
|
|
.onDisconnect { log.info("disconnected") }
|
|
|
|
|
.and()
|
|
|
|
|
.registerEventListener(StudioModeStateChangedEvent::class.java) {
|
|
|
|
|
log.info("studio mode state change: ${it}")
|
|
|
|
|
}
|
|
|
|
|
.build()
|
|
|
|
|
|
|
|
|
|
fun run() {
|
|
|
|
|
@@ -23,21 +35,31 @@ class ObsCommunity(private val q:BlockingQueue<Op>): AutoCloseable {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun ready() {
|
|
|
|
|
while (true) {
|
|
|
|
|
val op: Op = q.take() // blocks
|
|
|
|
|
log.info("op: ${op}")
|
|
|
|
|
op(op)
|
|
|
|
|
}
|
|
|
|
|
log.info("ready")
|
|
|
|
|
val op: Op = q.take() // blocks
|
|
|
|
|
log.info("op: ${op}")
|
|
|
|
|
op(op)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun op(op:Op) {
|
|
|
|
|
when(op) {
|
|
|
|
|
Op.SCENE_TEST -> {
|
|
|
|
|
controller.setCurrentProgramScene("test") { response ->
|
|
|
|
|
log.info("set scene response: ${response.isSuccessful}")
|
|
|
|
|
ready()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Op.STUDIO_TRANSITION -> {
|
|
|
|
|
controller.triggerStudioModeTransition { response ->
|
|
|
|
|
// This does not get called?
|
|
|
|
|
log.info("Response successful: ${response.isSuccessful}")
|
|
|
|
|
ready()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Op.TODO -> {
|
|
|
|
|
log.info("OP=TODO")
|
|
|
|
|
ready()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -45,6 +67,3 @@ class ObsCommunity(private val q:BlockingQueue<Op>): AutoCloseable {
|
|
|
|
|
private val log = LoggerFactory.getLogger(ObsCommunity::class.java)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Move window:
|
|
|
|
|
// https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#setsceneitemtransform
|
|
|
|
|
|