2026-05-16 11:14:39 +02:00
|
|
|
import { authedAPIRequest } from "../utils/auth";
|
2026-05-16 12:18:35 +02:00
|
|
|
import { socket } from "../pages/index";
|
2026-05-15 11:08:23 +02:00
|
|
|
// FIXME: This file should handle the rooms API
|
|
|
|
|
// Functions may include:
|
|
|
|
|
// - fetchRoomConfig (get the configuration of a room)
|
|
|
|
|
// - setCurrentRoomConfig (set the current room configuration and update the DOM accordingly)
|
|
|
|
|
// - getCurrentRoomConfig (get the current room configuration)
|
|
|
|
|
// - joinRoom (join a room by its slug)
|
|
|
|
|
// - listRooms (list all the rooms available)
|
|
|
|
|
// - createRoom (create a room)
|
|
|
|
|
// - updateRoom (update a room's configuration)
|
|
|
|
|
// - deleteRoom (delete a room)
|
2026-05-15 22:59:15 +02:00
|
|
|
|
2026-05-16 12:18:35 +02:00
|
|
|
const roomsConfig = null;
|
2026-05-15 22:59:15 +02:00
|
|
|
|
2026-05-16 12:18:35 +02:00
|
|
|
function setCurrentRoomConfig(room, cfg) {
|
|
|
|
|
roomsConfig[room] = cfg;
|
|
|
|
|
}
|
|
|
|
|
function getCurrentRoomConfig(room) {
|
|
|
|
|
return roomsConfig[room];
|
|
|
|
|
}
|
|
|
|
|
async function joinRoom(room) {
|
|
|
|
|
socket.on("connection", (sockett) => {
|
|
|
|
|
sockett.join(room);
|
|
|
|
|
|
|
|
|
|
// broadcast to all connected clients in the room
|
|
|
|
|
// socket.to('some room').emit('hello', 'world');
|
|
|
|
|
|
|
|
|
|
// broadcast to all connected clients except those in the room
|
|
|
|
|
// socket.except('some room').emit('hello', 'world');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// async function leaveRoom(room) {
|
|
|
|
|
// io.on('connection', (socket) => {
|
|
|
|
|
// socket.leave(room);
|
|
|
|
|
// })
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// async function listRooms() {
|
2026-05-15 22:59:15 +02:00
|
|
|
|
2026-05-16 12:18:35 +02:00
|
|
|
// }
|
|
|
|
|
// async function createRoom() {
|
2026-05-15 22:59:15 +02:00
|
|
|
|
2026-05-16 12:18:35 +02:00
|
|
|
// }
|
|
|
|
|
// async function updateRoom() {
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
// async function deleteRoom() {
|
|
|
|
|
|
|
|
|
|
// }
|
2026-05-16 11:14:39 +02:00
|
|
|
|
|
|
|
|
async function fetchRoomConfig(room) {
|
2026-05-16 12:18:35 +02:00
|
|
|
if (!room) {
|
|
|
|
|
console.error("Cannot fetch an undefined room");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const response = await authedAPIRequest("/rooms/" + room + "/config", {
|
|
|
|
|
method: "GET",
|
|
|
|
|
});
|
2026-05-16 11:14:39 +02:00
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
console.error("Could not retrieve room config: " + response.statusText);
|
|
|
|
|
console.debug(await response.text());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-16 12:18:35 +02:00
|
|
|
const res = await response.json();
|
|
|
|
|
|
|
|
|
|
console.debug(`Retrieved config for room ${room}:`);
|
|
|
|
|
console.debug(res);
|
2026-05-16 11:14:39 +02:00
|
|
|
|
2026-05-16 12:18:35 +02:00
|
|
|
setCurrentRoomConfig(res);
|
2026-05-16 11:14:39 +02:00
|
|
|
|
|
|
|
|
// Update HTML
|
2026-05-16 12:18:35 +02:00
|
|
|
const roomNameElt = document.getElementById("room-name");
|
|
|
|
|
|
|
|
|
|
roomNameElt.innerText = res.metadata.name;
|
2026-05-16 11:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
2026-05-16 12:18:35 +02:00
|
|
|
export {
|
|
|
|
|
fetchRoomConfig,
|
|
|
|
|
setCurrentRoomConfig,
|
|
|
|
|
getCurrentRoomConfig,
|
|
|
|
|
joinRoom,
|
|
|
|
|
// listRooms,
|
|
|
|
|
// createRoom,
|
|
|
|
|
// updateRoom,
|
|
|
|
|
// deleteRoom
|
|
|
|
|
};
|