Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
shinyoshiaki committed Jan 1, 2024
1 parent d430869 commit 50af776
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
44 changes: 44 additions & 0 deletions e2e/server/handler/ice/restart.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { AcceptFn, Peer } from "protoo-server";
import { RTCPeerConnection } from "../..";
import { peerConfig } from "../../fixture";

export class ice_restart_answer {
label = "ice_restart_answer";
pc!: RTCPeerConnection;

async exec(type: string, payload: any, accept: AcceptFn, peer: Peer) {
switch (type) {
case "init": {
this.pc = new RTCPeerConnection(await peerConfig);
const dc = this.pc.createDataChannel("dc");
dc.onMessage.subscribe((msg) => {
dc.send(msg + "pong");
});
this.pc.onIceCandidate.subscribe((candidate) => {
peer.request(this.label, candidate).catch(() => {});
});

const offer = await this.pc.createOffer();
this.pc.setLocalDescription(offer);
accept(this.pc.localDescription);
}
break;
case "candidate": {
this.pc.addIceCandidate(payload);
accept({});
}
break;
case "answer": {
this.pc.setRemoteDescription(payload);
accept({});
}
break;
case "restart": {
this.pc.restartIce();
const offer = await this.pc.createOffer();
this.pc.setLocalDescription(offer);
accept(this.pc.localDescription);
}
}
}
}
8 changes: 7 additions & 1 deletion packages/ice/src/ice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { Message, parseMessage } from "./stun/message";
import { StunProtocol } from "./stun/protocol";
import { createTurnEndpoint } from "./turn/protocol";
import { Address, Protocol } from "./types/model";
import { getHostAddresses, normalizeFamilyNodeV18 } from "./utils";
import { getHostAddresses } from "./utils";

const log = debug("werift-ice : packages/ice/src/ice.ts : log");

Expand Down Expand Up @@ -662,6 +662,12 @@ export class Connection {
this.sortCheckList();
}

resetNominatedPair() {
log("resetNominatedPair");
this.nominated = undefined;
this.nominating = false;
}

private checkComplete(pair: CandidatePair) {
pair.handle = undefined;
if (pair.state === CandidatePairState.SUCCEEDED) {
Expand Down
2 changes: 1 addition & 1 deletion packages/webrtc/src/media/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class RtpRouter {
}

if (!rtpReceiver) {
log("ssrcReceiver not found");
// log("ssrcReceiver not found");
return;
}

Expand Down
9 changes: 6 additions & 3 deletions packages/webrtc/src/transport/ice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ export class RTCIceTransport {
(this.connection.remoteUsername !== remoteParameters.usernameFragment ||
this.connection.remotePassword !== remoteParameters.password)
) {
log("restartIce", remoteParameters);
this.gather.restart();
log("resetNominatedPair", remoteParameters);
this.connection.resetNominatedPair();
// this.gather.restart();
}
this.connection.setRemoteParams(remoteParameters);
}
Expand All @@ -76,7 +77,9 @@ export class RTCIceTransport {
throw new Error("remoteParams missing");
}

if (this.gather.waitStart) await this.gather.waitStart.asPromise();
if (this.gather.waitStart) {
await this.gather.waitStart.asPromise();
}
this.gather.waitStart = new Event();

this.setState("checking");
Expand Down

0 comments on commit 50af776

Please sign in to comment.