mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-02-09 10:20:16 +01:00
fixed frontend for #10
This commit is contained in:
@@ -6,8 +6,6 @@ const { io } = require("socket.io-client");
|
|||||||
const SOCKET_URL = 'wss://' + process.env.NEXT_PUBLIC_SOCKET_HOST + ':' + process.env.NEXT_PUBLIC_SOCKET_PORT;
|
const SOCKET_URL = 'wss://' + process.env.NEXT_PUBLIC_SOCKET_HOST + ':' + process.env.NEXT_PUBLIC_SOCKET_PORT;
|
||||||
const USER_SOCKET_URL = SOCKET_URL + "/player";
|
const USER_SOCKET_URL = SOCKET_URL + "/player";
|
||||||
const ADMIN_SOCKET_URL = SOCKET_URL + "/admin";
|
const ADMIN_SOCKET_URL = SOCKET_URL + "/admin";
|
||||||
console.log(USER_SOCKET_URL);
|
|
||||||
console.log(ADMIN_SOCKET_URL);
|
|
||||||
|
|
||||||
export const teamSocket = io(USER_SOCKET_URL);
|
export const teamSocket = io(USER_SOCKET_URL);
|
||||||
export const adminSocket = io(ADMIN_SOCKET_URL);
|
export const adminSocket = io(ADMIN_SOCKET_URL);
|
||||||
|
|||||||
@@ -8,19 +8,21 @@ import { useTeamConnexion } from "./teamConnexionContext";
|
|||||||
const teamContext = createContext()
|
const teamContext = createContext()
|
||||||
function TeamProvider({children}) {
|
function TeamProvider({children}) {
|
||||||
const [enemyPosition, setEnemyPosition] = useState();
|
const [enemyPosition, setEnemyPosition] = useState();
|
||||||
const currentPosition = useLocation(10000);
|
const [currentPosition, setCurrentPosition] = useState();
|
||||||
|
const measuredLocation = useLocation(10000);
|
||||||
const {teamSocket} = useSocket();
|
const {teamSocket} = useSocket();
|
||||||
const {loggedIn} = useTeamConnexion();
|
const {loggedIn} = useTeamConnexion();
|
||||||
|
|
||||||
useSocketListener(teamSocket, "enemy_position", setEnemyPosition);
|
useSocketListener(teamSocket, "enemy_position", setEnemyPosition);
|
||||||
|
useSocketListener(teamSocket, "live_location", setCurrentPosition);
|
||||||
|
|
||||||
//Send the current position to the server when the user is logged in
|
//Send the current position to the server when the user is logged in
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log("sending position", currentPosition);
|
console.log("sending position", measuredLocation);
|
||||||
if(loggedIn) {
|
if(loggedIn) {
|
||||||
teamSocket.emit("update_position", currentPosition);
|
teamSocket.emit("update_position", measuredLocation);
|
||||||
}
|
}
|
||||||
}, [loggedIn, currentPosition]);
|
}, [loggedIn, measuredLocation]);
|
||||||
|
|
||||||
const value = useMemo(() => ({enemyPosition, currentPosition}), [enemyPosition, currentPosition]);
|
const value = useMemo(() => ({enemyPosition, currentPosition}), [enemyPosition, currentPosition]);
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user