From 4632e6183d38bfd239f066d7e9698f3d118a3f77 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Mon, 9 Nov 2026 19:08:49 +0100 Subject: fix: use OBS's stored password and explain auth failures --- deckit/obsclient.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'deckit/obsclient.py') 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() -- cgit v1.2.3