mirror of
https://github.com/onyx-and-iris/obsws-python.git
synced 2024-11-22 12:50:53 +00:00
add subs intenum to baseclient
expand events example
This commit is contained in:
parent
82ddbacd7d
commit
c8f2b6419d
@ -5,17 +5,30 @@ class Observer:
|
|||||||
def __init__(self, cl):
|
def __init__(self, cl):
|
||||||
self._cl = cl
|
self._cl = cl
|
||||||
self._cl.callback.register(
|
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()}")
|
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):
|
def on_exit_started(self):
|
||||||
print(f"OBS closing!")
|
print(f"OBS closing!")
|
||||||
self._cl.unsubscribe()
|
self._cl.unsubscribe()
|
||||||
|
|
||||||
def on_current_program_scene_changed(self, data):
|
|
||||||
print(f"Switched to scene {data['sceneName']}")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
cl = obs.EventsClient()
|
cl = obs.EventsClient()
|
||||||
|
@ -1,12 +1,19 @@
|
|||||||
import base64
|
import base64
|
||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json
|
||||||
|
from enum import IntEnum
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from random import randint
|
from random import randint
|
||||||
|
|
||||||
import tomllib
|
import tomllib
|
||||||
import websocket
|
import websocket
|
||||||
|
|
||||||
|
Subs = IntEnum(
|
||||||
|
"Subs",
|
||||||
|
"general config scenes inputs transitions filters outputs sceneitems mediainputs vendors ui",
|
||||||
|
start=0,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ObsClient(object):
|
class ObsClient(object):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
@ -49,7 +56,28 @@ class ObsClient(object):
|
|||||||
).digest()
|
).digest()
|
||||||
).decode()
|
).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))
|
self.ws.send(json.dumps(payload))
|
||||||
return self.ws.recv()
|
return self.ws.recv()
|
||||||
|
Loading…
Reference in New Issue
Block a user