Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions obswebsocket/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ def __init__(self, host='localhost', port=4444, password='', legacy=None, timeou
self.answers = {}
self.server_version = None

def connect(self):
def connect(
self,
input_volume_meters=False,
input_active_state_changed=False,
input_show_state_changed=False,
scene_item_transform_changed=False
):
"""
Connect to the websocket server

Expand All @@ -86,7 +92,12 @@ def connect(self):
if self.legacy:
self._auth_legacy()
else:
self._auth()
self._auth(
input_volume_meters=input_volume_meters,
input_active_state_changed=input_active_state_changed,
input_show_state_changed=input_show_state_changed,
scene_item_transform_changed=scene_item_transform_changed
)

if self.thread_recv is not None:
self.thread_recv.running = False
Expand Down Expand Up @@ -136,7 +147,13 @@ def disconnect(self):
self.thread_recv.join()
self.thread_recv = None

def _auth(self):
def _auth(
self,
input_volume_meters=False,
input_active_state_changed=False,
input_show_state_changed=False,
scene_item_transform_changed=False
):
message = self.ws.recv()
LOG.debug("Got Hello message: {}".format(message))
result = json.loads(message)
Expand All @@ -150,20 +167,30 @@ def _auth(self):
else:
auth = ''

eventSubscriptions = 1023 # EventSubscription::All
if input_volume_meters:
eventSubscriptions = eventSubscriptions << 16
if input_active_state_changed:
eventSubscriptions = eventSubscriptions << 17
if input_show_state_changed:
eventSubscriptions = eventSubscriptions << 18
if scene_item_transform_changed:
eventSubscriptions = eventSubscriptions << 19

payload = {
"op": 1,
"d": {
"rpcVersion": 1,
"authentication": auth,
"eventSubscriptions": 1023 # EventSubscription::All
"eventSubscriptions": eventSubscriptions
}
}
LOG.debug("Sending Identify message: {}".format(json.dumps(payload)))
self.ws.send(json.dumps(payload))

message = self.ws.recv()
if not message:
raise exceptions.ConnectionFailure("Empty response to Identify, password may be inconnect.")
raise exceptions.ConnectionFailure("Empty response to Identify, password may be incorrect.")
LOG.debug("Got Identified message: {}".format(message))
result = json.loads(message)
if result.get('op') != 2:
Expand Down