This commit is contained in:
Guillem George 2026-05-15 22:59:15 +02:00
parent 441f00507d
commit a0b5e97058
3 changed files with 52 additions and 23 deletions

View file

@ -1,5 +1,5 @@
import { io } from "socket.io-client";
// import { v4 as uuidv4 } from "uuid";
import { v4 as uuidv4 } from "uuid";
// FIXME: This file should handle the sockets and the subscriptions
// Exports must include
@ -12,13 +12,18 @@ import { io } from "socket.io-client";
// - sendMessage (send a message to a room's chat)
let socket = null;
// let uuid = uuidv4();
const uuid = uuidv4();
/**
* Initializes the socket when authenticated
* returns {Promise<void>}
*/
async function initSocket() {
if (socket !== null) {
console.warn("Blocked attempt to re-init socket connection");
return;
}
console.debug("Initializing socket connection");
const token = localStorage.getItem("token");
@ -38,13 +43,27 @@ async function initSocket() {
}
// TODO
// async function subscribe(room) {
async function subscribe(room) {
if (!room) {
room = "epi-place";
}
// if (!room)
// room = "epi-place"
// console.warn("Skipping room susbscription (not implemented)")
const msg = {
id: uuid,
method: "subscription",
params: {
path: "rooms.canvas.getStream" | "rooms.getChat",
input: {
json: {
roomSlug: room,
},
},
},
};
// console.warn("Skipping room susbscription (not implemented)")
// }
socket.send(msg);
}
// async function unsubscribe() {