mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-02-09 02:10:18 +01:00
Ajout zones en pavage + fix dockefiles
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
"use client";
|
||||
import { createContext, useContext, useMemo, } from "react";
|
||||
import { createContext, useContext, useMemo } from "react";
|
||||
import { useSocket } from "./socketContext";
|
||||
import { useSocketAuth } from "@/hook/useSocketAuth";
|
||||
import { usePasswordProtect } from "@/hook/usePasswordProtect";
|
||||
import useSocketAuth from "@/hook/useSocketAuth";
|
||||
import usePasswordProtect from "@/hook/usePasswordProtect";
|
||||
|
||||
const adminConnexionContext = createContext();
|
||||
const AdminConnexionProvider = ({ children }) => {
|
||||
|
||||
export function AdminConnexionProvider({ children }) {
|
||||
const { adminSocket } = useSocket();
|
||||
const { login, loggedIn, loading } = useSocketAuth(adminSocket, "admin_password");
|
||||
const useProtect = () => usePasswordProtect("/admin/login", "/admin", loading, loggedIn);
|
||||
@@ -19,9 +20,6 @@ const AdminConnexionProvider = ({ children }) => {
|
||||
);
|
||||
}
|
||||
|
||||
function useAdminConnexion() {
|
||||
export function useAdminConnexion() {
|
||||
return useContext(adminConnexionContext);
|
||||
}
|
||||
|
||||
export { AdminConnexionProvider, useAdminConnexion };
|
||||
|
||||
|
||||
@@ -1,53 +1,43 @@
|
||||
"use client";
|
||||
import { createContext, useContext, useEffect, useMemo, useState } from "react";
|
||||
import { useSocket } from "./socketContext";
|
||||
import { useSocketListener } from "@/hook/useSocketListener";
|
||||
import useSocketListener from "@/hook/useSocketListener";
|
||||
import { useAdminConnexion } from "./adminConnexionContext";
|
||||
import { GameState } from "@/util/gameState";
|
||||
|
||||
const adminContext = createContext();
|
||||
|
||||
function AdminProvider({ children }) {
|
||||
export function AdminProvider({ children }) {
|
||||
const [teams, setTeams] = useState([]);
|
||||
const [zoneSettings, setZoneSettings] = useState(null)
|
||||
const [penaltySettings, setPenaltySettings] = useState(null);
|
||||
const [gameSettings, setGameSettings] = useState(null);
|
||||
const [zone, setZone] = useState(null);
|
||||
const [zoneExtremities, setZoneExtremities] = useState(null);
|
||||
const [nextZoneDate, setNextZoneDate] = useState(null);
|
||||
const [isShrinking, setIsShrinking] = useState(false);
|
||||
const { adminSocket } = useSocket();
|
||||
const { loggedIn } = useAdminConnexion();
|
||||
const [gameState, setGameState] = useState(GameState.SETUP);
|
||||
const [startDate, setStartDate] = useState(null);
|
||||
|
||||
useSocketListener(adminSocket, "game_state", (data) => {setGameState(data.state); setStartDate(data.startDate)});
|
||||
//Send a request to get the teams when the user logs in
|
||||
// Send a request to get the teams when the user logs in
|
||||
useEffect(() => {
|
||||
adminSocket.emit("get_teams");
|
||||
}, [loggedIn]);
|
||||
|
||||
function waiting(data) {
|
||||
setIsShrinking(false);
|
||||
function setCurrent_zone(data) {
|
||||
setZoneExtremities({begin: data.begin, end: data.end});
|
||||
setNextZoneDate(data.endDate);
|
||||
}
|
||||
|
||||
function shrinking(data) {
|
||||
setIsShrinking(true);
|
||||
setNextZoneDate(data);
|
||||
}
|
||||
|
||||
//Bind listeners to update the team list and the game status on socket message
|
||||
// Bind listeners to update the team list and the game status on socket message
|
||||
useSocketListener(adminSocket, "teams", setTeams);
|
||||
useSocketListener(adminSocket, "zone_settings", setZoneSettings);
|
||||
useSocketListener(adminSocket, "game_settings", setGameSettings);
|
||||
useSocketListener(adminSocket, "penalty_settings", setPenaltySettings);
|
||||
useSocketListener(adminSocket, "zone", setZone);
|
||||
useSocketListener(adminSocket, "zone_start", shrinking);
|
||||
useSocketListener(adminSocket, "new_zone", waiting);
|
||||
useSocketListener(adminSocket, "current_zone", setCurrent_zone);
|
||||
|
||||
const value = useMemo(() => ({ zone, zoneExtremities, teams, zoneSettings, penaltySettings, gameSettings, gameState, nextZoneDate, isShrinking, startDate }), [zoneSettings, teams, gameState, zone, zoneExtremities, penaltySettings, gameSettings, nextZoneDate, isShrinking, startDate]);
|
||||
const value = useMemo(() => ({ zoneExtremities, teams, zoneSettings, penaltySettings, gameSettings, gameState, nextZoneDate, startDate }), [zoneSettings, teams, gameState, zoneExtremities, penaltySettings, gameSettings, nextZoneDate, startDate]);
|
||||
return (
|
||||
<adminContext.Provider value={value}>
|
||||
{children}
|
||||
@@ -55,8 +45,6 @@ function AdminProvider({ children }) {
|
||||
);
|
||||
}
|
||||
|
||||
function useAdminContext() {
|
||||
export function useAdminContext() {
|
||||
return useContext(adminContext);
|
||||
}
|
||||
|
||||
export { AdminProvider, useAdminContext };
|
||||
@@ -1,22 +1,17 @@
|
||||
"use client";
|
||||
import { createContext, useContext, useMemo } from "react";
|
||||
|
||||
import { env } from 'next-runtime-env';
|
||||
import { io } from 'socket.io-client';
|
||||
|
||||
const { io } = require("socket.io-client");
|
||||
|
||||
var proto = "wss://";
|
||||
const NEXT_PUBLIC_SOCKET_HOST = env("NEXT_PUBLIC_SOCKET_HOST");
|
||||
if (NEXT_PUBLIC_SOCKET_HOST == "localhost") {
|
||||
proto = "ws://";
|
||||
}
|
||||
const SOCKET_URL = proto + 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",
|
||||
});
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
"use client";
|
||||
import { createContext, useContext, useMemo } from "react";
|
||||
import { useSocket } from "./socketContext";
|
||||
import { useSocketAuth } from "@/hook/useSocketAuth";
|
||||
import { usePasswordProtect } from "@/hook/usePasswordProtect";
|
||||
import useSocketAuth from "@/hook/useSocketAuth";
|
||||
import usePasswordProtect from "@/hook/usePasswordProtect";
|
||||
|
||||
const teamConnexionContext = createContext();
|
||||
const TeamConnexionProvider = ({ children }) => {
|
||||
|
||||
export function TeamConnexionProvider({ children }) {
|
||||
const { teamSocket } = useSocket();
|
||||
const { login, password: teamId, loggedIn, loading, logout } = useSocketAuth(teamSocket, "team_password");
|
||||
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]);
|
||||
@@ -19,9 +20,6 @@ const TeamConnexionProvider = ({ children }) => {
|
||||
);
|
||||
}
|
||||
|
||||
function useTeamConnexion() {
|
||||
export function useTeamConnexion() {
|
||||
return useContext(teamConnexionContext);
|
||||
}
|
||||
|
||||
export { TeamConnexionProvider, useTeamConnexion };
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
"use client";
|
||||
import { useLocation } from "@/hook/useLocation";
|
||||
import { useSocketListener } from "@/hook/useSocketListener";
|
||||
import { createContext, use, useContext, useEffect, useMemo, useRef, useState } from "react";
|
||||
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();
|
||||
|
||||
const teamContext = createContext()
|
||||
function TeamProvider({children}) {
|
||||
export function TeamProvider({children}) {
|
||||
const [teamInfos, setTeamInfos] = useState({});
|
||||
const [gameState, setGameState] = useState(GameState.SETUP);
|
||||
const [gameSettings, setGameSettings] = useState(null);
|
||||
@@ -21,17 +21,12 @@ function TeamProvider({children}) {
|
||||
|
||||
teamInfosRef.current = teamInfos;
|
||||
|
||||
useSocketListener(teamSocket, "update_team", (newTeamInfos) => {
|
||||
setTeamInfos({...teamInfosRef.current, ...newTeamInfos});
|
||||
});
|
||||
|
||||
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);
|
||||
@@ -48,8 +43,6 @@ function TeamProvider({children}) {
|
||||
);
|
||||
}
|
||||
|
||||
function useTeamContext() {
|
||||
export function useTeamContext() {
|
||||
return useContext(teamContext);
|
||||
}
|
||||
|
||||
export { TeamProvider, useTeamContext };
|
||||
Reference in New Issue
Block a user