Skip to content

Commit

Permalink
fix for early check
Browse files Browse the repository at this point in the history
  • Loading branch information
shinyoshiaki committed Jan 2, 2025
1 parent 39ecdb6 commit 95d04a9
Show file tree
Hide file tree
Showing 15 changed files with 333 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
npm i
cd e2e
npm i
npx playwright install
npx playwright install chromium
cd ../
- name: test
env:
Expand Down
36 changes: 19 additions & 17 deletions e2e/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
"ci:silent": "npm run build && run-p server:silent chrome:prod",
"clean": "pkill -9 gst-launch",
"debug": "cd debug && npm run dev",
"dev": "vitest ./tests --browser.headless",
"firefox:dev": "vitest run ./tests --browser.headless --config vitest.firefox.config.ts",
"format": "biome check --write server tests",
"server": "ts-node-dev --project tsconfig.server.json ./server/main.ts",
"server:dev": "DEBUG=werift* ts-node-dev --project tsconfig.server.json ./server/main.ts",
"server:prod": "DEBUG=werift* node lib/e2e/server/main.js",
"server:silent": "node lib/e2e/server/main.js",
Expand All @@ -33,7 +35,7 @@
"express": "^4.21.1",
"jsonc-parser": "^3.1.0",
"npm-run-all2": "^6.1.1",
"playwright": "^1.41.2",
"playwright": "^1.49.1",
"protoo-client": "^4.0.6",
"protoo-server": "^4.0.6",
"vite-plugin-node-polyfills": "^0.21.0"
Expand Down
125 changes: 125 additions & 0 deletions e2e/server/handler/ice/restart.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import type { AcceptFn, Peer } from "protoo-server";
import { RTCPeerConnection } from "../..";
import { peerConfig } from "../../fixture";

const ice_restart_web_trigger_label = "ice_restart_web_trigger";
export class ice_restart_web_trigger {
pc!: RTCPeerConnection;

async exec(type: string, payload: any, accept: AcceptFn, peer: Peer) {
switch (type) {
case "init":
{
this.pc = new RTCPeerConnection(await peerConfig);
this.pc.onIceCandidate.subscribe((candidate) => {
peer
.request(ice_restart_web_trigger_label + "ice", candidate)
.catch((e) => {
console.error(e);
});
});
this.pc.iceConnectionStateChange.subscribe((state) => {
console.log(state);
});

const transceiver = this.pc.addTransceiver("video");
transceiver.onTrack.subscribe((track) => {
transceiver.sender.replaceTrack(track);
setInterval(async () => {
await transceiver.receiver.sendRtcpPLI(track.ssrc);
}, 3000);
});

this.pc.setLocalDescription(await this.pc.createOffer());
accept(this.pc.localDescription);
}
break;
case "candidate":
{
this.pc.addIceCandidate(payload);
accept({});
}
break;
case "answer":
{
await this.pc.setRemoteDescription(payload);
accept({});
}
break;
case "offer":
{
await this.pc.setRemoteDescription(payload);
const answer = await this.pc.createAnswer();
this.pc.setLocalDescription(answer);
accept(this.pc.localDescription);
}
break;
}
}
}

const ice_restart_node_trigger_label = "ice_restart_node_trigger";
export class ice_restart_node_trigger {
pc!: RTCPeerConnection;

async exec(type: string, payload: any, accept: AcceptFn, peer: Peer) {
switch (type) {
case "init":
{
this.pc = new RTCPeerConnection(await peerConfig);
this.pc.onIceCandidate.subscribe((candidate) => {
peer
.request(ice_restart_node_trigger_label + "ice", candidate)
.catch((e) => {
console.error(e);
});
});
this.pc.iceConnectionStateChange.subscribe((state) => {
console.log(state);
});

const transceiver = this.pc.addTransceiver("video");
transceiver.onTrack.subscribe((track) => {
transceiver.sender.replaceTrack(track);
const interval = setInterval(async () => {
if (this.pc.signalingState === "closed") {
clearInterval(interval);
return;
}
await transceiver.receiver.sendRtcpPLI(track.ssrc);
}, 3000);
});

this.pc.setLocalDescription(await this.pc.createOffer());
accept(this.pc.localDescription);
}
break;
case "candidate":
{
this.pc.addIceCandidate(payload);
accept({});
}
break;
case "answer":
{
await this.pc.setRemoteDescription(payload);
accept({});
}
break;
case "restart":
{
await this.pc.setLocalDescription(
await this.pc.createOffer({ iceRestart: true }),
);
accept(this.pc.localDescription);
}
break;
case "fin":
{
this.pc.close();
accept({});
}
break;
}
}
}
2 changes: 1 addition & 1 deletion e2e/server/handler/ice/trickle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class ice_trickle_offer {
this.pc.onIceCandidate.subscribe((candidate) => {
peer.request("ice_trickle_offer", candidate).catch(() => {});
});
this.pc.setRemoteDescription(payload);
await this.pc.setRemoteDescription(payload);
this.pc.setLocalDescription(await this.pc.createAnswer());

accept(this.pc.localDescription);
Expand Down
6 changes: 6 additions & 0 deletions e2e/server/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ import {
mediachannel_simulcast_answer,
mediachannel_simulcast_offer,
} from "./handler/mediachannel/simulcast";
import {
ice_restart_node_trigger,
ice_restart_web_trigger,
} from "./handler/ice/restart";

const app = express();
app.use(express.json() as never);
Expand Down Expand Up @@ -116,6 +120,8 @@ server.on("connectionrequest", async (_, accept) => {
mediachannel_addtrack_removefirst_addtrack:
new mediachannel_addtrack_removefirst_addtrack(),
mediachannel_offer_replace_second: new mediachannel_offer_replace_second(),
ice_restart_web_trigger: new ice_restart_web_trigger(),
ice_restart_node_trigger: new ice_restart_node_trigger(),
};

const transport = accept();
Expand Down
3 changes: 1 addition & 2 deletions e2e/tests/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ export const peer = new Peer(transport);

export async function waitVideoPlay(track: MediaStreamTrack) {
const video = document.createElement("video");
const media = new MediaStream();
media.addTrack(track);
const media = new MediaStream([track]);
video.srcObject = media;
video.autoplay = true;
video.muted = true;
Expand Down
Loading

0 comments on commit 95d04a9

Please sign in to comment.