added pong keepalive

This commit is contained in:
Maieul BOYER 2026-01-10 17:58:11 +01:00 committed by Maix0
parent 901e3e5a8e
commit 1b169fca13
3 changed files with 22 additions and 12 deletions

View file

@ -17,6 +17,7 @@ import "./pong.css";
declare module "ft_state" {
interface State {
pongSock?: CSocket;
pongKeepAliveInterval?: ReturnType<typeof setInterval>;
}
}
@ -51,20 +52,21 @@ enum TourInfoState {
}
document.addEventListener("ft:pageChange", (newUrl) => {
if (
newUrl.detail.startsWith("/app/pong") ||
newUrl.detail.startsWith("/pong")
)
return;
if (window.__state.pongSock !== undefined) window.__state.pongSock.close();
if (window.__state.pongKeepAliveInterval !== undefined) clearInterval(window.__state.pongKeepAliveInterval);
window.__state.pongSock = undefined;
window.__state.pongKeepAliveInterval = undefined;
});
export function getSocket(): CSocket {
if (window.__state.pongSock === undefined)
if (window.__state.pongSock === undefined) {
window.__state.pongSock = io(window.location.host, {
path: "/api/pong/socket.io/",
}) as any as CSocket;
}
if (window.__state.pongKeepAliveInterval === undefined) {
window.__state.pongKeepAliveInterval = setInterval(() => { window.__state.pongSock?.emit("hello") }, 100);
}
return window.__state.pongSock;
}
@ -387,7 +389,7 @@ function pongClient(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
queueBtn.style.color = "white";
if (!isNullish(currentGame)) {
let end_txt : string = '';
let end_txt: string = '';
if ((user.id === currentGame.left.id && winner === 'left') ||
(user.id === currentGame.right.id && winner === 'right'))
end_txt = 'won! #yippe';

View file

@ -11,7 +11,7 @@ import client from "@app/api";
declare module 'ft_state' {
interface State {
tttSock?: Socket;
keepAliveInterval?: ReturnType<typeof setInterval>;
tttkeepAliveInterval?: ReturnType<typeof setInterval>;
}
}
@ -23,16 +23,16 @@ enum QueueState {
document.addEventListener("ft:pageChange", () => {
if (window.__state.tttSock !== undefined) window.__state.tttSock.close();
if (window.__state.keepAliveInterval !== undefined) clearInterval(window.__state.keepAliveInterval);
if (window.__state.tttkeepAliveInterval !== undefined) clearInterval(window.__state.tttkeepAliveInterval);
window.__state.tttSock = undefined;
window.__state.keepAliveInterval = undefined;
window.__state.tttkeepAliveInterval = undefined;
});
export function getSocket(): Socket {
if (window.__state.tttSock === undefined)
window.__state.tttSock = io(window.location.host, { path: "/api/ttt/socket.io/" }) as any as Socket;
if (window.__state.keepAliveInterval === undefined)
window.__state.keepAliveInterval = setInterval(() => window.__state.tttSock?.emit('keepalive'), 100);
if (window.__state.tttkeepAliveInterval === undefined)
window.__state.tttkeepAliveInterval = setInterval(() => window.__state.tttSock?.emit('keepalive'), 100);
return window.__state.tttSock;
}