Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flatbuffers] Fix missing options in router.createWebRtcTransport() #1185

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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