Overview of the ProductFlo real-time communication architecture
WebSocketManager
utils/websocket_manager.py
// Connect to WebSocket with authentication const socket = new WebSocket('wss://api.productflo.io/ws/secure?access_token=YOUR_JWT_TOKEN'); // Join a product room after connection socket.onopen = () => { socket.send(JSON.stringify({ code: 'join', user_id: 'user-456', room_id: 'product-123', data: {} })); }; // Listen for product updates socket.onmessage = (event) => { const data = JSON.parse(event.data); if (data.code === 'file_update' && data.room_id === 'product-123') { console.log('Product file updated:', data.data.file_id); // Reload or update UI } };
// Request AI design feedback socket.send(JSON.stringify({ code: 'haitch_chat', user_id: 'user-456', room_id: 'design-123', data: { query: 'Review this PCB design and suggest improvements', doc_type: 'engineering_analysis', source_urls: ['https://path.to/pcb-456-design.pdf'] } })); // Process streaming response let fullResponse = ''; socket.onmessage = (event) => { const data = JSON.parse(event.data); // Handle streaming chunks (pending status) if (data.status === 'pending' && data.code === 'chat_response') { fullResponse += data.data.message || ''; updateUI(fullResponse); // Progressive rendering } // Handle final response (success status) if (data.status === 'success' && data.code === 'chat_response') { console.log('AI analysis complete:', data.data); finalizeUI(data.data.message); } };