recoder-shared
Version:
Shared types, utilities, and configurations for Recoder
91 lines • 2.85 kB
TypeScript
/**
* WebSocket Client for Recoder.xyz
* Handles real-time sync, collaboration, and notifications
*/
import { EventEmitter } from 'events';
import { AuthClient } from './auth-client';
export interface WebSocketConfig {
url: string;
authClient: AuthClient;
deviceId?: string;
platform?: string;
autoReconnect?: boolean;
reconnectInterval?: number;
maxReconnectAttempts?: number;
}
export interface SyncEvent {
dataType: string;
version: number;
changes?: any;
requestedBy?: {
deviceId: string;
platform: string;
};
updatedBy?: {
deviceId: string;
platform: string;
};
timestamp: string;
}
export interface CollaborationEvent {
userId: string;
userEmail?: string;
deviceId: string;
platform: string;
projectId?: string;
position?: any;
selection?: any;
edit?: any;
fileId?: string;
timestamp: string;
}
export interface NotificationEvent {
id: string;
type: 'info' | 'success' | 'warning' | 'error' | 'system';
title: string;
message: string;
data?: any;
channels?: string[];
timestamp: string;
}
export interface ActivityEvent {
deviceId: string;
platform: string;
status: 'active' | 'idle' | 'busy' | 'away';
timestamp: string;
}
export declare class WebSocketClient extends EventEmitter {
private socket;
private config;
private isConnected;
private isConnecting;
private reconnectAttempts;
private reconnectTimer;
private heartbeatInterval;
constructor(config: WebSocketConfig);
connect(): Promise<void>;
disconnect(): void;
requestSync(dataType: string, version: number): Promise<void>;
updateSync(dataType: string, version: number, changes: any): Promise<void>;
joinCollaboration(projectId: string): Promise<void>;
leaveCollaboration(projectId: string): Promise<void>;
sendCursorUpdate(projectId: string, position: any, selection?: any): Promise<void>;
sendEdit(projectId: string, edit: any, fileId: string): Promise<void>;
subscribeToChannels(channels: string[]): Promise<void>;
unsubscribeFromChannels(channels: string[]): Promise<void>;
updateStatus(status: 'active' | 'idle' | 'busy' | 'away'): Promise<void>;
notifyAIRequest(requestId: string, provider: string, prompt: string): Promise<void>;
notifyPlatformSwitch(fromPlatform: string, toPlatform: string, context?: any): Promise<void>;
private getSocketIOClient;
private setupEventHandlers;
private handleConnectionError;
private scheduleReconnect;
private stopReconnectTimer;
private startHeartbeat;
private stopHeartbeat;
get connected(): boolean;
get connecting(): boolean;
get reconnectCount(): number;
}
export default WebSocketClient;
//# sourceMappingURL=websocket-client.d.ts.map