@gitorial/sync
Version:
Universal sync library for real-time tutorial state synchronization between websites and VS Code extensions with built-in relay server orchestration
153 lines • 4.14 kB
TypeScript
import { EventEmitter } from 'events';
import { WebSocket } from 'ws';
import { IncomingMessage } from 'http';
import { SessionOrchestratorConfig, SessionOrchestratorEvents, CreateSessionOptions, SessionData } from './types/session';
/**
* Orchestrates relay sessions using focused components
* Acts as the main coordinator between SessionStore, SessionLifecycleManager, and ConnectionManager
*/
export declare class RelaySessionOrchestrator extends EventEmitter {
private readonly config;
private readonly sessionStore;
private readonly lifecycleManager;
private readonly connectionManager;
private pingTimer;
private isRunning;
constructor(config?: SessionOrchestratorConfig);
/**
* Start the orchestrator and all components
*/
start(): void;
/**
* Stop the orchestrator and all components
*/
stop(): void;
/**
* Create a new session
*/
createSession(options?: CreateSessionOptions): SessionData;
/**
* Get session information
*/
getSession(sessionId: string): SessionData | null;
/**
* List all active sessions
*/
listSessions(): SessionData[];
/**
* Delete a session and disconnect all clients
*/
deleteSession(sessionId: string): boolean;
/**
* Handle WebSocket upgrade for a session
*/
handleUpgrade(sessionId: string, socket: WebSocket, request: IncomingMessage): boolean;
/**
* Get orchestrator statistics
*/
getStats(): {
sessions: {
active: number;
total: number;
};
connections: {
totalConnections: number;
activeSessions: number;
connectionsPerSession: {
sessionId: string;
connectionCount: number;
}[];
};
lifecycle: {
isRunning: boolean;
lifecycleManagerActive: boolean;
};
};
/**
* Setup event forwarding between components
*/
private setupEventForwarding;
/**
* Setup WebSocket event handlers for a connection
*/
private setupWebSocketHandlers;
/**
* Handle incoming WebSocket message
*/
private handleWebSocketMessage;
/**
* Handle role-related messages
*/
private handleRoleMessage;
/**
* Handle control request messages
*/
private handleControlRequest;
/**
* Handle control offer messages
*/
private handleControlOffer;
/**
* Handle control accept messages
*/
private handleControlAccept;
/**
* Handle control decline messages
*/
private handleControlDecline;
/**
* Handle control release messages
*/
private handleControlRelease;
/**
* Handle sync direction coordination
*/
private handleSyncDirectionCoordination;
/**
* Assign sync direction to a connection
*/
private assignSyncDirection;
/**
* Assign sync direction to other clients in session
*/
private assignOtherClientsDirection;
/**
* Resolve control conflicts based on session configuration
*/
private resolveControlConflict;
/**
* Route message to other clients in the session
*/
private routeMessage;
/**
* Handle WebSocket close
*/
private handleWebSocketClose;
/**
* Handle WebSocket error
*/
private handleWebSocketError;
/**
* Start ping timer for health checks
*/
private startPingTimer;
/**
* Stop ping timer
*/
private stopPingTimer;
/**
* Ping all connected clients
*/
private pingClients;
/**
* Send message to a specific connection
*/
private sendToConnection;
/**
* Generate unique connection ID
*/
private generateConnectionId;
on<K extends keyof SessionOrchestratorEvents>(event: K, listener: SessionOrchestratorEvents[K]): this;
emit<K extends keyof SessionOrchestratorEvents>(event: K, ...args: Parameters<SessionOrchestratorEvents[K]>): boolean;
}
//# sourceMappingURL=RelaySessionOrchestrator.d.ts.map