kkk
This commit is contained in:
parent
441f00507d
commit
a0b5e97058
3 changed files with 52 additions and 23 deletions
|
|
@ -8,3 +8,19 @@
|
|||
// - createRoom (create a room)
|
||||
// - updateRoom (update a room's configuration)
|
||||
// - deleteRoom (delete a room)
|
||||
//
|
||||
|
||||
// joinRoom notes
|
||||
// io.on('connection', (socket) => {
|
||||
// // join the room named 'some room'
|
||||
// socket.join('some room');
|
||||
|
||||
// // broadcast to all connected clients in the room
|
||||
// io.to('some room').emit('hello', 'world');
|
||||
|
||||
// // broadcast to all connected clients except those in the room
|
||||
// io.except('some room').emit('hello', 'world');
|
||||
|
||||
// // leave the room
|
||||
// socket.leave('some room');
|
||||
// });
|
||||
|
|
|
|||
|
|
@ -144,22 +144,19 @@ async function authedAPIRequest(endpoint, options) {
|
|||
}
|
||||
|
||||
options.headers.Authorization = "Bearer " + localStorage.getItem("token");
|
||||
options.mode = "cors";
|
||||
|
||||
const full_endpoint = import.meta.env.VITE_URL + "/api" + endpoint;
|
||||
let response;
|
||||
|
||||
try {
|
||||
response = await fetch(full_endpoint, options);
|
||||
if (!response.ok) {
|
||||
throw new Error(response.statusText);
|
||||
}
|
||||
} catch (err) {
|
||||
if (response.status === 401) {
|
||||
const response_err = await response.text();
|
||||
|
||||
if (response_err.includes("Token expired")) {
|
||||
await refreshToken(null);
|
||||
if (await refreshToken(null)) {
|
||||
return await authedAPIRequest(endpoint, options);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -169,9 +166,6 @@ async function authedAPIRequest(endpoint, options) {
|
|||
return null;
|
||||
}
|
||||
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue