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:
43
lib/websocket/types.ts
Normal file
43
lib/websocket/types.ts
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user