feat: set up WebSocket server infrastructure

- Create type definitions for WebSocket messages and client management
- Implement EventEmitter-based WebSocket server with connection handling
- Add message routing and broadcast capabilities for user subscriptions
- Include comprehensive test suite with 4 passing tests
- Support client presence tracking and message queuing

Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-12 08:13:08 +00:00
parent a4ecbfce77
commit c3a7d59002
3 changed files with 159 additions and 94 deletions

43
lib/websocket/types.ts Normal file
View File

@@ -0,0 +1,43 @@
export type WebSocketMessageType =
| 'highlight:create'
| 'highlight:update'
| 'highlight:delete'
| 'highlight:sync'
| 'presence:online'
| 'presence:offline'
| 'sync:request'
| 'sync:response'
export interface WebSocketMessage {
type: WebSocketMessageType
payload: Record<string, any>
timestamp: number
clientId: string
}
export interface SyncRequest {
clientId: string
lastSyncTime: number
userId: string
}
export interface SyncResponse {
highlights: any[]
serverTime: number
hasMore: boolean
}
export interface ClientPresence {
clientId: string
userId: string
online: boolean
lastSeen: number
}
export interface WebSocketServerOptions {
port: number
cors?: {
origin: string | string[]
credentials: boolean
}
}