Skip to content

Fixes ICE candidate issue#3

Merged
martian56 merged 1 commit intomainfrom
fix-con-issues
Nov 7, 2025
Merged

Fixes ICE candidate issue#3
martian56 merged 1 commit intomainfrom
fix-con-issues

Conversation

@martian56
Copy link
Owner

This pull request introduces several improvements and bug fixes to both the backend and frontend of the application, with a focus on configuration flexibility, WebRTC connection handling, and enhanced debugging. The main changes include improved environment variable management in the backend, more robust and debuggable WebRTC peer connection logic, and safer, more maintainable WebSocket handling in the frontend.

Backend Configuration Improvements:

  • Enhanced the Settings class in backend/config.py to use Pydantic's SettingsConfigDict for better environment variable management, including ignoring extra variables and supporting case insensitivity. Also added properties to handle CORS origins as both a string and a list, and updated the default application name. [1] [2]

WebRTC Debugging and Robustness:

  • Added detailed logging throughout the WebRTC connection process in frontend/src/hooks/useWebRTC.ts and frontend/src/pages/MeetingRoom.tsx, including when adding tracks, creating/reusing peer connections, and handling offers/answers/ICE candidates. Improved logic to avoid duplicate peer connections and offers, and added error handling for signaling state issues. [1] [2] [3] [4] [5] [6]

WebSocket Hook Enhancements:

  • Refactored the useWebSocket hook to use a ref for the onMessage callback, preventing unnecessary reconnections and stale closures. This makes the hook safer and easier to maintain. [1] [2] [3]

@martian56 martian56 requested a review from Copilot November 7, 2025 16:41
@martian56 martian56 self-assigned this Nov 7, 2025
@martian56 martian56 added enhancement New feature or request question Further information is requested labels Nov 7, 2025
@martian56 martian56 merged commit 8b83646 into main Nov 7, 2025
7 checks passed
Copy link

Copilot AI left a 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 enhances the WebRTC peer-to-peer connection reliability by improving connection initialization flow, adding comprehensive error handling, and updating the backend configuration to use Pydantic v2 patterns.

  • Refactored WebRTC connection establishment to prevent duplicate peer connections and race conditions
  • Added extensive logging throughout the WebSocket and WebRTC message flow for better debugging
  • Migrated backend configuration to Pydantic v2 with SettingsConfigDict

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
frontend/src/pages/MeetingRoom.tsx Enhanced WebSocket message handling with additional logging, duplicate connection checks, error handling for async operations, and a default case for unhandled message types
frontend/src/hooks/useWebSocket.ts Fixed dependency issues by using useRef pattern for the onMessage callback to prevent unnecessary WebSocket reconnections
frontend/src/hooks/useWebRTC.ts Improved offer handling to reuse existing peer connections, added signaling state validation, and comprehensive logging throughout the connection lifecycle
backend/config.py Updated to Pydantic v2 with SettingsConfigDict, converted CORS origins to property methods, and changed app_name from "VideoCall" to "LinkUp"

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

model_config = SettingsConfigDict(
env_file=".env",
case_sensitive=False,
extra="ignore" # Ignore extra environment variables like CORS_ORIGINS
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment suggests CORS_ORIGINS is an extra environment variable to be ignored, but it's actually being used by the cors_origins_str property method via os.getenv(). This comment is misleading since CORS_ORIGINS is a required configuration, not an extra variable to ignore.

Suggested change
extra="ignore" # Ignore extra environment variables like CORS_ORIGINS
extra="ignore" # Ignore extra environment variables not defined in the model

Copilot uses AI. Check for mistakes.
Comment on lines +54 to +61
console.log('Sending ICE candidate to:', clientId);
sendMessageRef.current({
type: WSMessageType.ICE_CANDIDATE,
target: clientId,
data: candidate.toJSON(),
});
} else {
console.warn('sendMessageRef is null, cannot send ICE candidate to:', clientId);
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excessive debug logging has been added throughout the WebRTC connection flow. While useful for development, this amount of console logging in production code can:

  1. Impact performance with frequent console operations
  2. Clutter production logs making it harder to find actual issues
  3. Potentially expose sensitive connection details in production logs

Consider either:

  • Using a proper logging library with configurable log levels
  • Wrapping these logs in a debug flag check
  • Removing non-critical logs before production deployment

Copilot uses AI. Check for mistakes.
Comment on lines +113 to +119
if (pc.signalingState === 'stable') {
// We can set it again
} else {
console.error('Cannot set remote description, signaling state:', pc.signalingState);
return null;
}
}
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The empty if block when pc.signalingState === 'stable' serves no purpose and reduces code clarity. If the condition is meant to allow fall-through to the try block below, consider removing the empty branch and inverting the logic:

if (pc.remoteDescription && pc.signalingState !== 'stable') {
  console.error('Cannot set remote description, signaling state:', pc.signalingState);
  return null;
}

This makes the intent clearer and eliminates the confusing empty block.

Copilot uses AI. Check for mistakes.
@martian56 martian56 added this to the MVP version milestone Nov 9, 2025
@martian56 martian56 moved this from Backlog to Done in LinkUp Project Nov 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request question Further information is requested

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants