2022-12-16 00:38:45 +00:00
|
|
|
import '@acrd/types';
|
|
|
|
import { WS } from '@acrd/types';
|
2021-07-29 18:43:04 +01:00
|
|
|
import io from 'socket.io-client';
|
|
|
|
|
2025-03-22 13:35:52 +00:00
|
|
|
const ws = (io as any).connect(process.env.REACT_APP_WEBSITE_URL, {
|
2021-07-29 18:43:04 +01:00
|
|
|
secure: true,
|
|
|
|
path: `/ws`,
|
|
|
|
transports: ['websocket', 'polling', 'flashsocket'],
|
|
|
|
});
|
|
|
|
|
2025-03-22 13:35:52 +00:00
|
|
|
ws.io.on('open', () => console.log(`Connected to WS Server ${process.env.REACT_APP_WEBSITE_URL}/ws`));
|
2021-07-29 18:43:04 +01:00
|
|
|
|
2021-07-31 15:29:12 +01:00
|
|
|
export default ws as WSClient;
|
|
|
|
|
|
|
|
interface WSClient {
|
2021-10-04 18:15:43 +01:00
|
|
|
emit: <K extends keyof WS.To>(event: K, args: WS.To[K]) => any;
|
2021-08-23 17:20:48 +01:00
|
|
|
on: <K extends keyof WS.From>(event: K | 'error' | 'disconnect', callback: (args: WS.From[K]) => any) => any;
|
2021-08-22 19:25:02 +01:00
|
|
|
off: (event: string, callback?: any) => any;
|
|
|
|
disconnect: () => any;
|
2021-07-31 15:29:12 +01:00
|
|
|
}
|