Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: terminate ice gathering after 1000ms timeout #390

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion packages/js/src/Modules/Verto/webrtc/Peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { IVertoCallOptions } from './interfaces';
export default class Peer {
public instance: RTCPeerConnection;
public iceGatheringComplete: DeferredPromise<boolean>;
private iceGatheringTimeout: number | null;
public onSdpReadyTwice: Function = null;
private _constraints: {
offerToReceiveAudio: boolean;
Expand Down Expand Up @@ -60,7 +61,8 @@ export default class Peer {
this.handleNegotiationNeededEvent.bind(this);
this.handleTrackEvent = this.handleTrackEvent.bind(this);
this.createPeerConnection = this.createPeerConnection.bind(this);
this.iceGatheringComplete = deferredPromise({ debounceTime: 100 });
this.iceGatheringComplete = deferredPromise({ debounceTime: undefined });
this.iceGatheringTimeout = null;

this._session = session;

Expand Down Expand Up @@ -181,6 +183,12 @@ export default class Peer {
// This is a workaround for the issue where iceGatheringState is always 'gathering'
this.iceGatheringComplete.resolve(true);
}
if (event.candidate == null) {
console.log(
'ICE Candidate gathering is Complete without finding a relay candidate'
);
this.iceGatheringComplete.resolve(true);
}
};
private handleConnectionStateChange = async (event: Event) => {
const { connectionState } = this.instance;
Expand Down Expand Up @@ -252,6 +260,9 @@ export default class Peer {
`[${new Date().toISOString()}] ICE Gathering State`,
this.instance.iceGatheringState
);
if (this.instance.iceGatheringState === 'complete') {
this.iceGatheringComplete.resolve(true);
}
};
private async _init() {
await this.createPeerConnection();
Expand Down Expand Up @@ -442,6 +453,11 @@ export default class Peer {
mediaSettings.sdpASBandwidthKbps
);
}
window.clearTimeout(this.iceGatheringTimeout);
this.iceGatheringTimeout = window.setTimeout(() => {
// Failsafe for ICE gathering going on forever.
this.iceGatheringComplete.resolve(true);
}, 1000);
return this.instance.setLocalDescription(sessionDescription);
}

Expand Down
Loading