Skip to content

Commit ad1aa3c

Browse files
authored
Ensure publication isn't attempted after timeout rejected the promise (#1725)
1 parent 23fbd0a commit ad1aa3c

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

.changeset/spicy-scissors-bake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"livekit-client": patch
3+
---
4+
5+
Ensure publication isn't attempted after timeout rejected the promise

examples/demo/demo.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,14 +401,16 @@ const appActions = {
401401
if (shouldPublish) {
402402
await room.localParticipant.enableCameraAndMicrophone();
403403
appendLog(`tracks published in ${Date.now() - startTime}ms`);
404-
updateButtonsForPublishState();
405404
}
406405
resolve();
407406
} catch (error) {
408407
reject(error);
409408
}
410409
});
411-
await Promise.all([room.connect(url, token, connectOptions), publishPromise]);
410+
await Promise.all([
411+
room.connect(url, token, connectOptions),
412+
publishPromise.catch(appendLog),
413+
]);
412414
const elapsed = Date.now() - startTime;
413415
appendLog(
414416
`successfully connected to ${room.name} in ${Math.round(elapsed)}ms`,

src/room/participant/LocalParticipant.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,11 @@ export default class LocalParticipant extends Participant {
882882
track: getLogContextFromTrack(track),
883883
});
884884

885+
let publicationTimedOut = false;
886+
885887
const timeout = setTimeout(() => {
888+
publicationTimedOut = true;
889+
track.stop();
886890
reject(
887891
new PublishTrackError(
888892
'publishing rejected as engine not connected within timeout',
@@ -892,6 +896,9 @@ export default class LocalParticipant extends Participant {
892896
}, 15_000);
893897
await this.waitUntilEngineConnected();
894898
clearTimeout(timeout);
899+
if (publicationTimedOut) {
900+
return;
901+
}
895902
const publication = await this.publish(track, opts, isStereo);
896903
resolve(publication);
897904
} else {

0 commit comments

Comments
 (0)