import { Api } from './api'; export type SocketEvent = { channel: string; spoke: string; type: string; data: T; }; export type SocketEventSlice = SocketEvent<{ slice: number; tx: string; new: number[]; lost: number[]; changed: number[]; }>; export type WebRTCEvent = { type: string; } & ({ connected: { uid: string; username: string; }; } | { disconnected: { uid: string; username: string; }; } | { offer: { to: string; uid: string; username: string; offer: RTCSessionDescriptionInit; }; } | { answer: { to: string; uid: string; username: string; offer: RTCSessionDescriptionInit; }; }); /** Connection options */ export type SocketOptions = { /** Set connection URL or disable with false */ url?: string | false; /** Use one-time socket tickets only when explicitly enabled by a chat-capable host. */ authentication?: 'token' | 'ticket'; /** Optional realm used by backward-compatible token authentication. */ realm?: string; }; /** Callback shape */ export type SocketListener> = (event: T) => any; /** Call to unsubscribe callback from event */ export type Unsubscribe = () => void; /** Datalynk Socket connection */ export declare class Socket { private readonly api; readonly options: SocketOptions; private listeners; private retry?; private socket?; private connectGeneration; open: boolean; constructor(api: Api, options?: SocketOptions); /** * Add listener for all socket events * * @param {SocketListener} fn Callback function * * * * * @return {Unsubscribe} Function to unsubscribe callback */ addListener(fn: SocketListener, reconnect: () => void): Unsubscribe; /** * Close socket connection */ close(): void; /** * Connect socket client to socket server * @param {number} timeout Retry to connect every x seconds */ connect(timeout?: number): void | Promise; /** * Ticket-authenticated connection path, used only once a chat-capable host switches * this instance to `authentication: 'ticket'` (see Api.openChat). Entirely separate * from the token path above so existing non-chat consumers are never affected. */ private connectWithTicket; private scheduleReconnect; /** * Send data to socket server * * @param payload Data that will be serialized */ send(payload: any): void; /** * Run callback whenever the server notifies us of slice changes * * @param {number | number[]} slice Slice to subscribe to * @param {SocketListener} callback Function to run on changes * @return {Unsubscribe} Run returned function to unsubscribe callback */ sliceEvents(slice: number | number[] | string | string[], callback: SocketListener): Unsubscribe; private normalizeUrl; } //# sourceMappingURL=socket.d.ts.map