Download apps/web/src/lib/socket.ts from myagent10101/codesync-collaborative-platform: direct link, hf CLI and curl.
- Browser
- Download file 668 Bytes
-
https://huggingface.co/myagent10101/codesync-collaborative-platform/resolve/main/apps/web/src/lib/socket.ts
- Command line
-
hf download hf://myagent10101/codesync-collaborative-platform/apps/web/src/lib/socket.ts
-
curl -L -o socket.ts https://huggingface.co/myagent10101/codesync-collaborative-platform/resolve/main/apps/web/src/lib/socket.ts
668 Bytes
| import { io, Socket } from 'socket.io-client'; | |
| const SOCKET_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:4000'; | |
| let socket: Socket | null = null; | |
| export function getSocket(token: string): Socket { | |
| if (socket?.connected) return socket; | |
| socket = io(SOCKET_URL, { | |
| auth: { token }, | |
| transports: ['websocket', 'polling'], | |
| reconnection: true, | |
| reconnectionAttempts: 10, | |
| reconnectionDelay: 1000, | |
| timeout: 20000, | |
| autoConnect: false, | |
| }); | |
| return socket; | |
| } | |
| export function disconnectSocket(): void { | |
| if (socket) { socket.disconnect(); socket = null; } | |
| } | |
| export function getCurrentSocket(): Socket | null { | |
| return socket; | |
| } | |