mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-02-09 02:10:18 +01:00
Delete team pageweb (obselete + useless)
This commit is contained in:
@@ -5,13 +5,8 @@ import { io } from 'socket.io-client';
|
||||
|
||||
const NEXT_PUBLIC_SOCKET_HOST = env("NEXT_PUBLIC_SOCKET_HOST");
|
||||
const SOCKET_URL = (NEXT_PUBLIC_SOCKET_HOST == "localhost" ? "ws://" : "wss://") + NEXT_PUBLIC_SOCKET_HOST;
|
||||
const USER_SOCKET_URL = SOCKET_URL + "/player";
|
||||
const ADMIN_SOCKET_URL = SOCKET_URL + "/admin";
|
||||
|
||||
export const teamSocket = io(USER_SOCKET_URL, {
|
||||
path: "/back/socket.io",
|
||||
});
|
||||
|
||||
export const adminSocket = io(ADMIN_SOCKET_URL, {
|
||||
path: "/back/socket.io",
|
||||
});
|
||||
@@ -19,7 +14,8 @@ export const adminSocket = io(ADMIN_SOCKET_URL, {
|
||||
export const SocketContext = createContext();
|
||||
|
||||
export default function SocketProvider({ children }) {
|
||||
const value = useMemo(() => ({ teamSocket, adminSocket }), [teamSocket, adminSocket]);
|
||||
const value = useMemo(() => ({ adminSocket }), [adminSocket]);
|
||||
|
||||
return (
|
||||
<SocketContext.Provider value={value}>{children}</SocketContext.Provider>
|
||||
);
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
"use client";
|
||||
import { createContext, useContext, useMemo } from "react";
|
||||
import { useSocket } from "./socketContext";
|
||||
import useSocketAuth from "@/hook/useSocketAuth";
|
||||
import usePasswordProtect from "@/hook/usePasswordProtect";
|
||||
|
||||
const teamConnexionContext = createContext();
|
||||
|
||||
export function TeamConnexionProvider({ children }) {
|
||||
const { teamSocket } = useSocket();
|
||||
const { login, password: teamId, loggedIn, loading, logout } = useSocketAuth(teamSocket, "team_password");
|
||||
const useProtect = () => usePasswordProtect("/team", "/team/track", loading, loggedIn);
|
||||
|
||||
const value = useMemo(() => ({ teamId, login, logout, loggedIn, loading, useProtect}), [teamId, login, loggedIn, loading]);
|
||||
|
||||
return (
|
||||
<teamConnexionContext.Provider value={value}>
|
||||
{children}
|
||||
</teamConnexionContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useTeamConnexion() {
|
||||
return useContext(teamConnexionContext);
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
"use client";
|
||||
import useLocation from "@/hook/useLocation";
|
||||
import useSocketListener from "@/hook/useSocketListener";
|
||||
import { createContext, useContext, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useSocket } from "./socketContext";
|
||||
import { useTeamConnexion } from "./teamConnexionContext";
|
||||
import { GameState } from "@/util/gameState";
|
||||
|
||||
const teamContext = createContext();
|
||||
|
||||
export function TeamProvider({children}) {
|
||||
const [teamInfos, setTeamInfos] = useState({});
|
||||
const [gameState, setGameState] = useState(GameState.SETUP);
|
||||
const [gameSettings, setGameSettings] = useState(null);
|
||||
const [zone, setZone] = useState(null);
|
||||
const [zoneExtremities, setZoneExtremities] = useState(null);
|
||||
const measuredLocation = useLocation(5000);
|
||||
const {teamSocket} = useSocket();
|
||||
const {loggedIn} = useTeamConnexion();
|
||||
const teamInfosRef = useRef();
|
||||
|
||||
teamInfosRef.current = teamInfos;
|
||||
|
||||
useSocketListener(teamSocket, "update_team", (newTeamInfos) => setTeamInfos({...teamInfosRef.current, ...newTeamInfos}) );
|
||||
useSocketListener(teamSocket, "game_state", setGameState);
|
||||
useSocketListener(teamSocket, "zone", setZone);
|
||||
useSocketListener(teamSocket, "new_zone", setZoneExtremities);
|
||||
useSocketListener(teamSocket, "game_settings", setGameSettings);
|
||||
|
||||
//Send the current position to the server when the user is logged in
|
||||
useEffect(() => {
|
||||
console.log("sending position", measuredLocation);
|
||||
if(loggedIn) {
|
||||
teamSocket.emit("update_position", measuredLocation);
|
||||
}
|
||||
}, [loggedIn, measuredLocation]);
|
||||
|
||||
const value = useMemo(() => ({teamInfos, gameState, zone, zoneExtremities, gameSettings}), [gameSettings, teamInfos, gameState, zone, zoneExtremities]);
|
||||
return (
|
||||
<teamContext.Provider value={value}>
|
||||
{children}
|
||||
</teamContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useTeamContext() {
|
||||
return useContext(teamContext);
|
||||
}
|
||||
Reference in New Issue
Block a user