Compare commits

...

2 commits

Author SHA1 Message Date
1d1e94da85 Add "queue to waitingroom" feature
All checks were successful
Check / mypy (push) Successful in 52s
Check / ruff (push) Successful in 5s
2025-05-24 09:42:55 +02:00
648d3afc21 limit the autoconnect retries if the server is not available. 2025-05-23 21:15:14 +02:00
4 changed files with 43 additions and 2 deletions

View file

@ -160,7 +160,7 @@ class Client:
self.connection_state = ConnectionState()
self.set_log_level(config["config"]["log_level"])
self.sio = socketio.AsyncClient(json=jsonencoder)
self.sio = socketio.AsyncClient(json=jsonencoder, reconnection_attempts=-1)
self.loop: Optional[asyncio.AbstractEventLoop] = None
self.skipped: list[UUID] = []
self.sources = configure_sources(config["sources"])

View file

@ -120,6 +120,20 @@ class Queue:
return item
return None
def find_all_by_name(self, name: str) -> Iterable[Entry]:
"""
Find all entries by their performer and return them as an iterable.
:param name: The name of the performer to search for.
:type name: str
:returns: The entries with the performer.
:rtype: Iterable[Entry]
"""
for item in self._queue:
if item.shares_performer(name):
yield item
def find_by_uuid(self, uuid: UUID | str) -> Optional[Entry]:
"""
Find an entry by its uuid and return it.

View file

@ -682,6 +682,33 @@ class Server:
await self.sio.emit("play", current, room=sid)
@admin
@with_state
async def handle_queue_to_waiting_room(
self, state: State, sid: str, data: dict[str, Any]
) -> None:
"""
Handle the "queue-to-waiting" message.
If on an admin-connection, removes a song from the queue and appends it to
the waiting room. If the performer has only one entry in the queue, it is
put back into the queue immediately.
:param sid: The session id of the requesting client
:type sid: str
:rtype: None
"""
entry = state.queue.find_by_uuid(data["uuid"])
if entry is not None:
performer_entries = list(state.queue.find_all_by_name(entry.performer))
print(performer_entries)
if len(performer_entries) == 1:
return
await state.queue.remove(entry)
state.waiting_room.append(entry)
await self.broadcast_state(state, sid=sid)
@admin
@with_state
async def handle_waiting_room_to_queue(

View file

@ -36,7 +36,7 @@ class AsyncServer:
def instrument(self, auth: dict[str, str]) -> None: ...
class AsyncClient:
def __init__(self, json: Any = None): ...
def __init__(self, json: Any = None, reconnection_attempts: int = 0): ...
def on(
self, event: str, handler: Optional[Callable[..., Any]] = None
) -> Callable[[ClientHandler], ClientHandler]: ...