EventsClient renamed to EventClient

remove getter, setter for send.

add persistend data unit test

add hotkey example

default event sub now 0. explicitly define subs in event class.
now subs can be set as kwarg
This commit is contained in:
onyx-and-iris
2022-07-27 19:39:33 +01:00
parent c71d7e4ea9
commit 2a3a86c277
7 changed files with 209 additions and 276 deletions

View File

@@ -1,4 +1,4 @@
from .events import EventsClient
from .events import EventClient
from .reqs import ReqClient
__ALL__ = ["ReqClient", "EventsClient"]

View File

@@ -9,18 +9,13 @@ from random import randint
import tomllib
import websocket
Subs = IntEnum(
"Subs",
"general config scenes inputs transitions filters outputs sceneitems mediainputs vendors ui",
start=0,
)
class ObsClient(object):
DELAY = 0.001
def __init__(self, **kwargs):
defaultkwargs = {key: None for key in ["host", "port", "password"]}
defaultkwargs["subs"] = 0
kwargs = defaultkwargs | kwargs
for attr, val in kwargs.items():
setattr(self, attr, val)
@@ -59,26 +54,12 @@ class ObsClient(object):
).digest()
).decode()
all_non_high_volume = (
(1 << Subs.general)
| (1 << Subs.config)
| (1 << Subs.scenes)
| (1 << Subs.inputs)
| (1 << Subs.transitions)
| (1 << Subs.filters)
| (1 << Subs.outputs)
| (1 << Subs.sceneitems)
| (1 << Subs.mediainputs)
| (1 << Subs.vendors)
| (1 << Subs.ui)
)
payload = {
"op": 1,
"d": {
"rpcVersion": 1,
"authentication": auth,
"eventSubscriptions": all_non_high_volume,
"eventSubscriptions": self.subs,
},
}
@@ -102,7 +83,4 @@ class ObsClient(object):
}
self.ws.send(json.dumps(payload))
response = json.loads(self.ws.recv())
while "requestId" not in response["d"]:
response = json.loads(self.ws.recv())
time.sleep(self.DELAY)
return response["d"]

View File

@@ -1,5 +1,6 @@
import json
import time
from enum import IntEnum
from threading import Thread
from .baseclient import ObsClient
@@ -11,11 +12,30 @@ defined in official github repo
https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#events
"""
Subs = IntEnum(
"Subs",
"general config scenes inputs transitions filters outputs sceneitems mediainputs vendors ui",
start=0,
)
class EventsClient(object):
class EventClient(object):
DELAY = 0.001
def __init__(self, **kwargs):
kwargs["subs"] = (
(1 << Subs.general)
| (1 << Subs.config)
| (1 << Subs.scenes)
| (1 << Subs.inputs)
| (1 << Subs.transitions)
| (1 << Subs.filters)
| (1 << Subs.outputs)
| (1 << Subs.sceneitems)
| (1 << Subs.mediainputs)
| (1 << Subs.vendors)
| (1 << Subs.ui)
)
self.base_client = ObsClient(**kwargs)
self.base_client.authenticate()
self.callback = Callback()

File diff suppressed because it is too large Load Diff