Add some tests and improve docs

This commit is contained in:
Jack Kingsman
2026-02-27 16:54:18 -08:00
parent 60455cdd7b
commit 884972f9e0
9 changed files with 1109 additions and 39 deletions
+4 -4
View File
@@ -58,7 +58,7 @@ export function useWebSocket(options: UseWebSocketOptions) {
const ws = new WebSocket(wsUrl);
ws.onopen = () => {
console.log('WebSocket connected');
// Connection established (or re-established after disconnect)
if (reconnectTimeoutRef.current) {
clearTimeout(reconnectTimeoutRef.current);
reconnectTimeoutRef.current = null;
@@ -70,7 +70,7 @@ export function useWebSocket(options: UseWebSocketOptions) {
};
ws.onclose = () => {
console.log('WebSocket disconnected');
// Connection lost — will auto-reconnect after delay
wsRef.current = null;
if (!shouldReconnectRef.current) {
@@ -82,7 +82,7 @@ export function useWebSocket(options: UseWebSocketOptions) {
clearTimeout(reconnectTimeoutRef.current);
}
reconnectTimeoutRef.current = window.setTimeout(() => {
console.log('Attempting WebSocket reconnect...');
// Reconnect attempt after disconnect
connect();
}, 3000);
};
@@ -129,7 +129,7 @@ export function useWebSocket(options: UseWebSocketOptions) {
// Heartbeat response, ignore
break;
default:
console.log('Unknown WebSocket message type:', msg.type);
console.warn('Unknown WebSocket message type:', msg.type);
}
} catch (e) {
console.error('Failed to parse WebSocket message:', e);