set timeout when waiting for connection
This commit is contained in:
parent
4592ff1a11
commit
f28ebd15ad
@ -52,12 +52,28 @@ export async function onVideo(this: WebRtcWebSocket, payload: VoicePayload) {
|
|||||||
const wantsToProduceVideo = d.video_ssrc !== 0 && stream?.active;
|
const wantsToProduceVideo = d.video_ssrc !== 0 && stream?.active;
|
||||||
|
|
||||||
// this is to handle a really weird case where the client sends audio info before the
|
// this is to handle a really weird case where the client sends audio info before the
|
||||||
// dtls ice connection is completely connected. TODO: find a better way to handle this
|
// dtls ice connection is completely connected. Wait for connection for 3 seconds
|
||||||
|
// and if no connection, just ignore this message
|
||||||
if (!this.webRtcClient.webrtcConnected) {
|
if (!this.webRtcClient.webrtcConnected) {
|
||||||
if (wantsToProduceAudio) {
|
if (wantsToProduceAudio) {
|
||||||
await new Promise<void>((resolve, reject) => {
|
try {
|
||||||
this.webRtcClient?.emitter.once("connected", () => resolve());
|
await Promise.race([
|
||||||
});
|
new Promise<void>((resolve, reject) => {
|
||||||
|
this.webRtcClient?.emitter.once("connected", () =>
|
||||||
|
resolve(),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
new Promise<void>((resolve, reject) => {
|
||||||
|
// Reject after 3 seconds if still not connected
|
||||||
|
setTimeout(() => {
|
||||||
|
if (this.webRtcClient?.webrtcConnected) resolve();
|
||||||
|
else reject();
|
||||||
|
}, 3000);
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
} catch (e) {
|
||||||
|
return; // just ignore this message if client didn't connect within 3 seconds
|
||||||
|
}
|
||||||
} else return;
|
} else return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user