UNPKG

@boringnode/transmit

Version:

A framework agnostic Server-Sent-Event library

42 lines (41 loc) 1.74 kB
import { StreamManager } from './stream_manager.js'; import type { Transport } from '@boringnode/bus/types/main'; import type { AccessCallback, Broadcastable, TransmitConfig } from './types/main.js'; import type { CreateStreamParams, SubscribeParams, UnsubscribeParams } from './stream_manager.js'; export interface TransmitLifecycleHooks<Context> { connect: { uid: string; context: Context; }; disconnect: { uid: string; context: Context; }; broadcast: { channel: string; payload: Broadcastable; }; subscribe: { uid: string; channel: string; context: Context; }; unsubscribe: { uid: string; channel: string; context: Context; }; } export declare class Transmit<Context extends unknown> { #private; constructor(config: TransmitConfig, transport?: Transport | null); getManager(): StreamManager<Context>; createStream(params: Omit<CreateStreamParams<Context>, 'onConnect' | 'onDisconnect'>): import("./stream.js").Stream; authorize<Params extends Record<string, string>>(channel: string, callback: AccessCallback<Context, Params>): void; subscribe(params: Omit<SubscribeParams<Context>, 'onSubscribe'>): Promise<boolean>; unsubscribe(params: Omit<UnsubscribeParams<Context>, 'onUnsubscribe'>): Promise<boolean>; broadcastExcept(channel: string, payload: Broadcastable, senderUid: string | string[]): void; broadcast(channel: string, payload?: Broadcastable): void; on<T extends keyof TransmitLifecycleHooks<Context>>(event: T, callback: (payload: TransmitLifecycleHooks<Context>[T]) => void): import("emittery").UnsubscribeFunction; shutdown(): Promise<void>; }