Skip to content

Counter-announce to non-leader peers to speed up connectivity#164

Merged
dmotz merged 1 commit intodmotz:mainfrom
rogersanick:nickrogers/improve-connection-times
Apr 22, 2026
Merged

Counter-announce to non-leader peers to speed up connectivity#164
dmotz merged 1 commit intodmotz:mainfrom
rogersanick:nickrogers/improve-connection-times

Conversation

@rogersanick
Copy link
Copy Markdown
Contributor

@rogersanick rogersanick commented Apr 16, 2026

Faster discovery by counter-announcing

To prevent race conditions when exchanging WebRTC SDP offers, we compare peer IDs. The lower-ID peer always leads by creating the offer.

const shouldLeadOffer = selfId < peerId

...

if (!shouldLeadOffer && !announcePeerState.offerPeer) {
  return
}

This means that when a new lower ID peer joins and announces, the higher ID peer silently ignores. The new joining peer must then wait up to ~5.3 seconds for the higher ID peer's next re-announce before a negotiation for connectivity begins.

This change makes the higher ID peer immediately counter-announce to the lower ID peer's self topic, allowing the connection to begin right away.

Changes

  • packages/core/src/signal-handler.ts — In the !shouldLeadOffer branch, reply with {peerId: selfId} to the announcing peer's self topic instead of returning silently.
  • test/node/shared-room-peer-reuse.spec.ts — Two new test cases: higher-ID peer replies to lower-ID peer; lower-ID peer does not reply (it leads the offer instead).

@dmotz dmotz merged commit 2e817dc into dmotz:main Apr 22, 2026
@dmotz
Copy link
Copy Markdown
Owner

dmotz commented Apr 22, 2026

Thanks! Did some testing and saw this drop the connection time for peers coming later, which is something that's not measured in the existing tests. Will publish this in the next release.

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