import { WsClientEventDefinition, WsServerEventDefinition } from '@gecogvidanto/shared'; /** * Manage a web socket at client side. */ export default class WebSocket { /** * The socket. */ private readonly socket; /** * Create the socket. */ constructor(); /** * Add a callback function when connection established. Beware that this should be called immediately after creating * the object, or the connection event may be lost. * * @param callback - The callback function which will be called when connection. */ onConnect(callback: () => void): void; /** * Close the connection. */ close(): void; /** * Emit a new event. * * @param event - The event name. * @param args - The event arguments. */ emit(event: T, ...args: WsClientEventDefinition[T]): void; /** * Listen to an event. * * @param event - The event to listen to. * @param callback - The function to execute on event. */ on(event: T, callback: (...args: WsServerEventDefinition[T]) => void): void; }