import ApiError from './ApiError.js'; import Api from './Api.js'; /** * The Stream is responsible for managing your connection with a server * when you call connect Stream will try to create a WebSocket connection. * * At this point you can start a Sender or Receiver. The request will wait * until a channel could be established or the server closed it. * * You can listen for messages or send them until you receive the error event * which will mean the channel was closed. You can then try to create a new * one. * * When the Stream triggers an error event this might mean the connection is * closed but doesn't have to. You should wait until you receive the close * event to be sure. After that you can call connect again. * * * ## Important * Only use functions all properties are private also functions prefix with an * underscore. */ export default class Stream { api: Api; path: string; private ws; private connected; private openListeners; private errorListeners; private closeListeners; senders: Map; receivers: Map; constructor(api: Api, path: string); isConnect(): boolean; private _addr; connect(): void; onError(fn: (e: Event) => void): () => void; onClose(fn: () => void): () => void; close(): void; _waitReady(): Promise; newSender(action: string): Sender; newReceiver(action: string): Receiver; _send(protMsg: ProtMessage): void; private _handleProtMessage; } export type ProtMessage = { kind: 'SenderRequest' | 'SenderClose' | 'SenderMessage' | 'ReceiverRequest' | 'ReceiverMessage' | 'ReceiverClose'; action: string; data: any; }; export declare class Sender { action: string; private stream; private state; private openProm; private errorListeners; private rmCloseListener; constructor(action: string, stream: Stream); isReadyToOpen(): boolean; isReady(): boolean; isClosed(): boolean; open(req?: any): Promise; _onMsg(msg: ProtMessage): void; _closeWithError(err: ApiError): void; send(msg: any): void; onError(fn: (e: ApiError) => void): () => void; close(): void; } export declare class Receiver { action: string; private stream; private state; private openProm; private parseFn; private errorListeners; private messageListeners; private rmCloseListener; constructor(action: string, stream: Stream); isReadyToOpen(): boolean; isReady(): boolean; isClosed(): boolean; open(req?: any): Promise; _onMsg(msg: ProtMessage): void; _closeWithError(err: ApiError): void; onMessage(fn: (msg: any) => void): () => void; setParseFn(fn: (d: any) => any): void; onError(fn: (e: ApiError) => void): () => void; close(): void; closeTemporary(): void; } export declare class ReceiverManager { receiver: Receiver; openFn: (receiver: Receiver, hasError: boolean, error: any) => Promise; private state; private listeners; constructor(receiver: Receiver, open: (receiver: Receiver, hasError: boolean, error: any) => Promise); onMessage(fn: (msg: any) => void): () => void; _open(): Promise; _onError(_e: any): void; _onClose(): void; } //# sourceMappingURL=Stream.d.ts.map