import DemultiplexedReconnectingWebsocket from "../../helpers/reconnectingWebsocket"; import { WebsocketMessage } from "../../resources/baseDemultiplexedHttp.resource"; export declare type WebsocketManagerSettings = { DEBUG: boolean; WSS: boolean; WS_DOMAIN: string; WS_PORT: string; WS_ENDPOINT: string; }; /** * Used to manage streams exposed using the Django Channels swebsocketBridge demultiplexing functionality. * But it also integrates with the events that Django-Channels API provides. * @constructor */ export declare class WebsocketManager { url: string; base_url: string; private _endpoint; _webSocketBridge: DemultiplexedReconnectingWebsocket; _listeners: Array; /** * @return WebsocketManager instance */ constructor(endpoint: string, settings?: WebsocketManagerSettings); /** * Connect the wrapped webSocketBridge */ private connect(); getUrl(): string; /** * Find listeners based on stream and message * @param {string} stream - The stream to look for * @param {message} [message] - A message received on the Websocket, can be used to choose a StreamListener * @return {Array} - The StreamListeners that are valid for the (stream, message) combination * @private */ _findListeners(stream: string, message?: WebsocketMessage): any; /** * Demultiplex on events, not only on stream. * @private * @param demultiplexedStream */ _demultiplex(demultiplexedStream: string): void; /** * Get a stream object * @param stream * @returns A stream */ stream(stream: string): { send: (payload: object) => void; }; /** * Send rawData on the websocket * @param stream * @param data */ send(stream: string, data: object): void; close(): void; /** * @param {StreamListener} streamListener * @return {StreamListener} */ registerStreamListener(streamListener: StreamListener): StreamListener; deregisterStreamListener(streamListener: StreamListener): void; } /** * A StreamListener can listen to several events (e.g. ['update', 'create']), on one single resource under a specific * stream. * * For example, you can listen on the 'chats' stream to a chat identified by {id: 1}, on the 'update' and 'create' * events. A second one: you can listen on the 'messages' stream to a chat identified by {chat: 1} on the 'create' * event. * * @constructor */ export declare class StreamListener { stream: string; events: Array; validator: Function; metaData: object; callback: Function; _socketManager: WebsocketManager; _onDeregistration: Function; /** * @param {String} [endpoint] - The endpoint to listen on * @param {String} stream - The stream to listen on * @param {Array} events - The events to listen on (e.g. 'create' or 'update'), within the specified stream * @param {function} validator - A function that accepts stream and a message, returns a boolean indicating whether * the StreamListener callback should be called * @param metaData - Metadata identifying a StreamListener, can be used to compare StreamListeners * @param {function} callback - The callback to execute when validator(stream, response) returns true * @param {function} [onDeregistration] - Handle deregistration on the WebsocketManager, can be used to track/remove * listeners in other contexts too */ constructor(endpoint: string, stream: string, events: Array, validator: Function, metaData: object, callback: Function, onDeregistration: Function); /** * Process a response */ processResponse(response: WebsocketMessage, stream: string): void; /** * Function that validates whether a given StreamListener is equal to this one. * @param streamListener * @return {boolean} */ isEqual(streamListener: StreamListener): boolean; /** * Subscribe to 'event' using the metaData passed to the StreamListener constructor to identify the resource to * subscribe to. */ listen(): void; /** * Remove the StreamListener from the SocketManager, and handle deregistration. */ deregister(): void; /** * Register this StreamListener on the WebsocketManager * @private */ _register(): void; /** * Send rawData to the WebsocketManager * @param action string - The action (e.g. 'create', 'update') * @param rawData object - The of the resource to create. Can contain identifying rawData. * @param useMetadata [{}] - Whether to use the available metadata */ send(action: string, rawData: object, useMetadata?: boolean): void; }