Handle setting Channel Controls from WS.

This commit is contained in:
Matthew Stratford 2021-02-14 17:53:28 +00:00
parent a18d4317e4
commit 45d9c32146
4 changed files with 31 additions and 30 deletions

View file

@ -12,9 +12,9 @@ class ServerState(TypedDict):
num_channels: int num_channels: int
class RepeatMode(Enum): class RepeatMode(Enum):
NONE = 0 none = 0
ONE = 1 one = 1
ALL = 2 all = 2
class PlayerState(TypedDict): class PlayerState(TypedDict):
initialised: bool initialised: bool

View file

@ -68,7 +68,7 @@ class Player():
"remaining": 0, "remaining": 0,
"length": 0, "length": 0,
"auto_advance": True, "auto_advance": True,
"repeat": "NONE", # NONE, ONE or ALL "repeat": "none", # none, one or all
"play_on_load": False, "play_on_load": False,
"output": None, "output": None,
"show_plan": [] "show_plan": []
@ -209,32 +209,21 @@ class Player():
self._updateState(pos=pos) self._updateState(pos=pos)
return True return True
def set_auto_advance(self, message: int) -> bool: def set_auto_advance(self, message: bool) -> bool:
if message == 0: self.state.update("auto_advance", message)
self.state.update("auto_advance", False) return True
return True # It did it
elif message == 1:
self.state.update("auto_advance", True)
return True
else:
return False
def set_repeat(self, message: str) -> bool: def set_repeat(self, message: str) -> bool:
if message in ["ALL", "ONE", "NONE"]: if message in ["all", "one", "none"]:
self.state.update("repeat", message) self.state.update("repeat", message)
return True return True
else: else:
return False return False
def set_play_on_load(self, message: int) -> bool: def set_play_on_load(self, message: bool) -> bool:
if message == 0: self.state.update("play_on_load", message)
self.state.update("play_on_load", False) return True
return True # It did it
elif message == 1:
self.state.update("play_on_load", True)
return True
else:
return False
# Show Plan Related Methods # Show Plan Related Methods
def get_plan(self, message: int): def get_plan(self, message: int):
@ -389,7 +378,7 @@ class Player():
global already_stopped global already_stopped
print(already_stopped, self.state.state["remaining"], self.isPlaying) #print(already_stopped, self.state.state["remaining"], self.isPlaying)
if loaded_item == None or already_stopped or (self.state.state["remaining"] > 1): if loaded_item == None or already_stopped or (self.state.state["remaining"] > 1):
return return
@ -465,7 +454,7 @@ class Player():
response += "FAIL:" + msg response += "FAIL:" + msg
else: else:
response += "FAIL" response += "FAIL"
self.logger.log.info(("Preparing to send: {}".format(response))) self.logger.log.debug(("Preparing to send: {}".format(response)))
if self.out_q: if self.out_q:
self.logger.log.info(("Sending: {}".format(response))) self.logger.log.info(("Sending: {}".format(response)))
self.out_q.put(response) self.out_q.put(response)
@ -528,6 +517,7 @@ class Player():
try: try:
try: try:
self.last_msg = in_q.get_nowait() self.last_msg = in_q.get_nowait()
self.logger.log.info("Recieved message: {}".format(self.last_msg))
except Empty: except Empty:
# The incomming message queue was empty, # The incomming message queue was empty,
# skip message processing # skip message processing
@ -542,7 +532,6 @@ class Player():
self._retMsg(self.output(split[1])) self._retMsg(self.output(split[1]))
elif self.isInit: elif self.isInit:
message_types: Dict[str, Callable[..., Any]] = { # TODO Check Types message_types: Dict[str, Callable[..., Any]] = { # TODO Check Types
"STATUS": lambda: self._retMsg(self.status, True), "STATUS": lambda: self._retMsg(self.status, True),
@ -552,9 +541,9 @@ class Player():
"UNPAUSE": lambda: self._retMsg(self.unpause()), "UNPAUSE": lambda: self._retMsg(self.unpause()),
"STOP": lambda: self._retMsg(self.stop()), "STOP": lambda: self._retMsg(self.stop()),
"SEEK": lambda: self._retMsg(self.seek(float(self.last_msg.split(":")[1]))), "SEEK": lambda: self._retMsg(self.seek(float(self.last_msg.split(":")[1]))),
"AUTOADVANCE": lambda: self._retMsg(self.set_auto_advance(int(self.last_msg.split(":")[1]))), "AUTOADVANCE": lambda: self._retMsg(self.set_auto_advance((self.last_msg.split(":")[1] == "True"))),
"REPEAT": lambda: self._retMsg(self.set_repeat(self.last_msg.split(":")[1])), "REPEAT": lambda: self._retMsg(self.set_repeat(self.last_msg.split(":")[1])),
"PLAYONLOAD": lambda: self._retMsg(self.set_play_on_load(int(self.last_msg.split(":")[1]))), "PLAYONLOAD": lambda: self._retMsg(self.set_play_on_load((self.last_msg.split(":")[1] == "True"))),
# Show Plan Items # Show Plan Items
"GET_PLAN": lambda: self._retMsg(self.get_plan(int(self.last_msg.split(":")[1]))), "GET_PLAN": lambda: self._retMsg(self.get_plan(int(self.last_msg.split(":")[1]))),

View file

@ -80,7 +80,7 @@ class PlayerHandler():
try: try:
message = channel_from_q[channel].get_nowait() message = channel_from_q[channel].get_nowait()
websocket_to_q[channel].put(message) websocket_to_q[channel].put(message)
print("Player Handler saw:", message.split(":")[0]) #print("Player Handler saw:", message.split(":")[0])
ui_to_q[channel].put(message) ui_to_q[channel].put(message)
except: except:
pass pass

View file

@ -38,6 +38,18 @@ async def websocket_handler(websocket, path):
channel_to_q[channel].put("SEEK:" + str(data["time"])) channel_to_q[channel].put("SEEK:" + str(data["time"]))
elif data["command"] == "LOAD": elif data["command"] == "LOAD":
channel_to_q[channel].put("LOAD:" + str(data["weight"])) channel_to_q[channel].put("LOAD:" + str(data["weight"]))
elif data["command"] == "AUTOADVANCE":
channel_to_q[channel].put("AUTOADVANCE:" + str(data["enabled"]))
elif data["command"] == "PLAYONLOAD":
channel_to_q[channel].put("PLAYONLOAD:" + str(data["enabled"]))
elif data["command"] == "REPEAT":
channel_to_q[channel].put("REPEAT:" + str(data["mode"]).lower())
# Wasteland
elif data["command"] == "ADD": elif data["command"] == "ADD":
if "managedId" in data["newItem"].keys() and isinstance(data["newItem"]["managedId"], str): if "managedId" in data["newItem"].keys() and isinstance(data["newItem"]["managedId"], str):
if data["newItem"]["managedId"].startswith("managed"): if data["newItem"]["managedId"].startswith("managed"):
@ -77,7 +89,7 @@ async def websocket_handler(websocket, path):
try: try:
message = webstudio_to_q[channel].get_nowait() message = webstudio_to_q[channel].get_nowait()
command = message.split(":")[0] command = message.split(":")[0]
print("Websocket Out:", command) #print("Websocket Out:", command)
if command == "STATUS": if command == "STATUS":
try: try:
message = message.split("OKAY:")[1] message = message.split("OKAY:")[1]