Skip to content
Snippets Groups Projects
Commit 8c0191e9 authored by Simon Rainer's avatar Simon Rainer
Browse files

Merge branch 'synd_to_me_server' into 'main'

Handle sync_to_me on the server side

See merge request !2
parents f4d1a277 9e7346b8
No related branches found
No related tags found
1 merge request!2Handle sync_to_me on the server side
......@@ -106,9 +106,7 @@ 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):
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment