Skip to content
Snippets Groups Projects

Handle sync_to_me on the server side

Merged Simon Rainer requested to merge synd_to_me_server into main
1 file
+ 18
9
Compare changes
  • Side-by-side
  • Inline
+ 18
9
@@ -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)
Loading