From 1bf21d7df8af86e77a89f1e8d12fa4aaac1950fe Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Wed, 10 Dec 2025 19:51:31 +0100 Subject: [PATCH] Include both offerer and answerer ICE candidates in polling endpoint - Add role and peerId to ICE candidate responses for matching - Offerers can now see their own candidates (for debugging/sync) - Answerers can poll same endpoint to get offerer candidates - Each candidate tagged with role ('offerer' or 'answerer') and peerId - Enables proper bidirectional ICE candidate exchange --- src/app.ts | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/app.ts b/src/app.ts index 1550d65..6328657 100644 --- a/src/app.ts +++ b/src/app.ts @@ -576,16 +576,35 @@ export function createApp(storage: Storage, config: Config) { // Get all peer's offers const allOffers = await storage.getOffersByPeerId(peerId); - // For each offer, get ICE candidates since timestamp + // For each offer, get ICE candidates from both sides const iceCandidatesByOffer: Record = {}; for (const offer of allOffers) { - // Get answerer ICE candidates (offerer polls for these) - const candidates = await storage.getIceCandidates(offer.id, 'answerer', sinceTimestamp); - if (candidates.length > 0) { - iceCandidatesByOffer[offer.id] = candidates.map(c => ({ + const allCandidates = []; + + // Get offerer ICE candidates (answerer polls for these, offerer can also see for debugging/sync) + const offererCandidates = await storage.getIceCandidates(offer.id, 'offerer', sinceTimestamp); + for (const c of offererCandidates) { + allCandidates.push({ candidate: c.candidate, + role: 'offerer', + peerId: c.peerId, createdAt: c.createdAt - })); + }); + } + + // Get answerer ICE candidates (offerer polls for these) + const answererCandidates = await storage.getIceCandidates(offer.id, 'answerer', sinceTimestamp); + for (const c of answererCandidates) { + allCandidates.push({ + candidate: c.candidate, + role: 'answerer', + peerId: c.peerId, + createdAt: c.createdAt + }); + } + + if (allCandidates.length > 0) { + iceCandidatesByOffer[offer.id] = allCandidates; } }