UNPKG

@gitorial/sync

Version:

Universal sync library for real-time tutorial state synchronization between websites and VS Code extensions with built-in relay server orchestration

90 lines 3.21 kB
import { ConnectionManager } from '../connection/ConnectionManager'; import { TutorialSyncState, ClientRole, RoleTransferRequest } from '../types'; import { SyncDirectionAssignment } from '../types/messages'; export interface MessageDispatcherEvents { tutorialStateReceived: (state: TutorialSyncState) => void; controlRequested: (event: ControlRequestEvent) => void; controlOffered: (event: ControlOfferEvent) => void; controlAccepted: (fromClientId: string) => void; controlTransferConfirmed: () => void; syncDirectionAssigned: (assignment: SyncDirectionAssignment) => void; clientConnected: (clientId: string) => void; clientDisconnected: (clientId: string) => void; } export interface ControlRequestEvent { fromClientId: string; request: RoleTransferRequest; accept: () => void; decline: () => void; } export interface ControlOfferEvent { fromClientId: string; state: TutorialSyncState | null; accept: () => void; decline: () => void; } /** * Handles message routing and protocol communication */ export declare class MessageDispatcher { private connectionManager; private readonly eventEmitter; private clientId; private lastSynchronizedState; constructor(connectionManager: ConnectionManager, clientId: string); on(event: string, listener: (...args: any[]) => void): this; off(event: string, listener: (...args: any[]) => void): this; emit(event: string, ...args: any[]): boolean; once(event: string, listener: (...args: any[]) => void): this; removeAllListeners(event?: string): this; /** * Send tutorial state update - permission checking moved to RelayClient */ broadcastTutorialState(state: TutorialSyncState): void; /** * Request sync from peer - permission checking moved to RelayClient */ requestStateSync(): void; /** * Send control request */ sendControlRequest(request: RoleTransferRequest): void; /** * Offer role switch to other clients */ offerRoleSwitch(): void; /** * Send role change announcement */ announceRoleChange(role: ClientRole): void; /** * Send control release message */ releaseControl(): void; /** * Request sync direction coordination from server */ requestSyncDirectionCoordination(preferredDirection: 'ACTIVE' | 'PASSIVE', reason: string): void; private setupMessageHandling; private handleIncomingMessage; private handleStateUpdate; private handleSyncRequest; private handleControlRequest; private handleControlOffer; private handleControlAccept; private handleControlDecline; private handleControlRelease; private handleTransferConfirm; private handleRoleChanged; private handleClientConnected; private handleClientDisconnected; private handleServerError; private handleSyncDirectionAssignment; private acceptControlTransfer; private declineControlTransfer; private sendMessage; private generateStateChecksum; getCurrentState(): TutorialSyncState | null; updateCurrentState(state: TutorialSyncState): void; } //# sourceMappingURL=MessageDispatcher.d.ts.map