import { ErrorEvent } from 'reconnecting-websocket'; import { EventEmitter } from 'events'; import { WEBSOCKET_STATE } from './ReconnectingWebsocket'; import { InvalidTokenError, MissingCookieError } from '../auth/'; import { HttpClient } from '../http/'; import { Notification } from '../notification'; import { ConsumableNotification, ConsumableNotificationEvent, ConsumableNotificationSynchronization } from '../notification/ConsumableNotification'; declare enum TOPIC { ON_ERROR = "WebSocketClient.TOPIC.ON_ERROR", ON_INVALID_TOKEN = "WebSocketClient.TOPIC.ON_INVALID_TOKEN", ON_MESSAGE = "WebSocketClient.TOPIC.ON_MESSAGE", ON_STATE_CHANGE = "WebSocketClient.TOPIC.ON_STATE_CHANGE" } export interface WebSocketClient { on(event: TOPIC.ON_ERROR, listener: (error: Error | ErrorEvent) => void): this; on(event: TOPIC.ON_INVALID_TOKEN, listener: (error: InvalidTokenError | MissingCookieError) => void): this; on(event: TOPIC.ON_MESSAGE, listener: (notification: Notification | ConsumableNotification) => void): this; on(event: TOPIC.ON_STATE_CHANGE, listener: (state: WEBSOCKET_STATE) => void): this; } export type OnConnect = (abortHandler: AbortController) => void; export declare class WebSocketClient extends EventEmitter { private clientId?; private isRefreshingAccessToken; private readonly baseUrl; private readonly logger; private readonly socket; private websocketState; client: HttpClient; private isSocketLocked; private bufferedMessages; private abortHandler?; private versionPrefix; static readonly TOPIC: typeof TOPIC; private useLegacySocket; constructor(baseUrl: string, client: HttpClient); useVersion(version: number): void; private onStateChange; private readonly onMessage; private readonly onError; private readonly onReconnect; private readonly onOpen; private readonly onClose; /** * Attaches all listeners to the websocket and establishes the connection. * * @param clientId * When provided the websocket will get messages specific to the client. * If omitted the websocket will receive global messages for the account. * * @param onConnect * Handler that is executed before the websocket is fully connected. * Essentially the websocket will lock before execution of this function and * unlocks after the execution of the handler and pushes all buffered messages. */ connect(clientId?: string, onConnect?: OnConnect): WebSocketClient; private refreshAccessToken; disconnect(reason?: string): void; /** * Unlocks the websocket. * When unlocking the websocket all buffered messages between * connecting the websocket and the unlocking the websocket will be emitted. */ readonly unlock: () => void; /** * Locks the websocket so messages are buffered instead of being emitted. * Once the websocket gets unlocked buffered messages get emitted. * This behaviour is needed in order to not miss any messages * during fetching notifications from the notification stream. */ readonly lock: () => void; isLocked(): boolean; /** * this is a temporary hack method to check if app is running on * wire.com domain in order to use a different temporary websocket * endpoint on wire production server * delete this method as soon as /websocket no longer exists on prod backend * (possibly with next release of web), and change line 284 to use /await only * @returns true if app is connected to wire.com backend */ private _temporaryIsProdBackend; buildWebSocketUrl(): string; useAsyncNotificationsSocket(): void; acknowledgeMissedNotification(): void; acknowledgeConsumableNotificationSynchronization(notification: ConsumableNotificationSynchronization): void; acknowledgeNotification(notification: ConsumableNotificationEvent): void; /** * Performs a lightweight health check on the WebSocket connection. * Sends a ping and waits for a pong response without closing or reconnecting the socket. * The default timeout is 5 seconds; this may be configurable depending on the socket implementation. * This method does not disrupt the existing connection. * @returns A promise that resolves to true if a pong is received within the timeout, false otherwise. */ checkHealth(): Promise; } export {}; //# sourceMappingURL=WebSocketClient.d.ts.map