File size: 553 Bytes
cce8120 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | import { io } from "socket.io-client";
const SOCKET_URL =
process.env.NEXT_PUBLIC_WS_URL ||
"http://127.0.0.1:8000";
let socket = null;
export function connectSocket(token = null) {
if (socket) return socket;
socket = io(SOCKET_URL, {
transports: ["websocket"],
autoConnect: true,
auth: token ? { token } : {}
});
return socket;
}
export function disconnectSocket() {
if (socket) {
socket.disconnect();
socket = null;
}
}
export function getSocket() {
return socket;
}
|