Implement Agent 6: Real-Time Updates feature for LocalGreenChain: - Add Socket.io server with room-based subscriptions - Create client-side hooks (useSocket, useLiveFeed, usePlantUpdates) - Add SocketProvider context for application-wide state - Implement UI components: - ConnectionStatus: Shows WebSocket connection state - LiveFeed: Real-time event feed display - NotificationToast: Toast notifications with auto-dismiss - LiveChart: Real-time data visualization - Add event type definitions and formatting utilities - Create socket API endpoint for WebSocket initialization - Add socket stats endpoint for monitoring - Extend tailwind with fadeIn/slideIn animations Integrates with existing EventStream SSE system for fallback.
92 lines
1.5 KiB
TypeScript
92 lines
1.5 KiB
TypeScript
/**
|
|
* Real-Time Module for LocalGreenChain
|
|
*
|
|
* Provides WebSocket-based real-time updates using Socket.io
|
|
* with automatic fallback to SSE.
|
|
*/
|
|
|
|
// Types
|
|
export type {
|
|
RoomType,
|
|
ConnectionStatus,
|
|
SocketAuthPayload,
|
|
SocketHandshake,
|
|
ClientToServerEvents,
|
|
ServerToClientEvents,
|
|
InterServerEvents,
|
|
SocketData,
|
|
RealtimeNotification,
|
|
ConnectionMetrics,
|
|
LiveFeedItem,
|
|
TransparencyEventType,
|
|
EventPriority,
|
|
TransparencyEvent,
|
|
} from './types';
|
|
|
|
// Events
|
|
export {
|
|
EventCategory,
|
|
RealtimeEvent,
|
|
EVENT_CATEGORIES,
|
|
EVENT_DISPLAY,
|
|
getEventCategory,
|
|
getEventDisplay,
|
|
formatEventDescription,
|
|
toFeedItem,
|
|
getEventsByCategory,
|
|
isEventInCategory,
|
|
priorityToNumber,
|
|
sortEvents,
|
|
} from './events';
|
|
|
|
// Rooms
|
|
export {
|
|
parseRoom,
|
|
createRoom,
|
|
getDefaultRooms,
|
|
getCategoryRoom,
|
|
getEventRooms,
|
|
isValidRoom,
|
|
canJoinRoom,
|
|
ROOM_LIMITS,
|
|
} from './rooms';
|
|
|
|
// Server
|
|
export {
|
|
RealtimeSocketServer,
|
|
getSocketServer,
|
|
} from './socketServer';
|
|
|
|
// Client
|
|
export {
|
|
RealtimeSocketClient,
|
|
getSocketClient,
|
|
createSocketClient,
|
|
} from './socketClient';
|
|
export type {
|
|
SocketClientConfig,
|
|
EventListener,
|
|
StatusListener,
|
|
ErrorListener,
|
|
} from './socketClient';
|
|
|
|
// React Hooks
|
|
export {
|
|
useSocket,
|
|
useLiveFeed,
|
|
usePlantUpdates,
|
|
useFarmUpdates,
|
|
useConnectionStatus,
|
|
useEventCount,
|
|
} from './useSocket';
|
|
export type {
|
|
UseSocketOptions,
|
|
UseSocketReturn,
|
|
} from './useSocket';
|
|
|
|
// React Context
|
|
export {
|
|
SocketProvider,
|
|
useSocketContext,
|
|
useOptionalSocketContext,
|
|
} from './SocketContext';
|