-
Notifications
You must be signed in to change notification settings - Fork 0
fix: refine websocket service types #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors WebSocket and Telegram services by extracting them from lib utilities into dedicated service modules with React context providers, while improving type safety for WebSocket messages.
- Moved WebSocket and Telegram functionality from
lib/toservices/with React context providers - Enhanced WebSocket message types with strict
Tournamenttyping and union types - Improved reconnection handling by tracking attempts via
useRefinstead of closure variables
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
client/src/services/websocket.tsx |
New WebSocket service with context provider and improved type definitions |
client/src/services/telegram.tsx |
New Telegram service with context provider and error handling improvements |
client/src/pages/tournaments.tsx |
Updated to use new WebSocket service context |
client/src/pages/tournament-detail.tsx |
Updated to use new Telegram service context |
client/src/lib/websocket.ts |
Converted to re-export from services |
client/src/lib/telegram.ts |
Converted to re-export from services |
client/src/App.tsx |
Added service providers and removed direct initialization |
client/README.md |
Updated documentation for new service architecture |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
client/src/services/websocket.tsx
Outdated
| const reconnectTimeoutRef = useRef<number>(); | ||
| const websocketCallbacks = useRef<((message: any) => void)[]>([]); | ||
|
|
||
| const addCallback = (callback: (message: any) => void) => { |
Copilot
AI
Aug 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The callback parameter type any weakens type safety. This should match the type used in the websocketCallbacks ref for consistency.
| const addCallback = (callback: (message: any) => void) => { | |
| // Extend the message type to include system events | |
| export type WebSocketEvent = | |
| | WebSocketMessage | |
| | { type: 'connected' } | |
| | { type: 'error'; error: string }; | |
| function useWebSocket(onMessage?: (message: WebSocketMessage) => void) { | |
| const [isConnected, setIsConnected] = useState(false); | |
| const wsRef = useRef<WebSocket | null>(null); | |
| const reconnectTimeoutRef = useRef<number>(); | |
| const websocketCallbacks = useRef<((message: WebSocketEvent) => void)[]>([]); | |
| const addCallback = (callback: (message: WebSocketEvent) => void) => { |
| } | ||
| }); | ||
| useEffect(() => { | ||
| return addCallback((message: WebSocketMessage) => { |
Copilot
AI
Aug 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type mismatch: addCallback expects (message: any) => void but receives (message: WebSocketMessage) => void. The callback will receive internal WebSocket events like { type: 'connected' } which don't match the WebSocketMessage type.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Summary
Tournamentand strict event unionuseRefTesting
npm run type-checknpm run lint:checknpm testhttps://chatgpt.com/codex/tasks/task_e_689d085d8ccc8327bc09bfbcfab8927a