From eb280e3826e29bad42528cad0d93267326da2406 Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Sat, 13 Dec 2025 15:19:45 +0100 Subject: [PATCH] Fix ICE candidate handling for Node.js compatibility Handle both browser and Node.js (wrtc) environments when processing ICE candidates. Browsers provide toJSON() method on candidates, but wrtc library candidates are already plain objects. Check for toJSON() existence before calling it. Fixes: TypeError: event.candidate.toJSON is not a function in Node.js --- src/rondevu.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/rondevu.ts b/src/rondevu.ts index 9e781e7..0511f99 100644 --- a/src/rondevu.ts +++ b/src/rondevu.ts @@ -365,10 +365,17 @@ export class Rondevu { pc.onicecandidate = async (event) => { if (event.candidate) { try { + // Handle both browser and Node.js (wrtc) environments + // Browser: candidate.toJSON() exists + // Node.js wrtc: candidate is already a plain object + const candidateData = typeof event.candidate.toJSON === 'function' + ? event.candidate.toJSON() + : event.candidate + await this.api.addOfferIceCandidates( serviceFqn, offerId, - [event.candidate.toJSON()] + [candidateData] ) } catch (err) { console.error('[Rondevu] Failed to send ICE candidate:', err)