Skip to content

Commit 664fff7

Browse files
authored
Emit MediaDeviceError only when acquiring tracks fails (#1365)
* Emit MediaDeviceError only when acquiring tracks fails * Create strong-shrimps-wave.md
1 parent 1dcb15a commit 664fff7

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

.changeset/strong-shrimps-wave.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+
Emit MediaDeviceError only when acquiring tracks fails

src/room/participant/LocalParticipant.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,16 @@ export default class LocalParticipant extends Participant {
486486
default:
487487
throw new TrackInvalidError(source);
488488
}
489+
} catch (e: unknown) {
490+
localTracks?.forEach((tr) => {
491+
tr.stop();
492+
});
493+
if (e instanceof Error) {
494+
this.emit(ParticipantEvent.MediaDevicesError, e);
495+
}
496+
throw e;
497+
}
498+
try {
489499
const publishPromises: Array<Promise<LocalTrackPublication>> = [];
490500
for (const localTrack of localTracks) {
491501
this.log.info('publishing track', {
@@ -502,9 +512,6 @@ export default class LocalParticipant extends Participant {
502512
localTracks?.forEach((tr) => {
503513
tr.stop();
504514
});
505-
if (e instanceof Error && !(e instanceof TrackInvalidError)) {
506-
this.emit(ParticipantEvent.MediaDevicesError, e);
507-
}
508515
throw e;
509516
} finally {
510517
this.pendingPublishing.delete(source);

0 commit comments

Comments
 (0)