export = SubscriptionMap; /**) * Typedef Imports * @typedef {import("../client/Client")} Client * @typedef {import("./ClientSet")} ClientSet */ /** * @exports SubscriptionMap * @class SubscriptionMap * @extends Map * @author 7kasper * @classdesc * Special map implementation for subscriptions. * SubscriptionMap contains an array of clients based on a key * which is the name of the subscription. This allows to easily broadcast messages * across many clients. Clients will automatically unsubscribe from subscription services * when a connection is lost. Subscription maps are thus an excellent way to * manage active and open connections. * * In addition to the map surface, instances expose a small lifecycle * event API so application code can react to channel membership * transitions without polling: * * ```js * rnio.subscriptions.on('subscribe', (name, size, client) => {}); * rnio.subscriptions.on('unsubscribe', (name, size, client) => {}); * rnio.subscriptions.on('first', (name, client) => {}); * rnio.subscriptions.on('empty', (name) => {}); * ``` * * - `subscribe` fires after every add. `size` is the new member count. * - `unsubscribe` fires after every remove. `size` is the new member count. * - `first` fires only when the channel transitions from empty → 1. * - `empty` fires only when the channel transitions to 0. * * Idempotent add/remove (re-adding a client already in the set, or * removing one that isn't) does not fire any event — the underlying * `Set` swallows the operation and member count is unchanged. * * The emitter is composed rather than mixed in because the class * already extends `Map` and JS doesn't do multiple inheritance. */ declare class SubscriptionMap extends Map { constructor(); _emitter: EventEmitter; /** * Register a lifecycle listener. See the class JSDoc for the * available events and their signatures. * @param {string} event * @param {Function} fn * @returns {this} */ on(event: string, fn: Function): this; /** * Remove a lifecycle listener. * @param {string} event * @param {Function} fn * @returns {this} */ off(event: string, fn: Function): this; /** * Register a one-shot lifecycle listener. * @param {string} event * @param {Function} fn * @returns {this} */ once(event: string, fn: Function): this; /** * Subscribes a client to a service. Fires `subscribe` (always) and * `first` (only on the 0 → 1 transition). * @param {string} name - The name of service to subscribe to. * @param {Client} client - The client to subscribe. */ subscribe(name: string, client: Client): void; /** * Unsubscribes a client from a service. Fires `unsubscribe` (always) * and `empty` (only on the n → 0 transition). * @param {string} name - The name of service to unsubscribe from. * @param {Client} client - The client to subscribe. */ unsubscribe(name: string, client: Client): void; /** * Gets the clientset belonging to the subscription, creating it on * first access. Each ClientSet remembers its `name` so its broadcast * methods can pass `(channel, publishId)` down to participating * {@link ProxyClient}s for shadow-frame coalescing across peer links. * * @param {string} name - The name of the subscription. * @returns {ClientSet} - the clientset belonging to that subscription. */ get(name: string): ClientSet; } declare namespace SubscriptionMap { export { Client, ClientSet }; } import { EventEmitter } from "node:events"; import ClientSet = require("./ClientSet"); /** * ) * Typedef Imports */ type Client = import("../client/Client"); /** * ) * Typedef Imports */ type ClientSet = import("./ClientSet");