UNPKG

laravel-echo

Version:

Laravel Echo library for beautiful Pusher, Socket.IO, and Mercure integration

45 lines (44 loc) • 1.99 kB
import { EventFormatter } from "../util"; import { Channel } from "./channel"; import type { EchoOptionsWithDefaults } from "../connector"; import type { BroadcastDriver } from "../echo"; /** Structural interface that avoids a runtime channel/connector import cycle. */ export interface MercureWhisperPublisher { whisper(channel: string, event: string, data: unknown): void; listenForWhispers(channel: string): void; } /** A Mercure channel. */ export declare class MercureChannel extends Channel { /** The channel name. */ name: string; /** The event formatter. */ eventFormatter: EventFormatter; /** Event callbacks keyed by wire event name. */ private listeners; /** Subscription callbacks. */ private subscribedCallbacks; /** Error callbacks. */ private errorCallbacks; /** The connector used to publish whispers. */ protected whisperer?: MercureWhisperPublisher; /** Create a channel. */ constructor(name: string, options: EchoOptionsWithDefaults<BroadcastDriver>, whisperer?: MercureWhisperPublisher); /** Listen for an event. */ listen(event: string, callback: CallableFunction): this; /** Stop listening for an event. */ stopListening(event: string, callback?: CallableFunction): this; /** Register a subscription callback. */ subscribed(callback: CallableFunction): this; /** Register an error callback. */ error(callback: CallableFunction): this; /** Public channels cannot scope whisper grants to authorized members. */ whisper(_eventName: string, _data: Record<any, any>): this; /** Warn when registering a whisper listener that cannot receive events. */ listenForWhisper(event: string, callback: CallableFunction): this; /** Dispatch an incoming event. */ dispatch(event: string, payload: unknown): void; /** Notify subscription callbacks. */ notifySubscribed(): void; /** Notify error callbacks. */ notifyError(error: unknown): void; }