no moulinette ?

This commit is contained in:
Guillem George 2026-05-16 11:14:39 +02:00
parent a0b5e97058
commit 2b7b6b8684
5 changed files with 50 additions and 16 deletions

View file

@ -1,6 +1,7 @@
import { initSocket } from "../utils/streams"; import { initSocket, subscribe } from "../utils/streams";
import { calculateLayout } from "./utils"; import { calculateLayout } from "./utils";
import { authenticate } from "../utils/auth"; import { authenticate } from "../utils/auth";
import { fetchRoomConfig } from "../rooms";
// Initialize the layout // Initialize the layout
calculateLayout(); calculateLayout();
@ -11,6 +12,13 @@ async () => {
return; return;
} }
let room = window.location.pathname.split("/")[1];
if (room === "") {
room = "epi-place";
}
initSocket(); initSocket();
// subscribe() subscribe(room, "pixel-update");
fetchRoomConfig(room);
}; };

View file

@ -1,3 +1,4 @@
import { authedAPIRequest } from "../utils/auth";
// FIXME: This file should handle the rooms API // FIXME: This file should handle the rooms API
// Functions may include: // Functions may include:
// - fetchRoomConfig (get the configuration of a room) // - fetchRoomConfig (get the configuration of a room)
@ -24,3 +25,22 @@
// // leave the room // // leave the room
// socket.leave('some room'); // socket.leave('some room');
// }); // });
//
async function fetchRoomConfig(room) {
const response = await authedAPIRequest("/rooms/" + room + "/config");
if (!response.ok) {
console.error("Could not retrieve room config: " + response.statusText);
console.debug(await response.text());
return;
}
const obj = await response.json();
console.debug(`Retrieved config for room ${room}: ${obj}`);
// Update HTML
}
export { fetchRoomConfig };

View file

@ -134,10 +134,10 @@ async function authedAPIRequest(endpoint, options) {
return null; return null;
} }
if (!options.method) { // if (!options.method) {
console.error("Invalid parameter: options (missing method)"); // console.error("Invalid parameter: options (missing method)");
return null; // return null;
} // }
if (!options.headers) { if (!options.headers) {
options.headers = {}; options.headers = {};
@ -146,9 +146,9 @@ async function authedAPIRequest(endpoint, options) {
options.headers.Authorization = "Bearer " + localStorage.getItem("token"); options.headers.Authorization = "Bearer " + localStorage.getItem("token");
const full_endpoint = import.meta.env.VITE_URL + "/api" + endpoint; const full_endpoint = import.meta.env.VITE_URL + "/api" + endpoint;
let response;
response = await fetch(full_endpoint, options); const response = await fetch(full_endpoint, options);
if (response.status === 401) { if (response.status === 401) {
const response_err = await response.text(); const response_err = await response.text();
@ -156,8 +156,6 @@ async function authedAPIRequest(endpoint, options) {
if (await refreshToken(null)) { if (await refreshToken(null)) {
return await authedAPIRequest(endpoint, options); return await authedAPIRequest(endpoint, options);
} }
return null;
} }
localStorage.clear(); localStorage.clear();

View file

@ -21,7 +21,7 @@ function createLink() {
function redirectToLoginPage() { function redirectToLoginPage() {
const redirectUrl = createLink(); const redirectUrl = createLink();
window.location.href = redirectUrl; window.location.href = redirectUrl.href;
} }
export { createLink, redirectToLoginPage }; export { createLink, redirectToLoginPage };

View file

@ -42,18 +42,26 @@ async function initSocket() {
return; return;
} }
// TODO async function subscribe(room, channel) {
async function subscribe(room) {
if (!room) { if (!room) {
room = "epi-place"; room = "epi-place";
} }
// console.warn("Skipping room susbscription (not implemented)") if (!channel) {
channel = "message";
}
let path = "rooms.canvas.getStream";
if (channel.includes("chat") || channel.includes("message")) {
path = "rooms.getChat";
}
const msg = { const msg = {
id: uuid, id: uuid,
method: "subscription", method: "subscription",
params: { params: {
path: "rooms.canvas.getStream" | "rooms.getChat", path: path,
input: { input: {
json: { json: {
roomSlug: room, roomSlug: room,
@ -72,4 +80,4 @@ async function subscribe(room) {
// } // }
export { initSocket, socket }; export { socket, initSocket, subscribe };