diff --git a/.changeset/giant-ligers-flow.md b/.changeset/giant-ligers-flow.md new file mode 100644 index 0000000000..6c66d2bd3d --- /dev/null +++ b/.changeset/giant-ligers-flow.md @@ -0,0 +1,5 @@ +--- +"livekit-client": patch +--- + +Avoid uncaught errors related to send/disconnect races diff --git a/src/room/RTCEngine.ts b/src/room/RTCEngine.ts index 8af239ad51..350178db47 100644 --- a/src/room/RTCEngine.ts +++ b/src/room/RTCEngine.ts @@ -267,7 +267,9 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit // create offer if (!this.subscriberPrimary || joinResponse.fastPublish) { - this.negotiate(); + this.negotiate().catch((err) => { + log.error(err, this.logContext); + }); } this.registerOnLineListener(); @@ -1338,7 +1340,9 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit } if (needNegotiation) { // start negotiation - this.negotiate(); + this.negotiate().catch((err) => { + log.error(err, this.logContext); + }); } const targetChannel = this.dataChannelForKind(kind, subscriber); diff --git a/src/room/data-stream/incoming/IncomingDataStreamManager.ts b/src/room/data-stream/incoming/IncomingDataStreamManager.ts index 413b28c645..28fb282ed5 100644 --- a/src/room/data-stream/incoming/IncomingDataStreamManager.ts +++ b/src/room/data-stream/incoming/IncomingDataStreamManager.ts @@ -124,6 +124,9 @@ export default class IncomingDataStreamManager { let streamController: ReadableStreamDefaultController; const outOfBandFailureRejectingFuture = new Future(); + outOfBandFailureRejectingFuture.promise.catch((err) => { + this.log.error(err); + }); const info: ByteStreamInfo = { id: streamHeader.streamId, @@ -178,6 +181,10 @@ export default class IncomingDataStreamManager { let streamController: ReadableStreamDefaultController; const outOfBandFailureRejectingFuture = new Future(); + outOfBandFailureRejectingFuture.promise.catch((err) => { + this.log.error(err); + }); + const info: TextStreamInfo = { id: streamHeader.streamId, mimeType: streamHeader.mimeType,