From 8ff8dc9b8a9ee4d0f7fdc4cae8e4323aeabe2553 Mon Sep 17 00:00:00 2001 From: Sergey Aksenov Date: Fri, 18 Sep 2026 11:17:48 +0200 Subject: [PATCH] Catch the negotiate() rejection on a media-sections requirement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RTCEngine has three `this.negotiate()` call sites; two attach `.catch((err) => this.log.error(err))` and the one wired to `client.onMediaSectionsRequirement` does not. A renegotiation that fails there rejects into nothing, so instead of a logged error the application sees an unhandled promise rejection with no stack — on React Native it reaches crash reporting as a bare `onunhandledrejection`, detached from the disconnect it accompanies. Nothing changes behaviourally: `negotiate()` already calls `handleDisconnect` before rejecting, so the engine's own recovery runs either way. This only routes the error to the logger the other two call sites use. --- .changeset/catch-negotiate-on-media-sections-requirement.md | 5 +++++ src/room/RTCEngine.ts | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .changeset/catch-negotiate-on-media-sections-requirement.md diff --git a/.changeset/catch-negotiate-on-media-sections-requirement.md b/.changeset/catch-negotiate-on-media-sections-requirement.md new file mode 100644 index 0000000000..8d0fc0a150 --- /dev/null +++ b/.changeset/catch-negotiate-on-media-sections-requirement.md @@ -0,0 +1,5 @@ +--- +'livekit-client': patch +--- + +Catch the rejection from `negotiate()` when the server requests media sections, so a failed renegotiation no longer surfaces as an unhandled promise rejection diff --git a/src/room/RTCEngine.ts b/src/room/RTCEngine.ts index fd0fc1fd61..e31db71aa3 100644 --- a/src/room/RTCEngine.ts +++ b/src/room/RTCEngine.ts @@ -755,7 +755,9 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit this.client.onMediaSectionsRequirement = (requirement: MediaSectionsRequirement) => { this.addMediaSections(requirement.numAudios, requirement.numVideos); - this.negotiate(); + this.negotiate().catch((err) => { + this.log.error(err); + }); }; this.client.onPublishDataTrackResponse = (event: PublishDataTrackResponse) => {