Skip to content
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

Correct peerconnection states + proper cleanup peerconnection #165

Merged
merged 1 commit into from
Feb 9, 2025

Conversation

cedricve
Copy link
Member

@cedricve cedricve commented Feb 9, 2025

Description

Pull Request: Correct peerconnection states + proper cleanup peerconnection

Motivation

The primary motivation behind this pull request is to improve the robustness and reliability of the WebRTC peer connection handling within our project. By ensuring that the peer connection states are correctly managed and that resources are properly cleaned up, we can prevent potential memory leaks and improve the overall stability of the application.

Changes Made

  1. Corrected Peer Connection State Handling:

    • Replaced OnICEConnectionStateChange with OnConnectionStateChange to handle peer connection states more accurately.
    • Adjusted the handling of different peer connection states (Disconnected, Closed, Connected, Connecting, and Failed) to ensure appropriate actions are taken for each state.
  2. Proper Cleanup of Peer Connections:

    • Added logic to correctly manage and delete entries from the CandidateArrays map when the peer connection is closed or disconnected.
    • Ensured that locks (CandidatesMutex) are correctly used to prevent race conditions during state changes and cleanup.
    • Removed unnecessary channels (e.g., PacketsCount) that were not being used effectively.
  3. Improved Resource Management:

    • Ensured that the peerConnection.Close() method is called appropriately to release resources.
    • Added checks to avoid redundant operations when the peer connection is already in a connected state.

Benefits

  • Increased Stability: By correctly managing peer connection states and ensuring proper cleanup, we reduce the risk of memory leaks and other stability issues.
  • Improved Performance: Proper resource management ensures that the system does not hold onto unnecessary resources, improving overall performance.
  • Enhanced Reliability: Accurate handling of peer connection states ensures that the application behaves predictably under various network conditions.

Overall, these changes contribute to a more robust and maintainable WebRTC implementation in our project, enhancing the user experience and reliability of the application.

@cedricve cedricve merged commit 8c5b034 into master Feb 9, 2025
10 checks passed
@cedricve cedricve deleted the fix/iceconnection-state-event branch February 9, 2025 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant