diff --git a/examples/events/__main__.py b/examples/events/__main__.py index 4f6c0c5..a95770c 100644 --- a/examples/events/__main__.py +++ b/examples/events/__main__.py @@ -5,17 +5,30 @@ class Observer: def __init__(self, cl): self._cl = cl self._cl.callback.register( - [self.on_current_program_scene_changed, self.on_exit_started] + [ + self.on_current_program_scene_changed, + self.on_scene_created, + self.on_input_mute_state_changed, + self.on_exit_started, + ] ) print(f"Registered events: {self._cl.callback.get()}") + def on_current_program_scene_changed(self, data): + print(f"Switched to scene {data['sceneName']}") + + def on_scene_created(self, event, data): + """A new scene has been created.""" + print(f"{event}: {data}") + + def on_input_mute_state_changed(self, event, data): + """An input's mute state has changed.""" + print(f"{event}: {data}") + def on_exit_started(self): print(f"OBS closing!") self._cl.unsubscribe() - def on_current_program_scene_changed(self, data): - print(f"Switched to scene {data['sceneName']}") - if __name__ == "__main__": cl = obs.EventsClient() diff --git a/obsstudio_sdk/baseclient.py b/obsstudio_sdk/baseclient.py index 809d207..da19ba3 100644 --- a/obsstudio_sdk/baseclient.py +++ b/obsstudio_sdk/baseclient.py @@ -1,12 +1,19 @@ import base64 import hashlib import json +from enum import IntEnum from pathlib import Path 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): def __init__(self, **kwargs): @@ -49,7 +56,28 @@ class ObsClient(object): ).digest() ).decode() - payload = {"op": 1, "d": {"rpcVersion": 1, "authentication": auth}} + 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), + }, + } self.ws.send(json.dumps(payload)) return self.ws.recv()