mirror of
https://github.com/randyjc/Rahoot.git
synced 2026-03-13 20:15:35 +01:00
First Commit
This commit is contained in:
24
src/context/socket.jsx
Normal file
24
src/context/socket.jsx
Normal 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 }
|
||||
}
|
||||
Reference in New Issue
Block a user