First Commit

This commit is contained in:
Ralex91
2024-01-31 20:06:10 +01:00
commit e122fe1078
58 changed files with 6853 additions and 0 deletions

24
src/context/socket.jsx Normal file
View File

@@ -0,0 +1,24 @@
import { io } from "socket.io-client"
import { createContext, useContext, useState } from "react"
import { WEBSOCKET_URL } from "@/constants"
export const socket = io("http://localhost:5057", {
path: "/ws/",
//addTrailingSlash: false,
transports: ["websocket"],
})
export const SocketContext = createContext()
export const SocketContextProvider = ({ children }) => {
return (
<SocketContext.Provider value={socket}>{children}</SocketContext.Provider>
)
}
export function useSocketContext() {
const context = useContext(SocketContext)
const [isConnected, setIsConnected] = useState(false)
return { socket: context }
}