laravel-echo
Version:
Laravel Echo library for beautiful Pusher, Socket.IO, and Mercure integration
167 lines (166 loc) • 7.74 kB
TypeScript
import { MercureChannel, MercureEncryptedPrivateChannel, MercurePresenceChannel, MercurePrivateChannel } from "../channel";
import type { ConnectionStatus } from "../echo";
import { Connector } from "./connector";
type AnyMercureChannel = MercureChannel | MercurePrivateChannel | MercureEncryptedPrivateChannel | MercurePresenceChannel;
/** Mercure-specific connector options. */
export type MercureOptions = {
/** The hub URL, defaulting to the well-known path in browsers. */
host?: string | null;
/** The EventSource implementation, required when none exists globally. */
eventSource?: typeof EventSource;
};
/**
* Connects Echo to Mercure using one shared stream plus isolated whisper streams.
* Whisper channels are bound to exact topics because their envelopes are untrusted;
* client event payloads are peer-generated and must not be treated as server truth.
*/
export declare class MercureConnector extends Connector<"mercure", MercureChannel, MercurePrivateChannel, MercurePresenceChannel> {
/** Subscribed channels keyed by full name. */
channels: Record<string, AnyMercureChannel>;
/** Assigned by connect() during the base constructor before field initialization. */
private url;
/** The EventSource for the current topic set. */
private eventSource;
/** The last SSE id used to resume after reconnecting. */
private lastEventId;
/** Whisper streams keyed by guarded channel. */
private whisperEventSources;
/** Per-channel whisper replay cursors. */
private whisperLastEventIds;
/** Channels that have opened a whisper stream. */
private whisperListening;
/** Whether the server grants client events. */
private clientEventsEnabled;
/** The server-provided topic namespace. */
private topicPrefix;
/** Serializes outgoing whispers. */
private whisperQueue;
/** The local connection id used by toOthers(). */
private id;
/** The current connection status. */
private status;
/** Connection status listeners. */
private statusListeners;
/** Whether a connection refresh is running. */
private refreshing;
/** Whether another refresh is needed after the current one. */
private refreshPending;
/** The last authorized set, used to identify newcomers in rejected batches. */
private authorizedChannels;
/** Channels whose subscribed callbacks have fired. */
private subscribedNotified;
/** Presence channels with an initial snapshot. */
private seededPresenceChannels;
/** Presence events buffered until the initial snapshot arrives. */
private pendingSubscriptionEvents;
/** Decryption keys returned by the auth endpoint. */
private channelJwks;
/** Imported WebCrypto keys cached by channel. */
private importedKeys;
/** Serializes encrypted dispatches to preserve event order. */
private dispatchQueue;
/** Prevents an in-flight refresh from reconnecting after disconnect(). */
private epoch;
/** The exponential reconnect delay. */
private reconnectDelay;
/** The pending reconnect timer. */
private reconnectTimer;
/** The server-reported subscriber cookie lifetime. */
private tokenTtl;
/** When the subscriber cookie was last minted. */
private lastAuthAt;
/** Refreshes the httpOnly subscriber cookie before its reported expiry. */
private tokenRefreshTimer;
/** Runs from the base constructor and must not access subclass fields. */
connect(): void;
/** Get the configured EventSource implementation. */
private eventSourceClass;
/** Get the subscription API path for this hub. */
private subscriptionsPath;
/** Get the hub topic for a channel. */
private channelTopic;
/** Get the publishable whisper topic for a channel. */
private whisperTopic;
/** Map an exact hub topic back to its channel name. */
private channelNameFromTopic;
/** Listen for an event on a channel. */
listen(name: string, event: string, callback: CallableFunction): AnyMercureChannel;
/** Get a public channel. */
channel(name: string): MercureChannel;
/** Get a private channel. */
privateChannel(name: string): MercurePrivateChannel;
/** Get an encrypted private channel. */
encryptedPrivateChannel(name: string): MercureEncryptedPrivateChannel;
/** Get a presence channel. */
presenceChannel(name: string): MercurePresenceChannel;
/** Leave all variants of a channel. */
leave(name: string): void;
/** Leave a channel by its full name. */
leaveChannel(name: string): void;
/** Get the connection id. */
socketId(): string;
/** Queue a whisper for direct publication to the hub. */
whisper(name: string, event: string, data: unknown): void;
/** Open a whisper stream when the channel is authorized. */
listenForWhispers(name: string): void;
/** Publish a whisper, re-authenticating once after a 401 response. */
private publishWhisper;
/** Get the current connection status. */
connectionStatus(): ConnectionStatus;
/** Subscribe to connection status changes. */
onConnectionChange(callback: (status: ConnectionStatus) => void): () => void;
/** Disconnect from Mercure. */
disconnect(): void;
/** Update the connection status. */
private setStatus;
/** Forget all connector state for a channel. */
private forgetChannelState;
/** Evict channels and report the error to each one. */
private evict;
/** Notify every channel of an error. */
private notifyAllError;
/** Match guarded channels by the same prefixes used by the server. */
private guardedChannelNames;
/** Refresh the shared stream, coalescing concurrent requests. */
private refresh;
/** Run refresh work exclusively and retry failures with backoff. */
private runExclusive;
/** Refresh the subscriber cookie before its reported expiry. */
private scheduleTokenRefresh;
/** Schedule a full reconnect with exponential backoff. */
private scheduleReconnect;
private doRefresh;
/** Build a fresh hub subscription URL. */
private buildSubscribeUrl;
/** Close whisper streams while retaining replay cursors. */
private closeWhisperEventSources;
/** Reconcile lazy whisper streams without replacing healthy ones. */
private syncWhisperEventSources;
/** Open a channel's exact-topic whisper stream. */
private openWhisperEventSource;
/** Seed presence snapshots, then replay buffered live events. */
private seedPresenceChannels;
/** Dispatch a regular broadcast envelope to its channels. */
private handleMessage;
/** Dispatch only client events matching the trusted, stream-bound channel. */
private handleWhisperMessage;
/** Decrypt and dispatch an update only after authenticating it. */
private dispatchEncrypted;
/** Decrypt a compact direct-encryption A256GCM JWE using its protected header as AAD. */
private decrypt;
/** Encrypt a whisper as a compact direct-encryption A256GCM JWE. */
private encrypt;
/** Import and cache a channel's WebCrypto key. */
private channelKey;
/** Route exact subscription events with authorized member payloads. */
private handleSubscriptionEvent;
/** Fetch a presence snapshot after opening while live events are buffered. */
private fetchPresenceSnapshot;
/** Authenticate all joined channels in one request. */
private authenticate;
/** Record auth metadata and return individually denied channels. */
private readAuthResponse;
/** Build a presence channel's subscription-event matcher. */
private subscriptionEventsPattern;
}
export {};