Skip to content

Commit

Permalink
[flatbuffers] Fix missing options in router.createWebRtcTransport() (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ibc authored Oct 19, 2023
1 parent 5574b11 commit b706ae7
Show file tree
Hide file tree
Showing 14 changed files with 401 additions and 110 deletions.
23 changes: 20 additions & 3 deletions node/src/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,8 @@ export class Router<RouterAppData extends AppData = AppData>
listenInfos,
listenIps,
port,
enableUdp = true,
enableTcp = false,
enableUdp,
enableTcp,
preferUdp = false,
preferTcp = false,
initialAvailableOutgoingBitrate = 600000,
Expand Down Expand Up @@ -440,6 +440,19 @@ export class Router<RouterAppData extends AppData = AppData>
throw new TypeError('if given, appData must be an object');
}

// If webRtcServer is given, then do not force default values for enableUdp
// and enableTcp. Otherwise set them if unset.
if (webRtcServer)
{
enableUdp ??= true;
enableTcp ??= true;
}
else
{
enableUdp ??= true;
enableTcp ??= false;
}

// Convert deprecated TransportListenIps to TransportListenInfos.
if (listenIps)
{
Expand Down Expand Up @@ -545,7 +558,11 @@ export class Router<RouterAppData extends AppData = AppData>
webRtcServer ?
FbsWebRtcTransport.Listen.ListenServer :
FbsWebRtcTransport.Listen.ListenIndividual,
webRtcServer ? webRtcTransportListenServer : webRtcTransportListenIndividual
webRtcServer ? webRtcTransportListenServer : webRtcTransportListenIndividual,
enableUdp,
enableTcp,
preferUdp,
preferTcp
);

const requestOffset = new FbsRouter.CreateWebRtcTransportRequestT(
Expand Down
6 changes: 1 addition & 5 deletions node/src/WebRtcTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,21 @@ export type WebRtcTransportOptionsBase<WebRtcTransportAppData> =
{
/**
* Listen in UDP. Default true.
* @deprecated
*/
enableUdp?: boolean;

/**
* Listen in TCP. Default false.
* @deprecated
* Listen in TCP. Default true if webrtcServer is given, false otherwise.
*/
enableTcp?: boolean;

/**
* Prefer UDP. Default false.
* @deprecated
*/
preferUdp?: boolean;

/**
* Prefer TCP. Default false.
* @deprecated
*/
preferTcp?: boolean;

Expand Down
17 changes: 7 additions & 10 deletions node/src/tests/test-WebRtcServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,9 @@ test('router.createWebRtcTransport() with webRtcServer succeeds and transport is
const transport = await router.createWebRtcTransport(
{
webRtcServer,
appData : { foo: 'bar' }
// Let's disable UDP so resulting ICE candidates should only contain TCP.
enableUdp : false,
appData : { foo: 'bar' }
});

await expect(router.dump())
Expand All @@ -373,17 +375,12 @@ test('router.createWebRtcTransport() with webRtcServer succeeds and transport is

const iceCandidates = transport.iceCandidates;

expect(iceCandidates.length).toBe(2);
expect(iceCandidates.length).toBe(1);
expect(iceCandidates[0].ip).toBe('127.0.0.1');
expect(iceCandidates[0].port).toBe(port1);
expect(iceCandidates[0].protocol).toBe('udp');
expect(iceCandidates[0].port).toBe(port2);
expect(iceCandidates[0].protocol).toBe('tcp');
expect(iceCandidates[0].type).toBe('host');
expect(iceCandidates[0].tcpType).toBeUndefined();
expect(iceCandidates[1].ip).toBe('127.0.0.1');
expect(iceCandidates[1].port).toBe(port2);
expect(iceCandidates[1].protocol).toBe('tcp');
expect(iceCandidates[1].type).toBe('host');
expect(iceCandidates[1].tcpType).toBe('passive');
expect(iceCandidates[0].tcpType).toBe('passive');

expect(transport.iceState).toBe('new');
expect(transport.iceSelectedTuple).toBeUndefined();
Expand Down
Loading

0 comments on commit b706ae7

Please sign in to comment.