UNPKG

sveltekit-sync

Version:
59 lines (58 loc) 1.68 kB
/** * SyncChannel - Channel-based API for real-time features * * Provides a composable API for presence tracking, custom events, * and channel-scoped communication. */ import type { RealtimeClient } from '../realtime/client.js'; import { PresenceStore } from './presence.svelte.js'; import type { User } from './presence.svelte.js'; export interface ChannelOptions { /** Enable presence tracking for this channel */ presence?: boolean; /** Enable custom event broadcasting */ broadcast?: boolean; } export interface ChannelOptionsResolved { presence: boolean; broadcast: boolean; } /** * Channel for scoped real-time communication */ export declare class SyncChannel { readonly name: string; readonly presence: PresenceStore | null; private realtimeClient; private options; private subscribed; private eventHandlers; constructor(realtimeClient: RealtimeClient, name: string, user?: User, options?: ChannelOptions); private unsubscribeEphemeral?; private setupEventListeners; /** * Subscribe to the channel */ subscribe(): Promise<void>; unsubscribe(): Promise<void>; /** * Track presence state (if presence is enabled) */ track<T>(state: T): void; /** * Stop tracking presence */ untrack(): void; /** * Listen for custom events on this channel */ on<T>(event: string, handler: (data: T) => void): () => void; /** * Broadcast a custom event to all subscribers of this channel */ broadcast<T>(event: string, data: T): Promise<void>; /** * Check if the channel is subscribed */ isSubscribed(): boolean; }