Create "working" example

This commit is contained in:
AlexanderHD27
2024-11-03 23:52:06 +01:00
parent 41a32b450c
commit f9ce4db95a
42 changed files with 2067 additions and 21 deletions

Binary file not shown.

View File

@@ -0,0 +1,114 @@
import { assertEquals } from "jsr:@std/assert";
import { IceCandidate, parseIceCandidate } from '../src/iceCandiate.ts';
const iceCandidates = [
"candidate:842163049 1 udp 1677729535 192.168.1.2 3478 typ host",
"candidate:842163049 2 udp 1677729534 192.168.1.3 3479 typ srflx raddr 192.168.1.2 rport 3478",
"candidate:842163049 1 tcp 1677729533 192.168.1.4 3480 typ relay raddr 192.168.1.3 rport 3479",
"candidate:842163049 2 tcp 1677729532 192.168.1.5 3481 typ host",
"candidate:842163049 1 udp 1677729531 192.168.1.6 3482 typ srflx rport 3480",
"candidate:842163049 2 udp 1677729530 192.168.1.7 3483 typ relay raddr 192.168.1.5",
"candidate:842163049 1 tcp 1677729529 192.168.1.8 3484 typ host",
"candidate:842163049 2 tcp 1677729528 192.168.1.9 3485 typ srflx raddr 192.168.1.6 rport 3482"
];
const parsedExamples: IceCandidate[] = [
{
foundation: "842163049",
componentId: 1,
transport: "udp",
priority: 1677729535,
ipAddress: "192.168.1.2",
port: 3478,
candidateType: "host",
relatedAddress: null,
relatedPort: null
},
{
foundation: "842163049",
componentId: 2,
transport: "udp",
priority: 1677729534,
ipAddress: "192.168.1.3",
port: 3479,
candidateType: "srflx",
relatedAddress: "192.168.1.2",
relatedPort: 3478
},
{
foundation: "842163049",
componentId: 1,
transport: "tcp",
priority: 1677729533,
ipAddress: "192.168.1.4",
port: 3480,
candidateType: "relay",
relatedAddress: "192.168.1.3",
relatedPort: 3479
},
{
foundation: "842163049",
componentId: 2,
transport: "tcp",
priority: 1677729532,
ipAddress: "192.168.1.5",
port: 3481,
candidateType: "host",
relatedAddress: null,
relatedPort: null
},
{
foundation: "842163049",
componentId: 1,
transport: "udp",
priority: 1677729531,
ipAddress: "192.168.1.6",
port: 3482,
candidateType: "srflx",
relatedPort: 3480,
relatedAddress: null
},
{
foundation: "842163049",
componentId: 2,
transport: "udp",
priority: 1677729530,
ipAddress: "192.168.1.7",
port: 3483,
candidateType: "relay",
relatedAddress: "192.168.1.5",
relatedPort: null
},
{
foundation: "842163049",
componentId: 1,
transport: "tcp",
priority: 1677729529,
ipAddress: "192.168.1.8",
port: 3484,
candidateType: "host",
relatedAddress: null,
relatedPort: null
},
{
foundation: "842163049",
componentId: 2,
transport: "tcp",
priority: 1677729528,
ipAddress: "192.168.1.9",
port: 3485,
candidateType: "srflx",
relatedAddress: "192.168.1.6",
relatedPort: 3482
}
];
Deno.test("parseIceCandidate should correctly parse ICE candidates", async (t) => {
for (const [index, candidate] of iceCandidates.entries()) {
await t.step(`${index}-${candidate}`, () => {
const parsed = parseIceCandidate(candidate);
console.log(candidate);
assertEquals(parsed, parsedExamples[index]);
})
}
});