Skip to content

Commit

Permalink
add restartIce method
Browse files Browse the repository at this point in the history
  • Loading branch information
shinyoshiaki committed Jan 5, 2025
1 parent 6afe3f5 commit a8032cf
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/webrtc/src/peerConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ export class RTCPeerConnection extends EventTarget {
private replaceTransceiver(t: RTCRtpTransceiver, index: number) {
this.transceivers[index] = t;
}

candidatesSent = new Set<string>();
needRestart = false;

readonly iceGatheringStateChange = new Event<[IceGathererState]>();
readonly iceConnectionStateChange = new Event<[RTCIceConnectionState]>();
Expand Down Expand Up @@ -262,7 +261,8 @@ export class RTCPeerConnection extends EventTarget {
}

async createOffer({ iceRestart }: { iceRestart?: boolean } = {}) {
if (iceRestart) {
if (iceRestart || this.needRestart) {
this.needRestart = false;
for (const t of this.iceTransports) {
await t.restart();
}
Expand Down Expand Up @@ -482,7 +482,9 @@ export class RTCPeerConnection extends EventTarget {

private needNegotiation = async () => {
this.shouldNegotiationneeded = true;
if (this.negotiationneeded || this.signalingState !== "stable") return;
if (this.negotiationneeded || this.signalingState !== "stable") {
return;
}
this.shouldNegotiationneeded = false;
setImmediate(() => {
this.negotiationneeded = true;
Expand Down Expand Up @@ -879,6 +881,11 @@ export class RTCPeerConnection extends EventTarget {
return bundle;
}

restartIce() {
this.needRestart = true;
this.needNegotiation();
}

async setRemoteDescription(sessionDescription: RTCSessionDescriptionInit) {
if (
!sessionDescription.sdp ||
Expand Down

0 comments on commit a8032cf

Please sign in to comment.