Add playlists
This commit is contained in:
@@ -320,11 +320,29 @@ module.exports = (io) => (socket) => {
|
||||
|
||||
socket.on("get-playlist-options", async () => {
|
||||
try {
|
||||
const playlists = await youtubeService.getPlaylistDetails();
|
||||
socket.emit("playlist-options", playlists);
|
||||
const roomId = roomController.getUserRoom(socket.id);
|
||||
if (!roomId) {
|
||||
throw new Error("User not in a room");
|
||||
}
|
||||
|
||||
const availablePlaylists = roomController.getAvailablePlaylists(roomId);
|
||||
const details = await youtubeService.getPlaylistDetails(availablePlaylists);
|
||||
|
||||
if (Object.keys(details).length === 0) {
|
||||
const newPlaylists = await youtubeService.getRandomPlaylists(3);
|
||||
const newDetails = await youtubeService.getPlaylistDetails(newPlaylists);
|
||||
|
||||
roomController.updateAvailablePlaylists(roomId, newPlaylists);
|
||||
socket.emit("playlist-options", newDetails);
|
||||
} else {
|
||||
socket.emit("playlist-options", details);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error fetching playlist options:", error);
|
||||
socket.emit("error", { message: "Failed to load playlists" });
|
||||
socket.emit("error", {
|
||||
message: "Failed to load playlists",
|
||||
details: error.message
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user