mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-02-09 10:20:16 +01:00
Ajout traque-app
This commit is contained in:
24
traque-app/context/socketContext.jsx
Normal file
24
traque-app/context/socketContext.jsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import { createContext, useContext, useMemo } from "react";
|
||||
import { io } from "socket.io-client";
|
||||
|
||||
const HOST = '192.168.15.129'; // IP of the machine hosting the server
|
||||
|
||||
const SOCKET_URL = (HOST == "traque.rezel.net" ? "wss://" : "ws://") + HOST + "/player";
|
||||
const SERVER_URL = (HOST == "traque.rezel.net" ? "https://" : "http://") + HOST + "/back";
|
||||
|
||||
export const teamSocket = io(SOCKET_URL, {
|
||||
path: "/back/socket.io",
|
||||
});
|
||||
|
||||
export const SocketContext = createContext();
|
||||
|
||||
export default function SocketProvider({ children }) {
|
||||
const value = useMemo(() => ({ teamSocket, SERVER_URL }), [teamSocket]);
|
||||
return (
|
||||
<SocketContext.Provider value={value}>{children}</SocketContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useSocket() {
|
||||
return useContext(SocketContext);
|
||||
}
|
||||
Reference in New Issue
Block a user