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 { authenticate } from "../utils/auth";
import { fetchRoomConfig } from "../rooms";
// Initialize the layout
calculateLayout();
@ -11,6 +12,13 @@ async () => {
return;
}
let room = window.location.pathname.split("/")[1];
if (room === "") {
room = "epi-place";
}
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
// Functions may include:
// - fetchRoomConfig (get the configuration of a room)
@ -24,3 +25,22 @@
// // leave the 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;
}
if (!options.method) {
console.error("Invalid parameter: options (missing method)");
return null;
}
// if (!options.method) {
// console.error("Invalid parameter: options (missing method)");
// return null;
// }
if (!options.headers) {
options.headers = {};
@ -146,9 +146,9 @@ async function authedAPIRequest(endpoint, options) {
options.headers.Authorization = "Bearer " + localStorage.getItem("token");
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) {
const response_err = await response.text();
@ -156,8 +156,6 @@ async function authedAPIRequest(endpoint, options) {
if (await refreshToken(null)) {
return await authedAPIRequest(endpoint, options);
}
return null;
}
localStorage.clear();

View file

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

View file

@ -42,18 +42,26 @@ async function initSocket() {
return;
}
// TODO
async function subscribe(room) {
async function subscribe(room, channel) {
if (!room) {
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 = {
id: uuid,
method: "subscription",
params: {
path: "rooms.canvas.getStream" | "rooms.getChat",
path: path,
input: {
json: {
roomSlug: room,
@ -72,4 +80,4 @@ async function subscribe(room) {
// }
export { initSocket, socket };
export { socket, initSocket, subscribe };