import { StreamListener } from "../core/websockets/websocketManager"; import { BaseHttpResource } from "./baseHttp.resource"; import { ChatMessage, MultichatMessage } from "../core/entities/message"; export declare type WebsocketMessage = { action: string; response_status: number; data: MultichatMessage; }; /** * A class that can be subclassed to create resources managed by both websockets and HTTP. * Can be configured to use HTTP API calls and Websockets to sync states and rawData. */ export declare class BaseDemultiplexedHttpResource extends BaseHttpResource { resourceIdentifyingMetadata: { [key: string]: any; }; _callbacks: { [key: string]: any; }; _errorCallbacks: { [key: string]: any; }; _listeners: StreamListener[]; data: { [key: string]: any; }; stream_endpoint: string; actions: string[]; streams: string[]; constructor(streams?: string[], data?: { [key: string]: any; }); /** * @param stream */ getStreamListener(stream: string): StreamListener | undefined; getIncomingHandler(): (response: WebsocketMessage, stream: string) => void; callStreamCallbacksForMessage(stream: string, message: ChatMessage): void; _onUpdate(response: WebsocketMessage, stream: string): void; deregisterStreamListener(streamListener: StreamListener): void; /** * Return a function that can be used to handle the deregistration of a StreamListener. * @returns {(streamListener: ) => any} */ getDeregistrationHandler(): (streamListener: StreamListener) => void; /** * Basically cache keys * @return {{chat, pk}} */ readonly channelIdentifyingMetadata: { [key: string]: any; }; /** * @param actions * @param stream * @return {Function} - Returns a closure that enables any external entity to validate whether a stream/response * combination matches this chat. Returns true when a response should be demultiplexed in the context of this * Chat. */ getResponseMatcher(actions: Array, stream: string): Function; /** * Send rawData on a stream * @param data * @param stream */ sendDataOnStream(data: object, stream: string): void; /** * Make sure we're listening on the passed stream. Don't create another StreamListener if we are. * @param {string} stream * @param {Array} actions */ ensureListeningOnStream(stream: string, actions: Array): void; stopListeningOnStream(stream: string): void; /** * @param stream * @returns {boolean} - true if this chat has listeners on the message stream */ isListening(stream: string): boolean; /** * * @param callback - Function that gets executed on every received message * @param stream */ onStatusUpdate(callback: Function, stream: string): () => void; /** * Execute callback on every message. * Note: Remember to remove handlers returned by this function when not needed by executing them * @param stream * @param {Function} callback - Function to execute on a message * @param {Function} [errorCallback] - Function to execute on a !201 response * @return {Function} - Closure that can be executed to deregister the callback */ onAction(stream: string, callback: Function, errorCallback?: Function): () => void; }