From 518c8eadca630e06e7c2ebc30e1a89c8cb5be812 Mon Sep 17 00:00:00 2001 From: Robin Date: Mon, 24 Feb 2025 11:43:15 +0700 Subject: [PATCH] Finish the hangup procedure even if widget API throws errors --- src/rtcSessionHelpers.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/rtcSessionHelpers.ts b/src/rtcSessionHelpers.ts index 13cfae1e..52498516 100644 --- a/src/rtcSessionHelpers.ts +++ b/src/rtcSessionHelpers.ts @@ -144,11 +144,19 @@ const widgetPostHangupProcedure = async ( // We send the hangup event after the memberships have been updated // calling leaveRTCSession. // We need to wait because this makes the client hosting this widget killing the IFrame. - await widget.api.transport.send(ElementWidgetActions.HangupCall, {}); + try { + await widget.api.transport.send(ElementWidgetActions.HangupCall, {}); + } catch (e) { + logger.error("Failed to send hangup action", e); + } // On a normal user hangup we can shut down and close the widget. But if an // error occurs we should keep the widget open until the user reads it. if (cause === "user") { - await widget.api.transport.send(ElementWidgetActions.Close, {}); + try { + await widget.api.transport.send(ElementWidgetActions.Close, {}); + } catch (e) { + logger.error("Failed to send close action", e); + } widget.api.transport.stop(); PosthogAnalytics.instance.logout(); }