diff --git a/e2e/package.json b/e2e/package.json index 173db28d..c9609206 100644 --- a/e2e/package.json +++ b/e2e/package.json @@ -10,9 +10,9 @@ "dev": "npm run dev:chrome", "dev:chrome": "vitest ./tests", "dev:server": "DEBUG=werift* ts-node-dev --project tsconfig.server.json ./server/main.ts", - "format": "npx @biomejs/biome check --apply server tests", + "format": "biome check --apply server tests", "prod:server": "DEBUG=werift* node lib/e2e/server/main.js", - "prod:test": "vitest run ./tests --browser.headless && node stop.js", + "prod:test": "vitest run ./tests --browser.headless --reporter=basic && node stop.js", "server": "npm run dev:server", "test": "npm run prod:test", "type": "tsc --noEmit -p tsconfig.server.json && tsc --noEmit -p tsconfig.json" diff --git a/e2e/tests/bundle/max-compat.test.ts b/e2e/tests/bundle/max-compat.test.ts index d24bcfc1..67fe05ac 100644 --- a/e2e/tests/bundle/max-compat.test.ts +++ b/e2e/tests/bundle/max-compat.test.ts @@ -72,67 +72,63 @@ describe("bundle_max_compat", () => { 6000 * 1000, ); - it( - "bundle_max_compat_offer", - async () => - new Promise(async (done) => { - const label = "bundle_max_compat_offer"; + it("bundle_max_compat_offer", async () => + new Promise(async (done) => { + const label = "bundle_max_compat_offer"; - const counter = new Counter(3, () => { - pc.close(); - done(); - }); + const counter = new Counter(3, () => { + pc.close(); + done(); + }); - if (!peer.connected) await new Promise((r) => peer.on("open", r)); - await sleep(100); + if (!peer.connected) await new Promise((r) => peer.on("open", r)); + await sleep(100); - const pc = new RTCPeerConnection({ - iceServers: [{ urls: "stun:stun.l.google.com:19302" }], - bundlePolicy: "max-compat", - }); - pc.ontrack = async ({ track }) => { - await waitVideoPlay(track); - counter.done(); - }; - - const channel = pc.createDataChannel("dc"); - channel.onopen = () => { - channel.send("ping"); - }; - channel.onmessage = (e) => { - if (e.data === "pong") { - counter.done(); - } - }; + const pc = new RTCPeerConnection({ + iceServers: [{ urls: "stun:stun.l.google.com:19302" }], + bundlePolicy: "max-compat", + }); + pc.ontrack = async ({ track }) => { + await waitVideoPlay(track); + counter.done(); + }; - { - const [track] = ( - await navigator.mediaDevices.getUserMedia({ video: true }) - ).getTracks(); - pc.addTrack(track); - } - { - const [track] = ( - await navigator.mediaDevices.getUserMedia({ video: true }) - ).getTracks(); - pc.addTrack(track); + const channel = pc.createDataChannel("dc"); + channel.onopen = () => { + channel.send("ping"); + }; + channel.onmessage = (e) => { + if (e.data === "pong") { + counter.done(); } - pc.onicecandidate = ({ candidate }) => { - peer - .request(label, { - type: "candidate", - payload: candidate, - }) - .catch(() => {}); - }; + }; - await pc.setLocalDescription(await pc.createOffer()); - const answer = await peer.request(label, { - type: "init", - payload: pc.localDescription, - }); - await pc.setRemoteDescription(answer); - }), - 10 * 1000, - ); + { + const [track] = ( + await navigator.mediaDevices.getUserMedia({ video: true }) + ).getTracks(); + pc.addTrack(track); + } + { + const [track] = ( + await navigator.mediaDevices.getUserMedia({ video: true }) + ).getTracks(); + pc.addTrack(track); + } + pc.onicecandidate = ({ candidate }) => { + peer + .request(label, { + type: "candidate", + payload: candidate, + }) + .catch(() => {}); + }; + + await pc.setLocalDescription(await pc.createOffer()); + const answer = await peer.request(label, { + type: "init", + payload: pc.localDescription, + }); + await pc.setRemoteDescription(answer); + })); }); diff --git a/e2e/tests/combination/allmedia.test.ts b/e2e/tests/combination/allmedia.test.ts index 91dc02da..5e3f49aa 100644 --- a/e2e/tests/combination/allmedia.test.ts +++ b/e2e/tests/combination/allmedia.test.ts @@ -1,128 +1,120 @@ import { Counter, peer, sleep, waitVideoPlay } from "../fixture"; describe("combination_all_media", () => { - it( - "combination_all_media_answer", - async () => - new Promise(async (done) => { - const label = "combination_all_media_answer"; + it("combination_all_media_answer", async () => + new Promise(async (done) => { + const label = "combination_all_media_answer"; - const counter = new Counter(3, () => { - pc.close(); - done(); - }); + const counter = new Counter(3, () => { + pc.close(); + done(); + }); - if (!peer.connected) await new Promise((r) => peer.on("open", r)); - await sleep(100); + if (!peer.connected) await new Promise((r) => peer.on("open", r)); + await sleep(100); - const pc = new RTCPeerConnection({ - iceServers: [{ urls: "stun:stun.l.google.com:19302" }], - }); - pc.ontrack = async ({ track }) => { - await waitVideoPlay(track); - counter.done(); + const pc = new RTCPeerConnection({ + iceServers: [{ urls: "stun:stun.l.google.com:19302" }], + }); + pc.ontrack = async ({ track }) => { + await waitVideoPlay(track); + counter.done(); + }; + pc.ondatachannel = ({ channel }) => { + channel.onopen = () => { + channel.send("ping"); }; - pc.ondatachannel = ({ channel }) => { - channel.onopen = () => { - channel.send("ping"); - }; - channel.onmessage = (e) => { - if (e.data === "pong") { - counter.done(); - } - }; + channel.onmessage = (e) => { + if (e.data === "pong") { + counter.done(); + } }; + }; - { - const [track] = ( - await navigator.mediaDevices.getUserMedia({ video: true }) - ).getTracks(); - pc.addTrack(track); - } - { - const [track] = ( - await navigator.mediaDevices.getUserMedia({ video: true }) - ).getTracks(); - pc.addTrack(track); - } - - const offer = await peer.request(label, { - type: "init", - }); - await pc.setRemoteDescription(offer); - await pc.setLocalDescription(await pc.createAnswer()); + { + const [track] = ( + await navigator.mediaDevices.getUserMedia({ video: true }) + ).getTracks(); + pc.addTrack(track); + } + { + const [track] = ( + await navigator.mediaDevices.getUserMedia({ video: true }) + ).getTracks(); + pc.addTrack(track); + } - pc.onicecandidate = ({ candidate }) => { - peer - .request(label, { - type: "candidate", - payload: candidate, - }) - .catch(() => {}); - }; + const offer = await peer.request(label, { + type: "init", + }); + await pc.setRemoteDescription(offer); + await pc.setLocalDescription(await pc.createAnswer()); + pc.onicecandidate = ({ candidate }) => { peer .request(label, { - type: "answer", - payload: pc.localDescription, + type: "candidate", + payload: candidate, }) .catch(() => {}); - }), - 10 * 1000, - ); + }; - it( - "combination_all_media_offer", - async () => - new Promise(async (done) => { - const label = "combination_all_media_offer"; + peer + .request(label, { + type: "answer", + payload: pc.localDescription, + }) + .catch(() => {}); + })); - const counter = new Counter(2, () => { - pc.close(); - done(); - }); + it("combination_all_media_offer", async () => + new Promise(async (done) => { + const label = "combination_all_media_offer"; - if (!peer.connected) await new Promise((r) => peer.on("open", r)); - await sleep(100); + const counter = new Counter(2, () => { + pc.close(); + done(); + }); - const pc = new RTCPeerConnection({ - iceServers: [{ urls: "stun:stun.l.google.com:19302" }], - }); - pc.ontrack = async ({ track }) => { - await waitVideoPlay(track); - counter.done(); - }; + if (!peer.connected) await new Promise((r) => peer.on("open", r)); + await sleep(100); - const channel = pc.createDataChannel("dc"); - channel.onopen = () => { - channel.send("ping"); - }; - channel.onmessage = (e) => { - if (e.data === "pong") { - counter.done(); - } - }; + const pc = new RTCPeerConnection({ + iceServers: [{ urls: "stun:stun.l.google.com:19302" }], + }); + pc.ontrack = async ({ track }) => { + await waitVideoPlay(track); + counter.done(); + }; - const [track] = ( - await navigator.mediaDevices.getUserMedia({ video: true }) - ).getTracks(); - pc.addTrack(track); - pc.onicecandidate = ({ candidate }) => { - peer - .request(label, { - type: "candidate", - payload: candidate, - }) - .catch(() => {}); - }; + const channel = pc.createDataChannel("dc"); + channel.onopen = () => { + channel.send("ping"); + }; + channel.onmessage = (e) => { + if (e.data === "pong") { + counter.done(); + } + }; - await pc.setLocalDescription(await pc.createOffer()); - const answer = await peer.request(label, { - type: "init", - payload: pc.localDescription, - }); - await pc.setRemoteDescription(answer); - }), - 10 * 1000, - ); + const [track] = ( + await navigator.mediaDevices.getUserMedia({ video: true }) + ).getTracks(); + pc.addTrack(track); + pc.onicecandidate = ({ candidate }) => { + peer + .request(label, { + type: "candidate", + payload: candidate, + }) + .catch(() => {}); + }; + + await pc.setLocalDescription(await pc.createOffer()); + const answer = await peer.request(label, { + type: "init", + payload: pc.localDescription, + }); + await pc.setRemoteDescription(answer); + })); }); diff --git a/e2e/tests/datachannel/close.test.ts b/e2e/tests/datachannel/close.test.ts index 6ced4b1e..61068dd2 100644 --- a/e2e/tests/datachannel/close.test.ts +++ b/e2e/tests/datachannel/close.test.ts @@ -1,101 +1,93 @@ import { peer, sleep } from "../fixture"; describe("datachannel/close", () => { - it( - "datachannel_close_server_create_close", - async () => - new Promise(async (done) => { - const label = "datachannel_close_server_create_close"; - - if (!peer.connected) await new Promise((r) => peer.on("open", r)); - await sleep(100); - - const pc = new RTCPeerConnection({ - iceServers: [{ urls: "stun:stun.l.google.com:19302" }], - }); - const offer = await peer.request(label, { - type: "init", - }); - await pc.setRemoteDescription(offer); - await pc.setLocalDescription(await pc.createAnswer()); - - pc.ondatachannel = ({ channel }) => { - channel.onclose = () => { - pc.close(); - done(); - }; - channel.send("ping"); - }; - - pc.onicecandidate = ({ candidate }) => { - peer - .request(label, { - type: "candidate", - payload: candidate, - }) - .catch(() => {}); + it("datachannel_close_server_create_close", async () => + new Promise(async (done) => { + const label = "datachannel_close_server_create_close"; + + if (!peer.connected) await new Promise((r) => peer.on("open", r)); + await sleep(100); + + const pc = new RTCPeerConnection({ + iceServers: [{ urls: "stun:stun.l.google.com:19302" }], + }); + const offer = await peer.request(label, { + type: "init", + }); + await pc.setRemoteDescription(offer); + await pc.setLocalDescription(await pc.createAnswer()); + + pc.ondatachannel = ({ channel }) => { + channel.onclose = () => { + pc.close(); + done(); }; + channel.send("ping"); + }; + pc.onicecandidate = ({ candidate }) => { peer .request(label, { - type: "answer", - payload: pc.localDescription, + type: "candidate", + payload: candidate, }) .catch(() => {}); - }), - 10 * 1000, - ); - - it( - "datachannel_close_server_create_client_close", - async () => - new Promise(async (done) => { - const label = "datachannel_close_server_create_client_close"; - - if (!peer.connected) await new Promise((r) => peer.on("open", r)); - await sleep(100); + }; - const pc = new RTCPeerConnection({ - iceServers: [{ urls: "stun:stun.l.google.com:19302" }], - }); - pc.onicecandidate = ({ candidate }) => { - peer - .request(label, { - type: "candidate", - payload: candidate, - }) - .catch(() => {}); - }; + peer + .request(label, { + type: "answer", + payload: pc.localDescription, + }) + .catch(() => {}); + })); - const offer = await peer.request(label, { - type: "init", - }); - await pc.setRemoteDescription(offer); - await pc.setLocalDescription(await pc.createAnswer()); + it("datachannel_close_server_create_client_close", async () => + new Promise(async (done) => { + const label = "datachannel_close_server_create_client_close"; - pc.ondatachannel = ({ channel }) => { - channel.onmessage = () => { - Promise.all([ - peer.request(label, { type: "done" }), - new Promise((r) => { - channel.onclose = () => { - r(); - }; - setTimeout(() => channel.close(), 500); - }), - ]).then(() => done()); - }; - }; + if (!peer.connected) await new Promise((r) => peer.on("open", r)); + await sleep(100); + const pc = new RTCPeerConnection({ + iceServers: [{ urls: "stun:stun.l.google.com:19302" }], + }); + pc.onicecandidate = ({ candidate }) => { peer .request(label, { - type: "answer", - payload: pc.localDescription, + type: "candidate", + payload: candidate, }) .catch(() => {}); - }), - 10 * 1000, - ); + }; + + const offer = await peer.request(label, { + type: "init", + }); + await pc.setRemoteDescription(offer); + await pc.setLocalDescription(await pc.createAnswer()); + + pc.ondatachannel = ({ channel }) => { + channel.onmessage = () => { + Promise.all([ + peer.request(label, { type: "done" }), + new Promise((r) => { + channel.onclose = () => { + r(); + }; + setTimeout(() => channel.close(), 500); + }), + ]).then(() => done()); + }; + }; + + peer + .request(label, { + type: "answer", + payload: pc.localDescription, + }) + .catch(() => {}); + })); it( "datachannel_close_client_create_close", @@ -146,40 +138,36 @@ describe("datachannel/close", () => { 30 * 1000, ); - it( - "datachannel_close_client_create_server_close", - async () => - new Promise(async (done) => { - const label = "datachannel_close_client_create_server_close"; - if (!peer.connected) await new Promise((r) => peer.on("open", r)); - await sleep(100); + it("datachannel_close_client_create_server_close", async () => + new Promise(async (done) => { + const label = "datachannel_close_client_create_server_close"; + if (!peer.connected) await new Promise((r) => peer.on("open", r)); + await sleep(100); - const pc = new RTCPeerConnection({ - iceServers: [{ urls: "stun:stun.l.google.com:19302" }], - }); - pc.onicecandidate = ({ candidate }) => { - peer - .request(label, { - type: "candidate", - payload: candidate, - }) - .catch(() => {}); - }; - const channel = pc.createDataChannel("dc"); - channel.onopen = () => { - channel.send("hello"); - }; - channel.onclose = () => { - done(); - }; - - await pc.setLocalDescription(await pc.createOffer()); - const answer = await peer.request(label, { - type: "init", - payload: pc.localDescription, - }); - pc.setRemoteDescription(answer); - }), - 10 * 1000, - ); + const pc = new RTCPeerConnection({ + iceServers: [{ urls: "stun:stun.l.google.com:19302" }], + }); + pc.onicecandidate = ({ candidate }) => { + peer + .request(label, { + type: "candidate", + payload: candidate, + }) + .catch(() => {}); + }; + const channel = pc.createDataChannel("dc"); + channel.onopen = () => { + channel.send("hello"); + }; + channel.onclose = () => { + done(); + }; + + await pc.setLocalDescription(await pc.createOffer()); + const answer = await peer.request(label, { + type: "init", + payload: pc.localDescription, + }); + pc.setRemoteDescription(answer); + })); }); diff --git a/e2e/tests/datachannel/datachannel.test.ts b/e2e/tests/datachannel/datachannel.test.ts index e9103eeb..e6e438ce 100644 --- a/e2e/tests/datachannel/datachannel.test.ts +++ b/e2e/tests/datachannel/datachannel.test.ts @@ -1,84 +1,76 @@ import { peer, sleep } from "../fixture"; describe("datachannel", () => { - it( - "answer", - async () => - new Promise(async (done) => { - if (!peer.connected) await new Promise((r) => peer.on("open", r)); - await sleep(100); + it("answer", async () => + new Promise(async (done) => { + if (!peer.connected) await new Promise((r) => peer.on("open", r)); + await sleep(100); - const pc = new RTCPeerConnection({ - iceServers: [{ urls: "stun:stun.l.google.com:19302" }], - }); - const offer = await peer.request("datachannel_answer", { - type: "init", - }); - await pc.setRemoteDescription(offer); - await pc.setLocalDescription(await pc.createAnswer()); + const pc = new RTCPeerConnection({ + iceServers: [{ urls: "stun:stun.l.google.com:19302" }], + }); + const offer = await peer.request("datachannel_answer", { + type: "init", + }); + await pc.setRemoteDescription(offer); + await pc.setLocalDescription(await pc.createAnswer()); - pc.ondatachannel = ({ channel }) => { - channel.onmessage = ({ data }) => { - expect(data).toBe("ping" + "pong"); - pc.close(); - done(); - }; - channel.send("ping"); - }; - - pc.onicecandidate = ({ candidate }) => { - peer - .request("datachannel_answer", { - type: "candidate", - payload: candidate, - }) - .catch(() => {}); + pc.ondatachannel = ({ channel }) => { + channel.onmessage = ({ data }) => { + expect(data).toBe("ping" + "pong"); + pc.close(); + done(); }; + channel.send("ping"); + }; + pc.onicecandidate = ({ candidate }) => { peer .request("datachannel_answer", { - type: "answer", - payload: pc.localDescription, + type: "candidate", + payload: candidate, }) .catch(() => {}); - }), - 10 * 1000, - ); + }; - it( - "offer", - async () => - new Promise(async (done) => { - if (!peer.connected) await new Promise((r) => peer.on("open", r)); - await sleep(100); + peer + .request("datachannel_answer", { + type: "answer", + payload: pc.localDescription, + }) + .catch(() => {}); + })); - const pc = new RTCPeerConnection({ - iceServers: [{ urls: "stun:stun.l.google.com:19302" }], - }); - const channel = pc.createDataChannel("dc"); - channel.onopen = () => { - channel.send("ping"); - }; - channel.onmessage = ({ data }) => { - expect(data).toBe("ping" + "pong"); - done(); - }; - pc.onicecandidate = ({ candidate }) => { - peer - .request("datachannel_offer", { - type: "candidate", - payload: candidate, - }) - .catch(() => {}); - }; + it("offer", async () => + new Promise(async (done) => { + if (!peer.connected) await new Promise((r) => peer.on("open", r)); + await sleep(100); - await pc.setLocalDescription(await pc.createOffer()); - const answer = await peer.request("datachannel_offer", { - type: "init", - payload: pc.localDescription, - }); - await pc.setRemoteDescription(answer); - }), - 10 * 1000, - ); + const pc = new RTCPeerConnection({ + iceServers: [{ urls: "stun:stun.l.google.com:19302" }], + }); + const channel = pc.createDataChannel("dc"); + channel.onopen = () => { + channel.send("ping"); + }; + channel.onmessage = ({ data }) => { + expect(data).toBe("ping" + "pong"); + done(); + }; + pc.onicecandidate = ({ candidate }) => { + peer + .request("datachannel_offer", { + type: "candidate", + payload: candidate, + }) + .catch(() => {}); + }; + + await pc.setLocalDescription(await pc.createOffer()); + const answer = await peer.request("datachannel_offer", { + type: "init", + payload: pc.localDescription, + }); + await pc.setRemoteDescription(answer); + })); }); diff --git a/e2e/tests/fixture.ts b/e2e/tests/fixture.ts index 42970d7a..58b09bd1 100644 --- a/e2e/tests/fixture.ts +++ b/e2e/tests/fixture.ts @@ -46,7 +46,10 @@ export const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms)); export class Counter { private now = 0; - constructor(private times: number, private finished: () => void) {} + constructor( + private times: number, + private finished: () => void, + ) {} done() { if (++this.now === this.times) { diff --git a/e2e/tests/ice/trickle.test.ts b/e2e/tests/ice/trickle.test.ts index b3ef4399..753ed2f6 100644 --- a/e2e/tests/ice/trickle.test.ts +++ b/e2e/tests/ice/trickle.test.ts @@ -1,105 +1,97 @@ import { peer, sleep, waitVideoPlay } from "../fixture"; describe("ice/trickle", () => { - it( - "answer", - async () => - new Promise(async (done) => { - const label = "ice_trickle_answer"; + it("answer", async () => + new Promise(async (done) => { + const label = "ice_trickle_answer"; - if (!peer.connected) await new Promise((r) => peer.on("open", r)); - await sleep(100); + if (!peer.connected) await new Promise((r) => peer.on("open", r)); + await sleep(100); - const pc = new RTCPeerConnection({ - iceServers: [{ urls: "stun:stun.l.google.com:19302" }], - }); - pc.ondatachannel = ({ channel }) => { - channel.onmessage = ({ data }) => { - expect(data).toBe("ping" + "pong"); - pc.close(); - done(); - }; - channel.send("ping"); - }; - pc.ontrack = (ev) => { - waitVideoPlay(ev.track); - }; - pc.onicecandidate = ({ candidate }) => { - if (candidate) { - peer - .request(label, { - type: "candidate", - payload: candidate, - }) - .catch(() => {}); - } - }; - peer.on("request", async (request, accept) => { - if (request.method !== label) return; - const candidate = request.data; - await pc.addIceCandidate(candidate); - accept(); - }); - - const offer = await peer.request(label, { - type: "init", - }); - await pc.setRemoteDescription(offer); - await pc.setLocalDescription(await pc.createAnswer()); - - peer - .request(label, { - type: "answer", - payload: pc.localDescription, - }) - .catch(() => {}); - }), - 10 * 1000, - ); - - it( - "offer", - async () => - new Promise(async (done) => { - const label = "ice_trickle_offer"; - - if (!peer.connected) await new Promise((r) => peer.on("open", r)); - await sleep(100); - - const pc = new RTCPeerConnection({ - iceServers: [{ urls: "stun:stun.l.google.com:19302" }], - }); - const channel = pc.createDataChannel("dc"); - channel.onopen = () => { - channel.send("ping"); - }; + const pc = new RTCPeerConnection({ + iceServers: [{ urls: "stun:stun.l.google.com:19302" }], + }); + pc.ondatachannel = ({ channel }) => { channel.onmessage = ({ data }) => { expect(data).toBe("ping" + "pong"); pc.close(); done(); }; - pc.onicecandidate = ({ candidate }) => { + channel.send("ping"); + }; + pc.ontrack = (ev) => { + waitVideoPlay(ev.track); + }; + pc.onicecandidate = ({ candidate }) => { + if (candidate) { peer .request(label, { type: "candidate", payload: candidate, }) .catch(() => {}); - }; - peer.on("request", async (request, accept) => { - if (request.method !== label) return; - const candidate = request.data; - await pc.addIceCandidate(candidate); - accept(); - }); + } + }; + peer.on("request", async (request, accept) => { + if (request.method !== label) return; + const candidate = request.data; + await pc.addIceCandidate(candidate); + accept(); + }); + + const offer = await peer.request(label, { + type: "init", + }); + await pc.setRemoteDescription(offer); + await pc.setLocalDescription(await pc.createAnswer()); - await pc.setLocalDescription(await pc.createOffer()); - const answer = await peer.request(label, { - type: "init", + peer + .request(label, { + type: "answer", payload: pc.localDescription, - }); - await pc.setRemoteDescription(answer); - }), - 10 * 1000, - ); + }) + .catch(() => {}); + })); + + it("offer", async () => + new Promise(async (done) => { + const label = "ice_trickle_offer"; + + if (!peer.connected) await new Promise((r) => peer.on("open", r)); + await sleep(100); + + const pc = new RTCPeerConnection({ + iceServers: [{ urls: "stun:stun.l.google.com:19302" }], + }); + const channel = pc.createDataChannel("dc"); + channel.onopen = () => { + channel.send("ping"); + }; + channel.onmessage = ({ data }) => { + expect(data).toBe("ping" + "pong"); + pc.close(); + done(); + }; + pc.onicecandidate = ({ candidate }) => { + peer + .request(label, { + type: "candidate", + payload: candidate, + }) + .catch(() => {}); + }; + peer.on("request", async (request, accept) => { + if (request.method !== label) return; + const candidate = request.data; + await pc.addIceCandidate(candidate); + accept(); + }); + + await pc.setLocalDescription(await pc.createOffer()); + const answer = await peer.request(label, { + type: "init", + payload: pc.localDescription, + }); + await pc.setRemoteDescription(answer); + })); }); diff --git a/e2e/tests/mediachannel/addTrack.test.ts b/e2e/tests/mediachannel/addTrack.test.ts index dd64ed10..1277fdf8 100644 --- a/e2e/tests/mediachannel/addTrack.test.ts +++ b/e2e/tests/mediachannel/addTrack.test.ts @@ -1,90 +1,82 @@ import { peer, sleep, waitVideoPlay } from "../fixture"; describe("mediachannel_addTrack", () => { - it( - "mediachannel_addTrack_answer", - async () => - new Promise(async (done) => { - if (!peer.connected) await new Promise((r) => peer.on("open", r)); - await sleep(100); + it("mediachannel_addTrack_answer", async () => + new Promise(async (done) => { + if (!peer.connected) await new Promise((r) => peer.on("open", r)); + await sleep(100); - const offer = await peer.request("mediachannel_addTrack_answer", { - type: "init", - }); - - const pc = new RTCPeerConnection({ - iceServers: [{ urls: "stun:stun.l.google.com:19302" }], - }); - pc.onicecandidate = ({ candidate }) => { - peer - .request("mediachannel_addTrack_answer", { - type: "candidate", - payload: candidate, - }) - .catch(() => {}); - }; - pc.ontrack = async ({ track }) => { - await waitVideoPlay(track); - await peer.request("mediachannel_addTrack_answer", { - type: "done", - }); - pc.close(); - done(); - }; - - await pc.setRemoteDescription(offer); - await pc.setLocalDescription(await pc.createAnswer()); + const offer = await peer.request("mediachannel_addTrack_answer", { + type: "init", + }); + const pc = new RTCPeerConnection({ + iceServers: [{ urls: "stun:stun.l.google.com:19302" }], + }); + pc.onicecandidate = ({ candidate }) => { peer .request("mediachannel_addTrack_answer", { - type: "answer", - payload: pc.localDescription, + type: "candidate", + payload: candidate, }) .catch(() => {}); - }), - 10 * 1000, - ); + }; + pc.ontrack = async ({ track }) => { + await waitVideoPlay(track); + await peer.request("mediachannel_addTrack_answer", { + type: "done", + }); + pc.close(); + done(); + }; - it( - "mediachannel_addTrack_offer", - async () => - new Promise(async (done) => { - if (!peer.connected) await new Promise((r) => peer.on("open", r)); - await sleep(100); + await pc.setRemoteDescription(offer); + await pc.setLocalDescription(await pc.createAnswer()); - await peer.request("mediachannel_addTrack_offer", { - type: "init", - }); + peer + .request("mediachannel_addTrack_answer", { + type: "answer", + payload: pc.localDescription, + }) + .catch(() => {}); + })); - const pc = new RTCPeerConnection({ - iceServers: [{ urls: "stun:stun.l.google.com:19302" }], - }); - pc.ontrack = async ({ track }) => { - await waitVideoPlay(track); - await peer.request("mediachannel_addTrack_offer", { - type: "done", - }); - pc.close(); - done(); - }; - pc.onicecandidate = ({ candidate }) => { - peer - .request("mediachannel_addTrack_offer", { - type: "candidate", - payload: candidate, - }) - .catch(() => {}); - }; + it("mediachannel_addTrack_offer", async () => + new Promise(async (done) => { + if (!peer.connected) await new Promise((r) => peer.on("open", r)); + await sleep(100); - pc.addTransceiver("video", { direction: "recvonly" }); + await peer.request("mediachannel_addTrack_offer", { + type: "init", + }); - await pc.setLocalDescription(await pc.createOffer()); - const answer = await peer.request("mediachannel_addTrack_offer", { - type: "offer", - payload: pc.localDescription, + const pc = new RTCPeerConnection({ + iceServers: [{ urls: "stun:stun.l.google.com:19302" }], + }); + pc.ontrack = async ({ track }) => { + await waitVideoPlay(track); + await peer.request("mediachannel_addTrack_offer", { + type: "done", }); - await pc.setRemoteDescription(answer); - }), - 10 * 1000, - ); + pc.close(); + done(); + }; + pc.onicecandidate = ({ candidate }) => { + peer + .request("mediachannel_addTrack_offer", { + type: "candidate", + payload: candidate, + }) + .catch(() => {}); + }; + + pc.addTransceiver("video", { direction: "recvonly" }); + + await pc.setLocalDescription(await pc.createOffer()); + const answer = await peer.request("mediachannel_addTrack_offer", { + type: "offer", + payload: pc.localDescription, + }); + await pc.setRemoteDescription(answer); + })); }); diff --git a/e2e/tests/mediachannel/oneway.test.ts b/e2e/tests/mediachannel/oneway.test.ts index b3844893..42760c7a 100644 --- a/e2e/tests/mediachannel/oneway.test.ts +++ b/e2e/tests/mediachannel/oneway.test.ts @@ -1,89 +1,81 @@ import { peer, sleep, waitVideoPlay } from "../fixture"; describe("mediachannel_oneway", () => { - it( - "answer", - async () => - new Promise(async (done) => { - if (!peer.connected) await new Promise((r) => peer.on("open", r)); - await sleep(100); + it("answer", async () => + new Promise(async (done) => { + if (!peer.connected) await new Promise((r) => peer.on("open", r)); + await sleep(100); - const pc = new RTCPeerConnection({ - iceServers: [{ urls: "stun:stun.l.google.com:19302" }], - }); - pc.ontrack = async ({ track }) => { - await waitVideoPlay(track); - pc.close(); - done(); - }; + const pc = new RTCPeerConnection({ + iceServers: [{ urls: "stun:stun.l.google.com:19302" }], + }); + pc.ontrack = async ({ track }) => { + await waitVideoPlay(track); + pc.close(); + done(); + }; - const [track] = ( - await navigator.mediaDevices.getUserMedia({ video: true }) - ).getTracks(); - pc.addTrack(track); + const [track] = ( + await navigator.mediaDevices.getUserMedia({ video: true }) + ).getTracks(); + pc.addTrack(track); - const offer = await peer.request("mediachannel_oneway_answer", { - type: "init", - }); - await pc.setRemoteDescription(offer); - await pc.setLocalDescription(await pc.createAnswer()); - - pc.onicecandidate = ({ candidate }) => { - peer - .request("mediachannel_oneway_answer", { - type: "candidate", - payload: candidate, - }) - .catch(() => {}); - }; + const offer = await peer.request("mediachannel_oneway_answer", { + type: "init", + }); + await pc.setRemoteDescription(offer); + await pc.setLocalDescription(await pc.createAnswer()); + pc.onicecandidate = ({ candidate }) => { peer .request("mediachannel_oneway_answer", { - type: "answer", - payload: pc.localDescription, + type: "candidate", + payload: candidate, }) .catch(() => {}); - }), - 10 * 1000, - ); + }; - it( - "offer", - async () => - new Promise(async (done) => { - if (!peer.connected) await new Promise((r) => peer.on("open", r)); - await sleep(100); + peer + .request("mediachannel_oneway_answer", { + type: "answer", + payload: pc.localDescription, + }) + .catch(() => {}); + })); - const pc = new RTCPeerConnection({ - iceServers: [{ urls: "stun:stun.l.google.com:19302" }], - }); - pc.ontrack = async ({ track }) => { - await waitVideoPlay(track); - pc.close(); - done(); - }; - pc.onicecandidate = ({ candidate }) => { - peer - .request("mediachannel_oneway_offer", { - type: "candidate", - payload: candidate, - }) - .catch(() => {}); - }; + it("offer", async () => + new Promise(async (done) => { + if (!peer.connected) await new Promise((r) => peer.on("open", r)); + await sleep(100); - const [track] = ( - await navigator.mediaDevices.getUserMedia({ video: true }) - ).getTracks(); - pc.addTransceiver(track, { direction: "sendonly" }); - pc.addTransceiver("video", { direction: "recvonly" }); + const pc = new RTCPeerConnection({ + iceServers: [{ urls: "stun:stun.l.google.com:19302" }], + }); + pc.ontrack = async ({ track }) => { + await waitVideoPlay(track); + pc.close(); + done(); + }; + pc.onicecandidate = ({ candidate }) => { + peer + .request("mediachannel_oneway_offer", { + type: "candidate", + payload: candidate, + }) + .catch(() => {}); + }; - await pc.setLocalDescription(await pc.createOffer()); - const answer = await peer.request("mediachannel_oneway_offer", { - type: "init", - payload: pc.localDescription, - }); - await pc.setRemoteDescription(answer); - }), - 10 * 1000, - ); + const [track] = ( + await navigator.mediaDevices.getUserMedia({ video: true }) + ).getTracks(); + pc.addTransceiver(track, { direction: "sendonly" }); + pc.addTransceiver("video", { direction: "recvonly" }); + + await pc.setLocalDescription(await pc.createOffer()); + const answer = await peer.request("mediachannel_oneway_offer", { + type: "init", + payload: pc.localDescription, + }); + await pc.setRemoteDescription(answer); + })); }); diff --git a/e2e/tests/mediachannel/red.test.ts b/e2e/tests/mediachannel/red.test.ts index ef44302e..dee018df 100644 --- a/e2e/tests/mediachannel/red.test.ts +++ b/e2e/tests/mediachannel/red.test.ts @@ -76,7 +76,6 @@ describe("mediachannel_red", () => { }) .catch(() => {}); }), - 10 * 1000, ); const mediachannel_red_client_offer = "mediachannel_red_client_offer"; @@ -127,6 +126,5 @@ describe("mediachannel_red", () => { }); await pc.setRemoteDescription(answer); }), - 10 * 1000, ); }); diff --git a/e2e/tests/mediachannel/removeTrack.test.ts b/e2e/tests/mediachannel/removeTrack.test.ts index 513622f3..5c1984ca 100644 --- a/e2e/tests/mediachannel/removeTrack.test.ts +++ b/e2e/tests/mediachannel/removeTrack.test.ts @@ -68,7 +68,6 @@ describe("mediachannel_removeTrack", () => { pc.close(); done(); }), - 10 * 1000, ); it( @@ -144,7 +143,6 @@ describe("mediachannel_removeTrack", () => { pc.close(); done(); }), - 10 * 1000, ); it( diff --git a/e2e/tests/mediachannel/rtx.test.ts b/e2e/tests/mediachannel/rtx.test.ts index d00f67b7..b832cbb9 100644 --- a/e2e/tests/mediachannel/rtx.test.ts +++ b/e2e/tests/mediachannel/rtx.test.ts @@ -1,85 +1,77 @@ import { peer, sleep, waitVideoPlay } from "../fixture"; describe("mediachannel_rtx", () => { - it( - "mediachannel_rtx_client_answer", - async () => - new Promise(async (done) => { - const label = "mediachannel_rtx_client_answer"; - if (!peer.connected) await new Promise((r) => peer.on("open", r)); - await sleep(100); - - const pc = new RTCPeerConnection({ - iceServers: [{ urls: "stun:stun.l.google.com:19302" }], - }); - pc.onicecandidate = ({ candidate }) => { - peer - .request(label, { - type: "candidate", - payload: candidate, - }) - .catch(() => {}); - }; - pc.ontrack = async ({ track }) => { - await waitVideoPlay(track); - await peer.request(label, { - type: "done", - }); - pc.close(); - done(); - }; - - const offer = await peer.request(label, { - type: "init", - }); - await pc.setRemoteDescription(offer); - await pc.setLocalDescription(await pc.createAnswer()); + it("mediachannel_rtx_client_answer", async () => + new Promise(async (done) => { + const label = "mediachannel_rtx_client_answer"; + if (!peer.connected) await new Promise((r) => peer.on("open", r)); + await sleep(100); + const pc = new RTCPeerConnection({ + iceServers: [{ urls: "stun:stun.l.google.com:19302" }], + }); + pc.onicecandidate = ({ candidate }) => { peer .request(label, { - type: "answer", - payload: pc.localDescription, + type: "candidate", + payload: candidate, }) .catch(() => {}); - }), - 10 * 1000, - ); + }; + pc.ontrack = async ({ track }) => { + await waitVideoPlay(track); + await peer.request(label, { + type: "done", + }); + pc.close(); + done(); + }; - it( - "mediachannel_rtx_client_offer", - async () => - new Promise(async (done) => { - const label = "mediachannel_rtx_client_offer"; + const offer = await peer.request(label, { + type: "init", + }); + await pc.setRemoteDescription(offer); + await pc.setLocalDescription(await pc.createAnswer()); - if (!peer.connected) await new Promise((r) => peer.on("open", r)); - await sleep(100); + peer + .request(label, { + type: "answer", + payload: pc.localDescription, + }) + .catch(() => {}); + })); - await peer.request(label, { type: "init" }); + it("mediachannel_rtx_client_offer", async () => + new Promise(async (done) => { + const label = "mediachannel_rtx_client_offer"; - const pc = new RTCPeerConnection({ - iceServers: [{ urls: "stun:stun.l.google.com:19302" }], - }); - pc.ontrack = async ({ track }) => { - await waitVideoPlay(track); - await peer.request(label, { type: "done" }); - pc.close(); - done(); - }; - pc.onicecandidate = ({ candidate }) => { - peer - .request(label, { type: "candidate", payload: candidate }) - .catch(() => {}); - }; + if (!peer.connected) await new Promise((r) => peer.on("open", r)); + await sleep(100); - pc.addTransceiver("video", { direction: "recvonly" }); + await peer.request(label, { type: "init" }); - await pc.setLocalDescription(await pc.createOffer()); - const answer = await peer.request(label, { - type: "offer", - payload: pc.localDescription, - }); - await pc.setRemoteDescription(answer); - }), - 10 * 1000, - ); + const pc = new RTCPeerConnection({ + iceServers: [{ urls: "stun:stun.l.google.com:19302" }], + }); + pc.ontrack = async ({ track }) => { + await waitVideoPlay(track); + await peer.request(label, { type: "done" }); + pc.close(); + done(); + }; + pc.onicecandidate = ({ candidate }) => { + peer + .request(label, { type: "candidate", payload: candidate }) + .catch(() => {}); + }; + + pc.addTransceiver("video", { direction: "recvonly" }); + + await pc.setLocalDescription(await pc.createOffer()); + const answer = await peer.request(label, { + type: "offer", + payload: pc.localDescription, + }); + await pc.setRemoteDescription(answer); + })); }); diff --git a/e2e/tests/mediachannel/sendrecv.test.ts b/e2e/tests/mediachannel/sendrecv.test.ts index 08e4307a..f6f4b484 100644 --- a/e2e/tests/mediachannel/sendrecv.test.ts +++ b/e2e/tests/mediachannel/sendrecv.test.ts @@ -1,89 +1,81 @@ import { peer, sleep, waitVideoPlay } from "../fixture"; describe("mediachannel_sendrecv", () => { - it( - "mediachannel_sendrecv_answer", - async () => - new Promise(async (done) => { - const label = "mediachannel_sendrecv_answer"; + it("mediachannel_sendrecv_answer", async () => + new Promise(async (done) => { + const label = "mediachannel_sendrecv_answer"; - if (!peer.connected) await new Promise((r) => peer.on("open", r)); - await sleep(100); + if (!peer.connected) await new Promise((r) => peer.on("open", r)); + await sleep(100); - const pc = new RTCPeerConnection({ - iceServers: [{ urls: "stun:stun.l.google.com:19302" }], - }); - pc.ontrack = async ({ track }) => { - await waitVideoPlay(track); - pc.close(); - done(); - }; + const pc = new RTCPeerConnection({ + iceServers: [{ urls: "stun:stun.l.google.com:19302" }], + }); + pc.ontrack = async ({ track }) => { + await waitVideoPlay(track); + pc.close(); + done(); + }; - const [track] = ( - await navigator.mediaDevices.getUserMedia({ video: true }) - ).getTracks(); - pc.addTrack(track); + const [track] = ( + await navigator.mediaDevices.getUserMedia({ video: true }) + ).getTracks(); + pc.addTrack(track); - const offer = await peer.request(label, { - type: "init", - }); - await pc.setRemoteDescription(offer); - await pc.setLocalDescription(await pc.createAnswer()); - - pc.onicecandidate = ({ candidate }) => { - peer - .request(label, { - type: "candidate", - payload: candidate, - }) - .catch(() => {}); - }; + const offer = await peer.request(label, { + type: "init", + }); + await pc.setRemoteDescription(offer); + await pc.setLocalDescription(await pc.createAnswer()); + pc.onicecandidate = ({ candidate }) => { peer .request(label, { - type: "answer", - payload: pc.localDescription, + type: "candidate", + payload: candidate, }) .catch(() => {}); - }), - 10 * 1000, - ); + }; - it( - "offer", - async () => - new Promise(async (done) => { - if (!peer.connected) await new Promise((r) => peer.on("open", r)); - await sleep(100); + peer + .request(label, { + type: "answer", + payload: pc.localDescription, + }) + .catch(() => {}); + })); - const pc = new RTCPeerConnection({ - iceServers: [{ urls: "stun:stun.l.google.com:19302" }], - }); - pc.ontrack = async ({ track }) => { - await waitVideoPlay(track); - pc.close(); - done(); - }; - const [track] = ( - await navigator.mediaDevices.getUserMedia({ video: true }) - ).getTracks(); - pc.addTrack(track); - pc.onicecandidate = ({ candidate }) => { - peer - .request("mediachannel_sendrecv_offer", { - type: "candidate", - payload: candidate, - }) - .catch(() => {}); - }; + it("offer", async () => + new Promise(async (done) => { + if (!peer.connected) await new Promise((r) => peer.on("open", r)); + await sleep(100); - await pc.setLocalDescription(await pc.createOffer()); - const answer = await peer.request("mediachannel_sendrecv_offer", { - type: "init", - payload: pc.localDescription, - }); - await pc.setRemoteDescription(answer); - }), - 10 * 1000, - ); + const pc = new RTCPeerConnection({ + iceServers: [{ urls: "stun:stun.l.google.com:19302" }], + }); + pc.ontrack = async ({ track }) => { + await waitVideoPlay(track); + pc.close(); + done(); + }; + const [track] = ( + await navigator.mediaDevices.getUserMedia({ video: true }) + ).getTracks(); + pc.addTrack(track); + pc.onicecandidate = ({ candidate }) => { + peer + .request("mediachannel_sendrecv_offer", { + type: "candidate", + payload: candidate, + }) + .catch(() => {}); + }; + + await pc.setLocalDescription(await pc.createOffer()); + const answer = await peer.request("mediachannel_sendrecv_offer", { + type: "init", + payload: pc.localDescription, + }); + await pc.setRemoteDescription(answer); + })); }); diff --git a/e2e/tests/mediachannel/simulcast.test.ts b/e2e/tests/mediachannel/simulcast.test.ts index de151845..4dcc427f 100644 --- a/e2e/tests/mediachannel/simulcast.test.ts +++ b/e2e/tests/mediachannel/simulcast.test.ts @@ -1,91 +1,87 @@ import { peer, sleep, waitVideoPlay } from "../fixture"; describe("mediachannel_simulcast", () => { - it( - "mediachannel_simulcast_answer", - async () => - new Promise(async (done) => { - const label = "mediachannel_simulcast_answer"; - if (!peer.connected) await new Promise((r) => peer.on("open", r)); - await sleep(100); + it("mediachannel_simulcast_answer", async () => + new Promise(async (done) => { + const label = "mediachannel_simulcast_answer"; + if (!peer.connected) await new Promise((r) => peer.on("open", r)); + await sleep(100); - const pc = new RTCPeerConnection({ - iceServers: [{ urls: "stun:stun.l.google.com:19302" }], - }); + const pc = new RTCPeerConnection({ + iceServers: [{ urls: "stun:stun.l.google.com:19302" }], + }); - let count = 0; - const finish = () => { - if (++count == 2) { - pc.close(); - done(); - } - }; - pc.ontrack = async ({ track }) => { - await new Promise((r) => setTimeout(r, 2000)); - await waitVideoPlay(track); + let count = 0; + const finish = () => { + if (++count == 2) { pc.close(); + done(); + } + }; + pc.ontrack = async ({ track }) => { + await new Promise((r) => setTimeout(r, 2000)); + await waitVideoPlay(track); + pc.close(); - finish(); - }; + finish(); + }; - const [track] = ( - await navigator.mediaDevices.getUserMedia({ - video: { - width: { - ideal: 4096, - }, - height: { - ideal: 2160, - }, - frameRate: { - ideal: 60, - min: 10, - }, + const [track] = ( + await navigator.mediaDevices.getUserMedia({ + video: { + width: { + ideal: 4096, + }, + height: { + ideal: 2160, + }, + frameRate: { + ideal: 60, + min: 10, }, - audio: false, - }) - ).getTracks(); - - const offer = await peer.request(label, { - type: "init", - }); - await pc.setRemoteDescription(offer); - pc.addTrack(track); - const transceiver = pc.getTransceivers()[0]; - const params = transceiver.sender.getParameters(); - params.encodings = [ - { - rid: "high", - maxBitrate: 200000, - scaleResolutionDownBy: 1, - }, - { - rid: "low", - maxBitrate: 100000 / 4, - scaleResolutionDownBy: 4, }, - ]; - transceiver.sender.setParameters(params); - await pc.setLocalDescription(await pc.createAnswer()); + audio: false, + }) + ).getTracks(); - pc.onicecandidate = ({ candidate }) => { - peer - .request(label, { - type: "candidate", - payload: candidate, - }) - .catch(() => {}); - }; + const offer = await peer.request(label, { + type: "init", + }); + await pc.setRemoteDescription(offer); + pc.addTrack(track); + const transceiver = pc.getTransceivers()[0]; + const params = transceiver.sender.getParameters(); + params.encodings = [ + { + rid: "high", + maxBitrate: 200000, + scaleResolutionDownBy: 1, + }, + { + rid: "low", + maxBitrate: 100000 / 4, + scaleResolutionDownBy: 4, + }, + ]; + transceiver.sender.setParameters(params); + await pc.setLocalDescription(await pc.createAnswer()); + pc.onicecandidate = ({ candidate }) => { peer .request(label, { - type: "answer", - payload: pc.localDescription, + type: "candidate", + payload: candidate, }) .catch(() => {}); - }), - 15_000, - ); + }; + + peer + .request(label, { + type: "answer", + payload: pc.localDescription, + }) + .catch(() => {}); + })); it( "mediachannel_simulcast_offer", diff --git a/e2e/vitest.config.ts b/e2e/vitest.config.ts index 0418c5b3..e0b6923e 100644 --- a/e2e/vitest.config.ts +++ b/e2e/vitest.config.ts @@ -5,8 +5,8 @@ export default defineConfig({ plugins: [nodePolyfills()], test: { globals: true, - testTimeout: 15_000, - maxConcurrency: 1, + testTimeout: 20_000, + // maxConcurrency: 1, browser: { enabled: true, name: "chromium",