Files
traque/traque-app/hook/useGame.jsx
Sebastien Riviere 7e4d9f910a Cleaning
2025-09-11 17:15:24 +02:00

33 lines
1.1 KiB
JavaScript

import { useSocket } from "../context/socketContext";
import { useTeamConnexion } from "../context/teamConnexionContext";
import { useTeamContext } from "../context/teamContext";
export default function useGame() {
const { teamSocket } = useSocket();
const { teamId } = useTeamConnexion();
const { teamInfos } = useTeamContext();
function sendCurrentPosition() {
console.log("Reveal position.")
teamSocket.emit("send_position");
}
function capture(captureCode) {
console.log("Try to capture :", captureCode);
return new Promise((resolve, reject) => {
const timeout = setTimeout(() => {
console.warn("Server did not respond to capture emit.");
reject();
}, 3000);
teamSocket.emit("capture", captureCode, (response) => {
clearTimeout(timeout);
console.log(response.message);
resolve(response);
});
});
}
return {...teamInfos, sendCurrentPosition, capture, teamId};
}