diff --git a/server/server.py b/server/server.py
index 69c4c6e969ffcdf8996519b87a262e68eabdf9e8..9893ec7afc130c22441d1ef971ffe5d48997dcbf 100755
--- a/server/server.py
+++ b/server/server.py
@@ -106,10 +106,8 @@ class ClientGroup:
current_clients = await self._filter_valid_clients()
return [
- c.get_playback_time()
- for c in current_clients
- if c.get_playback_time() >= 1
- ]
+ c.get_playback_time() for c in current_clients if c.get_playback_time() >= 1
+ ]
async def play(self):
await self._send_command(PLAY_REQUEST)
@@ -118,7 +116,6 @@ class ClientGroup:
await self._send_command(PAUSE_REQUEST)
async def sync(self):
-
await self._send_command(GET_PLAYBACK_TIME_REQUEST)
await asyncio.sleep(1)
@@ -130,13 +127,27 @@ class ClientGroup:
set_pb_time_filled_req["data"] = min_time
await self._send_command(set_pb_time_filled_req)
- async def sendCommandToClients(self, command):
+ async def sync_to_me(self, playback_time):
+ set_pb_time_filled_req = SET_PLAYBACK_TIME_REQUEST.copy()
+ set_pb_time_filled_req["data"] = playback_time
+ await self._send_command(set_pb_time_filled_req)
+
+ async def sendCommandToClients(self, parsed):
+ command = parsed["command"]
if command == "play":
await self.play()
elif command == "pause":
await self.pause()
elif command == "sync":
await self.sync()
+ elif command == "sync_to_me":
+ if "playback_time" not in parsed:
+ print(
+ f"Ignoring sync_to_me command, because playback_time is missing: <{parsed}>"
+ )
+ return
+ playback_time = parsed["playback_time"]
+ await self.sync_to_me(playback_time)
elif command == "show":
await self.show_connected_clients()
else:
@@ -164,8 +175,6 @@ async def console_input():
while True:
com = await ainput("> ")
print("cool, but currently we dont listen on this...")
- #await sendCommandToClients(com)
-
async def handle(ws: websockets.WebSocketServerProtocol, path: str) -> None:
@@ -199,7 +208,7 @@ async def handle(ws: websockets.WebSocketServerProtocol, path: str) -> None:
f"Ignoring message that does not contain a command <{message}>"
)
else:
- asyncio.create_task(clients.sendCommandToClients(parsed["command"]))
+ asyncio.create_task(clients.sendCommandToClients(parsed))
finally:
await clients.remove_client(client)