socket.io first attempt

This commit is contained in:
NigeParis 2025-11-16 19:42:19 +01:00 committed by Maix0
parent 5a905a1239
commit cf6f3145b6
9 changed files with 4901 additions and 7 deletions

View file

@ -4,16 +4,31 @@ import authHtml from './chat.html?raw';
import client from '@app/api'
import { updateUser } from "@app/auth";
import io from "socket.io-client"
const socket = io("https://localhost:8888");
// Listen for the 'connect' event
socket.on("connect", async() => {
console.log("Connected to the server: ", socket.id);
// Send a message to the server
socket.send("Hello from the client: " + `${socket.id}`);
// Emit a custom event 'coucou' with some data
socket.emit("coucou", { message: "Hello Nigel from coucou!" });
});
type Providers = {
name: string,
display_name: string,
icon_url?: string,
color?: { default: string, hover: string },
name: string,
display_name: string,
icon_url?: string,
color?: { default: string, hover: string },
};
function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn {
setTitle('Chat Page');
// Listen for the 'connect' event
return {
html: authHtml, postInsert: async (app) => {
@ -78,7 +93,13 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
showError('Failed to login: Unknown error');
}
});
}
}
}
};
addRoute('/chat', handleChat, { bypass_auth: true });

View file

@ -1,6 +1,7 @@
import { updateUser } from '@app/auth';
import { route_404 } from './special_routes'
// ---- Router logic ----
export function navigateTo(url: string) {
if (url.startsWith('/') && !url.startsWith('/app'))