Compare commits
2 commits
285deadf09
...
1d1e94da85
Author | SHA1 | Date | |
---|---|---|---|
1d1e94da85 | |||
648d3afc21 |
4 changed files with 43 additions and 2 deletions
|
@ -160,7 +160,7 @@ class Client:
|
||||||
|
|
||||||
self.connection_state = ConnectionState()
|
self.connection_state = ConnectionState()
|
||||||
self.set_log_level(config["config"]["log_level"])
|
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.loop: Optional[asyncio.AbstractEventLoop] = None
|
||||||
self.skipped: list[UUID] = []
|
self.skipped: list[UUID] = []
|
||||||
self.sources = configure_sources(config["sources"])
|
self.sources = configure_sources(config["sources"])
|
||||||
|
|
|
@ -120,6 +120,20 @@ class Queue:
|
||||||
return item
|
return item
|
||||||
return None
|
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]:
|
def find_by_uuid(self, uuid: UUID | str) -> Optional[Entry]:
|
||||||
"""
|
"""
|
||||||
Find an entry by its uuid and return it.
|
Find an entry by its uuid and return it.
|
||||||
|
|
|
@ -682,6 +682,33 @@ class Server:
|
||||||
|
|
||||||
await self.sio.emit("play", current, room=sid)
|
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
|
@admin
|
||||||
@with_state
|
@with_state
|
||||||
async def handle_waiting_room_to_queue(
|
async def handle_waiting_room_to_queue(
|
||||||
|
|
|
@ -36,7 +36,7 @@ class AsyncServer:
|
||||||
def instrument(self, auth: dict[str, str]) -> None: ...
|
def instrument(self, auth: dict[str, str]) -> None: ...
|
||||||
|
|
||||||
class AsyncClient:
|
class AsyncClient:
|
||||||
def __init__(self, json: Any = None): ...
|
def __init__(self, json: Any = None, reconnection_attempts: int = 0): ...
|
||||||
def on(
|
def on(
|
||||||
self, event: str, handler: Optional[Callable[..., Any]] = None
|
self, event: str, handler: Optional[Callable[..., Any]] = None
|
||||||
) -> Callable[[ClientHandler], ClientHandler]: ...
|
) -> Callable[[ClientHandler], ClientHandler]: ...
|
||||||
|
|
Loading…
Add table
Reference in a new issue