hhhhhnnn mimimimimimimimi
This commit is contained in:
parent
0114214995
commit
441f00507d
4 changed files with 68 additions and 9 deletions
|
|
@ -1,3 +1,6 @@
|
|||
import { io } from "socket.io-client";
|
||||
// import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
// FIXME: This file should handle the sockets and the subscriptions
|
||||
// Exports must include
|
||||
// - initSocket (initialize the connection to the socket server)
|
||||
|
|
@ -7,3 +10,47 @@
|
|||
// - subscribe (subscribe to a room's stream or chat)
|
||||
// - unsubscribe (unsubscribe from a room's stream or chat)
|
||||
// - sendMessage (send a message to a room's chat)
|
||||
|
||||
let socket = null;
|
||||
// let uuid = uuidv4();
|
||||
|
||||
/**
|
||||
* Initializes the socket when authenticated
|
||||
* returns {Promise<void>}
|
||||
*/
|
||||
async function initSocket() {
|
||||
console.debug("Initializing socket connection");
|
||||
const token = localStorage.getItem("token");
|
||||
|
||||
const host = import.meta.env.VITE_HOST;
|
||||
const port = import.meta.env.VITE_PORT;
|
||||
const wsUri = "ws://" + host + (port ? ":" + port : "");
|
||||
|
||||
socket = io(wsUri, {
|
||||
reconnectionDelayMax: 10000,
|
||||
extraHeaders: {
|
||||
Authorization: "Bearer " + token,
|
||||
},
|
||||
});
|
||||
|
||||
console.debug("Socket active: " + socket.active);
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO
|
||||
// async function subscribe(room) {
|
||||
|
||||
// if (!room)
|
||||
// room = "epi-place"
|
||||
|
||||
// console.warn("Skipping room susbscription (not implemented)")
|
||||
// }
|
||||
|
||||
// async function unsubscribe() {
|
||||
|
||||
// }
|
||||
// async function sendMessage() {
|
||||
|
||||
// }
|
||||
|
||||
export { initSocket, socket };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue