From 3d66a425d5bcd5dd55895fdab6585c80bfd7bea5 Mon Sep 17 00:00:00 2001 From: Conroy Whitney Date: Tue, 19 Nov 2024 13:13:29 -0500 Subject: [PATCH] Catch `InvalidStateError: RTCPeerConnection is closed` exception --- src/room/track/LocalTrack.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/room/track/LocalTrack.ts b/src/room/track/LocalTrack.ts index 25fe029a34..e7162a5b4d 100644 --- a/src/room/track/LocalTrack.ts +++ b/src/room/track/LocalTrack.ts @@ -172,7 +172,17 @@ export default abstract class LocalTrack< } } if (this.sender) { - await this.sender.replaceTrack(processedTrack ?? newTrack); + try { + await this.sender.replaceTrack(processedTrack ?? newTrack); + } catch (e) { + this.log.error('failed to replace track on sender', { + ...this.logContext, + error: e, + newTrack: newTrack, + processedTrack: processedTrack, + sender: this.sender + }); + } } // if `newTrack` is different from the existing track, stop the // older track just before replacing it