From 0bce6307ae751ca21b5de1d872debc0adfd9b698 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Mon, 12 Feb 2024 18:24:26 +0100 Subject: [PATCH] [Node] Fix router.createWebRtcTransport() with listneIps - Fix a regression that produces empty candidates if `preferUdp === false` when using deprecated `listenIps` in `router.createWebRtcTransport()` instead of the new `listenInfos` since version 3.13.0. - Reported in https://mediasoup.discourse.group/t/produce-failed-after-upgrading-from-3-12-x-to-3-13-x/5838 --- node/src/Router.ts | 4 ++-- node/src/test/test-WebRtcTransport.ts | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/node/src/Router.ts b/node/src/Router.ts index 42732654be..7b87818bf7 100644 --- a/node/src/Router.ts +++ b/node/src/Router.ts @@ -507,13 +507,13 @@ export class Router< const orderedProtocols: TransportProtocol[] = []; - if (enableUdp && (!enableTcp || preferUdp)) { + if (enableUdp && (preferUdp || !enableTcp || !preferTcp)) { orderedProtocols.push('udp'); if (enableTcp) { orderedProtocols.push('tcp'); } - } else if (enableTcp && (!enableUdp || (preferTcp && !preferUdp))) { + } else if (enableTcp && ((preferTcp && !preferUdp) || !enableUdp)) { orderedProtocols.push('tcp'); if (enableUdp) { diff --git a/node/src/test/test-WebRtcTransport.ts b/node/src/test/test-WebRtcTransport.ts index 1e62a9dadb..72bfd48e4a 100644 --- a/node/src/test/test-WebRtcTransport.ts +++ b/node/src/test/test-WebRtcTransport.ts @@ -172,6 +172,31 @@ test('router.createWebRtcTransport() succeeds', async () => { expect(webRtcTransport.closed).toBe(true); }, 2000); +test('router.createWebRtcTransport() with deprecated listenIps succeeds', async () => { + const webRtcTransport = await ctx.router!.createWebRtcTransport({ + listenIps: [{ ip: '127.0.0.1', announcedIp: undefined }], + enableUdp: true, + enableTcp: true, + preferUdp: false, + initialAvailableOutgoingBitrate: 1000000, + }); + + expect(Array.isArray(webRtcTransport.iceCandidates)).toBe(true); + expect(webRtcTransport.iceCandidates.length).toBe(2); + + const iceCandidates = webRtcTransport.iceCandidates; + + expect(iceCandidates[0].ip).toBe('127.0.0.1'); + expect(iceCandidates[0].protocol).toBe('udp'); + expect(iceCandidates[0].type).toBe('host'); + expect(iceCandidates[0].tcpType).toBeUndefined(); + expect(iceCandidates[1].ip).toBe('127.0.0.1'); + expect(iceCandidates[1].protocol).toBe('tcp'); + expect(iceCandidates[1].type).toBe('host'); + expect(iceCandidates[1].tcpType).toBe('passive'); + expect(iceCandidates[0].priority).toBeGreaterThan(iceCandidates[1].priority); +}, 2000); + test('router.createWebRtcTransport() with wrong arguments rejects with TypeError', async () => { // @ts-ignore await expect(ctx.router!.createWebRtcTransport({})).rejects.toThrow(