import { CallEventListener, EventTypes } from '../coordinator/connection/types'; import type { SfuEvent } from '../gen/video/sfu/event/events'; export type SfuEventKinds = NonNullable; export type AllSfuEvents = { [K in SfuEventKinds]: K extends keyof Extract ? Extract[K] : never; }; export type DispatchableMessage = { eventPayload: { oneofKind: K; } & { [Key in K]: AllSfuEvents[Key]; }; }; /** * Determines if a given event name belongs to the category of SFU events. * * @param eventName the name of the event to check. * @returns true if the event name is an SFU event, otherwise false. */ export declare const isSfuEvent: (eventName: SfuEventKinds | EventTypes) => eventName is SfuEventKinds; export type ListenerTag = string | (() => string); type AnyListener = CallEventListener; type DynamicHandler = { tagSelector: () => string; listener: AnyListener; }; export declare class Dispatcher { private readonly logger; private subscribers; /** * Dispatch an event to all subscribers. * * @param message the event payload to dispatch. * @param tag for scoping events to a specific tag. Use `*` dispatch to every tag. */ dispatch: (message: DispatchableMessage, tag?: string) => void; /** * Emit an event to a list of listeners. * * @param payload the event payload to emit. * @param listeners the list of listeners to emit the event to. */ emit: (payload: any, listeners?: AnyListener[]) => void; /** * Emit an event to a list of listeners. * */ emitDynamic: (payload: any, tag: string, dynamic: DynamicHandler[]) => void; /** * Emit an event to a single listener. * @param payload the event payload to emit. * @param listener the listener to emit the event to. */ private emitOne; /** * Subscribe to an event. * * @param eventName the name of the event to subscribe to. * @param tag for scoping events to a specific tag. Can be a static tag * string or a function that resolves the tag dynamically. * @param fn the callback function to invoke when the event is emitted. * @returns a function that can be called to unsubscribe from the event. */ on: (eventName: E, tag: ListenerTag, fn: CallEventListener) => () => void; /** * Unsubscribe from an event. * * @param eventName the name of the event to unsubscribe from. * @param tag the original static/dynamic tag selector used during subscription. * @param fn the callback function to remove from the event listeners. */ off: (eventName: E, tag: ListenerTag, fn: CallEventListener) => void; private getHandlers; } export {};