import { Observable } from 'rxjs'; import { DDPStorage } from './ddp-storage'; import { DDP_COLLECTIONS } from './ddp-names'; export declare abstract class OnDDPMessage { abstract onMessage(data: any): void; } export declare abstract class OnDDPConnected { abstract onConnected(): void; } export declare abstract class OnDDPDisconnected { abstract onDisconnected(): void; } export declare abstract class OnSocketClosed { abstract onSocketClosed(event: any): void; } export declare abstract class OnSocketError { abstract onSocketError(error: any): void; } export interface IDDPClientSettings { url?: string; host?: string; port?: number; ssl?: boolean; path?: string; ddpVersion?: string; socketConstructor: any; pingInterval?: number; reconnectInterval?: number; } export declare class DDPClient implements OnDDPMessage, OnDDPConnected, OnDDPDisconnected, OnSocketClosed, OnSocketError { protected _isConnecting: boolean; protected _isConnected: boolean; protected _isClosed: boolean; protected pingInterval: number; protected reconnectTimeout: number; protected reconnectStatus: { attempt: number; nextDelay: number; }; protected _nextId: number; protected _callbacks: { [key: number]: Function; }; protected _updatedCallbacks: { [key: number]: Function; }; protected _pendingMethods: { [key: number]: Function; }; protected session: string; protected socket: WebSocket; protected ddpSettings: IDDPClientSettings; protected ddpStorage: DDPStorage; constructor(ddpSettings?: IDDPClientSettings); /** * Open a WebSocket connection to the server (if not already open or in progress) * Fire the onConnected when server respond with "connected" * @param {string} url if Url is provided, we connect directily to the url instead of using the DDPClientSettings */ connect(url?: any): void; /** * Close the WebSocket (if not already close) * Fire the onDisconnected in any case */ disconnect(needToReconnect?: boolean): void; /** * If a there is a WebSocket instance and is not CLOSED, call the socket.close() method * Reset also the onclose and onerror callbacks to avoid multiple disconnect() calls */ close(): void; ping(): void; /** * Fired when socket had and error */ onSocketError(error: any): void; /** * Fired when socket close */ onSocketClosed(event: any): void; /** * Fired when socket received a message * @param {EJSON} data message data in EJSON format */ onMessage(data: any): void; /** * Fired when respond with "connected" message * @param {EJSON} EJSON data */ onConnected(): void; /** * Just for notify errors. Fired when socket get an error or DDP server connection failed * @param {string} reason Error/reason of the exception */ onFailed(reason: string): void; /** * Fired when DDP become unusable (socket close, ddp do not respond, handshake failed) */ onDisconnected(): void; /** * @whatItDoes call a method on the server * @description * @param {string} name of the DDP method to call * @param {any} object containing the params to send to the method (encode as EJSON) * @param {Function} callback called with the result when the server respond RESULT * @param {Function} updatedCallback called when the server respond UPDATE */ protected call(name: string, params: any, callback: Function, updatedCallback?: Function): boolean; protected callWithPromise(name: string, params: any): Promise; protected callWithRandomSeed(name: string, params: any, randomSeed: any, callback: any, updatedCallback: any): void; /** * open a subscription on the server, * callback should handle on ready and nosub */ protected subscribe(name: string, params: any, unsubscribeCallback?: Function): string; protected unsubscribe(id: string): void; protected observeCollection(collectionName: DDP_COLLECTIONS): Observable; protected getItemFromCollection(collectionName: DDP_COLLECTIONS, value: any, fieldName?: string): any; protected convertToEJSON(data: any): string; private _send; /** * handle a message from the server */ private _message; private _connected; private _disconnected; /** * Fire the onFailed every time eather the socket drop (error) or the handshake wih DDP failed */ private _failed; private _notifySendFail; private _createUrlFromSettings; private _getNextId; private _endPendingMethodCalls; }