aboutsummaryrefslogtreecommitdiffstats
path: root/deckit/obsclient.py
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-11-09 19:08:49 +0100
committerDanilo M. <danix@danix.xyz>2026-11-09 19:08:49 +0100
commit4632e6183d38bfd239f066d7e9698f3d118a3f77 (patch)
tree8d458ea7395c6e52186f0bfb38344dbc84f68cbe /deckit/obsclient.py
parentc906d90dcf0abdfb347bd67d6f33a2c45ae32e66 (diff)
downloaddeck-it-4632e6183d38bfd239f066d7e9698f3d118a3f77.tar.gz
deck-it-4632e6183d38bfd239f066d7e9698f3d118a3f77.zip
fix: use OBS's stored password and explain auth failures
Diffstat (limited to 'deckit/obsclient.py')
-rw-r--r--deckit/obsclient.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/deckit/obsclient.py b/deckit/obsclient.py
index 181225a..87eefff 100644
--- a/deckit/obsclient.py
+++ b/deckit/obsclient.py
@@ -30,18 +30,31 @@ class ObsClient:
self._stop = threading.Event()
self._thread = None
+ def _recv_json(self) -> dict:
+ raw = self.ws.recv()
+ if not raw:
+ raise ModuleError("OBS closed the connection")
+ try:
+ return json.loads(raw)
+ except ValueError:
+ raise ModuleError("OBS sent a non-JSON reply")
+
def connect(self):
import websocket # only needed when actually talking to OBS
self.ws = websocket.create_connection(f"ws://{self.host}:{self.port}",
timeout=5, suppress_origin=True)
- hello = json.loads(self.ws.recv())
+ hello = self._recv_json()
auth = {}
if hello.get("d", {}).get("authentication"):
a = hello["d"]["authentication"]
auth["authentication"] = auth_string(self.password, a["salt"], a["challenge"])
self.ws.send(json.dumps({"op": 1, "d": {"rpcVersion": 1, **auth, "eventSubscriptions": 0xFFFFFFFF}}))
- if json.loads(self.ws.recv()).get("op") != 2:
+ try:
+ identified = self._recv_json()
+ except ModuleError:
+ raise ModuleError("OBS rejected the password" if auth else "OBS did not identify")
+ if identified.get("op") != 2:
raise ModuleError("OBS did not identify")
self.connected = True
self._stop.clear()