/// import * as lrap from '../long-running-async-process'; import ClientStickySocket from './clientStickySocket'; import { EmitHistoryPacket, SocketOptions } from './common.types'; import EventEmitter from '../../tools/eventEmitter'; import Queue from '../../tools/queue'; /** * A socket connection */ declare class StickySocketConnection extends lrap.RootProcess { private _options?; private _socket; private _client; private _sharedState; private _internalEvents; private _disconnectReason?; private _logger; private _prevStageListeners; private _label; /** * Returns native socket * @returns socket.io socket */ get socket(): SocketIOClient.Socket; /** * Returns current transport name, using socket.io internals * @returns transport name, e.g. "websocket" */ get transportName(): string; /** * Returns first present packet index in last emit history * @returns first history index * @internal intended for tests only */ get firstHistoryIndex(): number | undefined; /** * @inheritdoc * @param client parent client * @param internalEvents internal event emitter */ inject(client: ClientStickySocket, internalEvents: EventEmitter): void; /** * @inheritdoc * @param url url to connect to * @param sessionId session ID * @param sharedState shared state * @param options additiona options */ initialize(url: string, sessionId: string, sharedState: StickySocketConnection.SharedState, options?: StickySocketConnection.Options): void; /** * Emits a data event. All events are buffered if no connection * @param event The event that we're emitting * @param args Optional arguments to send with the event */ send(event: string, ...args: any[]): void; /** * @inheritdoc */ start(stopPromise: lrap.HandlePromise): Promise; private _connect; private _restoreConnectionIfNeeded; /** * @inheritdoc */ run(stopPromise: lrap.HandlePromise): Promise; /** * Removes expired emit history */ removeExpiredEmitHistory(): void; private _tryDisconnectClientGracefully; /** * @inheritdoc */ stop(): Promise; private _setSocketStageListener; private _removePrevStageListeners; } declare namespace StickySocketConnection { /** Options */ type Options = SocketOptions & { /** Logging label to identify this instance. Defaults to `default` */ label?: string; /** Native socket IO options */ connection?: Pick & { /** * Headers that will be passed for each request to the server (via xhr-polling and via websockets). These values * then can be used during handshake or for special proxies */ extraHeaders?: Record; }; /** * Adjusts compatibility to work in mode when a native socket.io server is used. In this mode the socket will not * try to restore connection and will send packets as is. Intended for tests where native socket.io server is used */ useNativeSocketIoServer?: boolean; }; /** Shared state */ type SharedState = { /** Count of times a connection is started */ startCount: number; /** Emit */ emitHistory: Queue; /** Last sent index. Starts from `0`. If no packets were sent yet, defaults to `-1` */ lastSentIndex: number; /** Last received packet index. Starts from `0`. If no packets were received, defaults to `-1` */ lastReceivedIndex: number; }; /** Shared events for intermediate state */ type SharedEvents = { /** Connected event */ connect: () => void; /** Lost connection event */ fail: (err: Error) => void; }; /** Connection events */ const CONNECTION_EVENTS: string[]; /** Sticky connection protocol events */ const PROTOCOL_EVENTS: string[]; /** Internal events */ const INTERNAL_EVENTS: string[]; } export default StickySocketConnection;