Skip to content

fix(p2p): queue tracks that arrive before P2P mode is established#2959

Open
MikCam wants to merge 1 commit intojitsi:masterfrom
MikCam:fix/p2p-track-queue
Open

fix(p2p): queue tracks that arrive before P2P mode is established#2959
MikCam wants to merge 1 commit intojitsi:masterfrom
MikCam:fix/p2p-track-queue

Conversation

@MikCam
Copy link

@MikCam MikCam commented Jan 5, 2026

Description

Fixes race condition where WebRTC ontrack events fire before P2P mode is fully established. When tracks arrive before _setP2PStatus(true) completes, they are now queued and processed once the P2P connection is ready.

Previously, tracks arriving during P2P establishment were ignored with "Trying to add remote P2P track, when not in P2P - IGNORED", causing tracks to never be added to the conference even after P2P was ready.

Changes:

  • Add pendingP2PTracks queue to buffer tracks before P2P is ready
  • Add _p2pTracksProcessed flag to prevent duplicate processing
  • Modify _setP2PStatus to process queued tracks when P2P established
  • Modify onRemoteTrackAdded to queue instead of ignoring early tracks
  • Add conditional check before _addRemoteP2PTracks to avoid duplicates
  • Clear queue when exiting P2P mode

Related Issue

Motivation and Context

How Has This Been Tested?

Screenshots or GIF (In case of UI changes):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • [] My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Fixes race condition where WebRTC ontrack events fire before P2P mode
is fully established. When tracks arrive before _setP2PStatus(true)
completes, they are now queued and processed once the P2P connection
is ready.

Previously, tracks arriving during P2P establishment were ignored with
"Trying to add remote P2P track, when not in P2P - IGNORED", causing
tracks to never be added to the conference even after P2P was ready.

Changes:
- Add pendingP2PTracks queue to buffer tracks before P2P is ready
- Add _p2pTracksProcessed flag to prevent duplicate processing
- Modify _setP2PStatus to process queued tracks when P2P established
- Modify onRemoteTrackAdded to queue instead of ignoring early tracks
- Add conditional check before _addRemoteP2PTracks to avoid duplicates
- Clear queue when exiting P2P mode
@jitsi-jenkins
Copy link

Hi, thanks for your contribution!
If you haven't already done so, could you please make sure you sign our CLA (https://jitsi.org/icla for individuals and https://jitsi.org/ccla for corporations)? We would unfortunately be unable to merge your patch unless we have that piece :(.

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.

2 participants