UNPKG

kuzzle-sdk

Version:
134 lines (133 loc) 5.16 kB
import { BaseController } from "./Base"; import { Notification, JSONObject, ArgsDefault } from "../types"; /** * Enum for `scope` option of realtime.subscribe method */ export declare enum ScopeOption { /** * Receive all document notifications */ all = "all", /** * Receive notifications when document enter or stay in the scope */ in = "in", /** * Receive notification when document exit the scope */ out = "out", /** * Do not receive document notifications */ none = "none" } /** * Enum for `user` option of realtime.subscribe method */ export declare enum UserOption { /** * Receive all user notifications */ all = "all", /** * Receive notification when users join the room */ in = "in", /** * Receive notifications when users leave the room */ out = "out", /** * Do not receive user notifications */ none = "none" } export declare class RealtimeController extends BaseController { private _subscriptions; private _subscriptionsOff; constructor(kuzzle: any); /** * Returns the number of other connections sharing the same subscription. * * @see https://docs.kuzzle.io/sdk/js/7/controllers/realtime/count/ * * @param roomId Subscription room ID * @param options Additional options * - `queuable` If true, queues the request during downtime, until connected to Kuzzle again * - `timeout` Request Timeout in ms, after the delay if not resolved the promise will be rejected * * @returns A number represensting active connections using the same provided subscription room. */ count(roomId: string, options?: ArgsRealtimeControllerCount): Promise<number>; /** * Sends a real-time message to Kuzzle. * * The message will be dispatched to all clients with subscriptions * matching the index, the collection and the message content. * * @see https://docs.kuzzle.io/sdk/js/7/controllers/realtime/count/ * * @param index Index name * @param collection Collection name * @param message Message to send (will be put in `_source` property of the notification) * @param options Additional options * - `queuable` If true, queues the request during downtime, until connected to Kuzzle again * - `_id` Additional unique ID (will be put in the `_id` property of the notification) * - `timeout` Request Timeout in ms, after the delay if not resolved the promise will be rejected */ publish(index: string, collection: string, message: JSONObject, options?: ArgsRealtimeControllerPublish): Promise<boolean>; /** * Subscribes by providing a set of filters: messages, document changes * and, optionally, user events matching the provided filters will generate * real-time notifications. * * @see https://docs.kuzzle.io/sdk/js/7/controllers/realtime/subscribe/ * @see https://docs.kuzzle.io/sdk/js/7/essentials/realtime-notifications/ * * @param index Index name * @param collection Collection name * @param filters Optional subscription filters (@see https://docs.kuzzle.io/core/2/api/koncorde-filters-syntax) * @param callback Callback function to handle notifications * @param options Additional options * - `scope` Subscribe to document entering or leaving the scope. (default: 'all') * - `users` Subscribe to users entering or leaving the room. (default: 'none') * - `subscribeToSelf` Subscribe to notifications fired by our own queries. (default: true) * - `volatile` Subscription information sent alongside notifications * - `timeout` Request Timeout in ms, after the delay if not resolved the promise will be rejected * * @returns A string containing the room ID */ subscribe(index: string, collection: string, filters: JSONObject, callback: (notification: Notification) => void | Promise<void>, options?: ArgsRealtimeControllerSubscribe): Promise<string>; /** * Removes a subscription * * @param roomId Subscription room ID * @param options Additional options * - `queuable` If true, queues the request during downtime, until connected to Kuzzle again * - `timeout` Request Timeout in ms, after the delay if not resolved the promise will be rejected */ unsubscribe(roomId: string, options?: ArgsRealtimeControllerUnsubscribe): Promise<void>; /** * Called when kuzzle is disconnected */ private saveSubscriptions; /** * Called on kuzzle reconnection */ private resubscribe; /** * Called when a token expire */ private removeSubscriptions; } export type ArgsRealtimeControllerCount = ArgsDefault; export interface ArgsRealtimeControllerPublish extends ArgsDefault { _id?: string; } export interface ArgsRealtimeControllerSubscribe extends ArgsDefault { scope?: ScopeOption; users?: UserOption; subscribeToSelf?: boolean; volatile?: JSONObject; } export type ArgsRealtimeControllerUnsubscribe = ArgsDefault;