Refactoring how we are creating the answer so we don't need to wait for the client gathering all ice candidates.

This commit is contained in:
Filipi Fuchter
2025-03-24 11:12:41 -03:00
parent fee0409f63
commit fcb8b9a5b3
4 changed files with 35 additions and 15 deletions

View File

@@ -157,7 +157,7 @@ export class SmallWebRTCTransport {
await this.pc.setLocalDescription(offer);
// Wait for ICE gathering to complete
await new Promise<void>((resolve) => {
/*await new Promise<void>((resolve) => {
if (this.pc!.iceGatheringState === 'complete') {
resolve();
} else {
@@ -169,7 +169,7 @@ export class SmallWebRTCTransport {
};
this.pc!.addEventListener('icegatheringstatechange', checkState);
}
});
});*/
let offerSdp = this.pc!.localDescription!;
let codec: string;

View File

@@ -24,7 +24,7 @@
let connected = false
let peerConnection = null
const waitForIceGatheringComplete = async (pc) => {
/*const waitForIceGatheringComplete = async (pc) => {
if (pc.iceGatheringState === 'complete') return;
return new Promise((resolve) => {
const checkState = () => {
@@ -35,14 +35,14 @@
};
pc.addEventListener('icegatheringstatechange', checkState);
});
}
}*/
const createSmallWebRTCConnection = async (audioTrack) => {
const pc = new RTCPeerConnection()
pc.ontrack = e => audioEl.srcObject = e.streams[0]
pc.addTransceiver(audioTrack, { direction: 'sendrecv' })
await pc.setLocalDescription(await pc.createOffer())
await waitForIceGatheringComplete(pc)
//await waitForIceGatheringComplete(pc)
const offer = pc.localDescription
const response = await fetch('/api/offer', {
body: JSON.stringify({ sdp: offer.sdp, type: offer.type}),