- 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>
44 lines
775 B
TypeScript
44 lines
775 B
TypeScript
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
|
|
}
|
|
}
|