Implemented waiting room feature
This commit is contained in:
parent
2f860ac3c4
commit
a1432529d3
3 changed files with 35 additions and 9 deletions
|
@ -205,7 +205,6 @@ async def handle_connect() -> None:
|
||||||
}
|
}
|
||||||
if state.key:
|
if state.key:
|
||||||
data["registration-key"] = state.key
|
data["registration-key"] = state.key
|
||||||
print(data)
|
|
||||||
await sio.emit("register-client", data)
|
await sio.emit("register-client", data)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -367,15 +367,12 @@ async def handle_get_first(sid: str) -> None:
|
||||||
await sio.emit("play", current, room=sid)
|
await sio.emit("play", current, room=sid)
|
||||||
|
|
||||||
|
|
||||||
async def discard_first(room) -> Entry:
|
async def add_uid_from_waiting_room(uid, room) -> None:
|
||||||
state = clients[room]
|
state = clients[room]
|
||||||
|
|
||||||
old_entry = await state.queue.popleft()
|
|
||||||
|
|
||||||
# append items from the waiting room
|
|
||||||
first_entry_for_uid = None
|
first_entry_for_uid = None
|
||||||
for wr_entry in state.waiting_room:
|
for wr_entry in state.waiting_room:
|
||||||
if wr_entry.uid == old_entry.uid:
|
if wr_entry.uid == uid:
|
||||||
first_entry_for_uid = wr_entry
|
first_entry_for_uid = wr_entry
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -383,6 +380,14 @@ async def discard_first(room) -> Entry:
|
||||||
await append_to_queue(room, first_entry_for_uid)
|
await append_to_queue(room, first_entry_for_uid)
|
||||||
state.waiting_room.remove(first_entry_for_uid)
|
state.waiting_room.remove(first_entry_for_uid)
|
||||||
|
|
||||||
|
|
||||||
|
async def discard_first(room) -> Entry:
|
||||||
|
state = clients[room]
|
||||||
|
|
||||||
|
old_entry = await state.queue.popleft()
|
||||||
|
|
||||||
|
await add_uid_from_waiting_room(old_entry.uid, room)
|
||||||
|
|
||||||
state.recent.append(old_entry)
|
state.recent.append(old_entry)
|
||||||
state.last_seen = datetime.datetime.now()
|
state.last_seen = datetime.datetime.now()
|
||||||
|
|
||||||
|
@ -753,7 +758,7 @@ async def handle_skip(sid: str, data: dict[str, Any]) -> None:
|
||||||
Handle the "skip" message.
|
Handle the "skip" message.
|
||||||
|
|
||||||
If on an admin connection, removes the entry specified by data["uuid"]
|
If on an admin connection, removes the entry specified by data["uuid"]
|
||||||
from the queue.
|
from the queue or the waiting room. Triggers the waiting room.
|
||||||
|
|
||||||
:param sid: The session id of the client requesting.
|
:param sid: The session id of the client requesting.
|
||||||
:type sid: str
|
:type sid: str
|
||||||
|
@ -770,8 +775,26 @@ async def handle_skip(sid: str, data: dict[str, Any]) -> None:
|
||||||
entry = state.queue.find_by_uuid(data["uuid"])
|
entry = state.queue.find_by_uuid(data["uuid"])
|
||||||
if entry is not None:
|
if entry is not None:
|
||||||
logger.info("Skipping %s", entry)
|
logger.info("Skipping %s", entry)
|
||||||
|
|
||||||
|
await add_uid_from_waiting_room(entry.uid, room)
|
||||||
|
|
||||||
await state.queue.remove(entry)
|
await state.queue.remove(entry)
|
||||||
await send_state(state, room)
|
|
||||||
|
first_entry_index = None
|
||||||
|
for idx, wr_entry in enumerate(state.waiting_room):
|
||||||
|
if wr_entry.uuid == data["uuid"]:
|
||||||
|
first_entry_index = idx
|
||||||
|
break
|
||||||
|
|
||||||
|
print(first_entry_index)
|
||||||
|
|
||||||
|
if first_entry_index is not None:
|
||||||
|
logger.info(
|
||||||
|
"Deleting %s from waiting room",
|
||||||
|
state.waiting_room[first_entry_index],
|
||||||
|
)
|
||||||
|
del state.waiting_room[first_entry_index]
|
||||||
|
await send_state(state, room)
|
||||||
|
|
||||||
|
|
||||||
@sio.on("disconnect")
|
@sio.on("disconnect")
|
||||||
|
|
|
@ -137,11 +137,15 @@ class YoutubeSource(Source):
|
||||||
|
|
||||||
def _get_entry(performer: str, url: str) -> Entry:
|
def _get_entry(performer: str, url: str) -> Entry:
|
||||||
yt_song = YouTube(url)
|
yt_song = YouTube(url)
|
||||||
|
try:
|
||||||
|
length = yt_song.length
|
||||||
|
except TypeError:
|
||||||
|
length = 180
|
||||||
return Entry(
|
return Entry(
|
||||||
ident=url,
|
ident=url,
|
||||||
source="youtube",
|
source="youtube",
|
||||||
album="YouTube",
|
album="YouTube",
|
||||||
duration=yt_song.length,
|
duration=length,
|
||||||
title=yt_song.title,
|
title=yt_song.title,
|
||||||
artist=yt_song.author,
|
artist=yt_song.author,
|
||||||
performer=performer,
|
performer=performer,
|
||||||
|
|
Loading…
Add table
Reference in a new issue