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

[Node] Fix router.createWebRtcTransport() with listenIps #1330

Merged
merged 1 commit into from
Feb 12, 2024
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
4 changes: 2 additions & 2 deletions node/src/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
25 changes: 25 additions & 0 deletions node/src/test/test-WebRtcTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading