Skip to content

Commit

Permalink
Added ice restart (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
hkirat authored Oct 24, 2021
1 parent 1e76031 commit a1f8afb
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ export default class Client {
stream.publish(this.transports[Role.pub]);
}

restartIce() {
this.renegotiate(true)
}

createDataChannel(label: string) {
if (!this.transports) {
throw Error(ERR_NO_SESSION);
Expand Down Expand Up @@ -222,15 +226,19 @@ export default class Client {
}
}

private async onNegotiationNeeded() {
private onNegotiationNeeded() {
this.renegotiate(false)
}

private async renegotiate(iceRestart: boolean) {
if (!this.transports) {
throw Error(ERR_NO_SESSION);
}

let offer: RTCSessionDescriptionInit | undefined;
let answer: RTCSessionDescriptionInit | undefined;
try {
offer = await this.transports[Role.pub].pc.createOffer();
offer = await this.transports[Role.pub].pc.createOffer({ iceRestart });
await this.transports[Role.pub].pc.setLocalDescription(offer);
answer = await this.signal.offer(offer);
await this.transports[Role.pub].pc.setRemoteDescription(answer);
Expand Down

0 comments on commit a1f8afb

Please sign in to comment.