watchtorrent / client /src /lib /socket.ts
Harsh Gupta
Initial commit: WatchTorrent - synchronized torrent streaming app
500a902
Raw
History Blame Contribute Delete
429 Bytes
import { io, Socket } from 'socket.io-client';
let socket: Socket | null = null;
export function getSocket(): Socket {
if (!socket) {
socket = io('/', {
transports: ['websocket', 'polling'],
reconnection: true,
reconnectionAttempts: 10,
reconnectionDelay: 1000,
});
}
return socket;
}
export function disconnectSocket() {
if (socket) {
socket.disconnect();
socket = null;
}
}