Hard
Your team is building a real-time collaborative whiteboard. Complete the missing WebSocket logic:
1function useWhiteboardSync({ roomId }) {2 const [strokes, setStrokes] = useState([]);3 const [users, setUsers] = useState([]);4 const wsRef = useRef(null);5 const currentStroke = useRef(null);67 useEffect(() => {8 wsRef.current = new WebSocket(`wss://api.example.com/whiteboard/${roomId}`);910 // Missing connection logic here1112 return () => {13 if (currentStroke.current) {14 // Missing cleanup logic here15 }16 wsRef.current?.close();17 };18 }, [roomId]);1920 const startStroke = (point) => {21 currentStroke.current = {22 id: Date.now(),23 points: [point],24 userId: currentUser.id25 };26 // Missing broadcast logic here27 };2829 const updateStroke = (point) => {30 if (!currentStroke.current) return;31 // Missing update logic here32 };33}