From 538332df66fb6938e1784c22b5185750e1edae67 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Mon, 11 Nov 2024 12:35:41 -0500 Subject: [PATCH] Refactor if expression Split the check on a boolean into another branch --- src/room/GroupCallView.tsx | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/room/GroupCallView.tsx b/src/room/GroupCallView.tsx index 86feaaaa..fc28e357 100644 --- a/src/room/GroupCallView.tsx +++ b/src/room/GroupCallView.tsx @@ -178,29 +178,31 @@ export const GroupCallView: FC = ({ }; if (skipLobby) { - if (widget && preload) { - // In preload mode without lobby we wait for a join action before entering - const onJoin = (ev: CustomEvent): void => { + if (widget) { + if (preload) { + // In preload mode without lobby we wait for a join action before entering + const onJoin = (ev: CustomEvent): void => { + (async (): Promise => { + await defaultDeviceSetup(ev.detail.data as unknown as JoinCallData); + await enterRTCSession(rtcSession, perParticipantE2EE); + widget!.api.transport.reply(ev.detail, {}); + })().catch((e) => { + logger.error("Error joining RTC session", e); + }); + }; + widget.lazyActions.on(ElementWidgetActions.JoinCall, onJoin); + return (): void => { + widget!.lazyActions.off(ElementWidgetActions.JoinCall, onJoin); + }; + } else { + // No lobby and no preload: we enter the rtc session right away (async (): Promise => { - await defaultDeviceSetup(ev.detail.data as unknown as JoinCallData); + await defaultDeviceSetup({ audioInput: null, videoInput: null }); await enterRTCSession(rtcSession, perParticipantE2EE); - widget!.api.transport.reply(ev.detail, {}); })().catch((e) => { logger.error("Error joining RTC session", e); }); - }; - widget.lazyActions.on(ElementWidgetActions.JoinCall, onJoin); - return (): void => { - widget!.lazyActions.off(ElementWidgetActions.JoinCall, onJoin); - }; - } else if (widget && !preload) { - // No lobby and no preload: we enter the rtc session right away - (async (): Promise => { - await defaultDeviceSetup({ audioInput: null, videoInput: null }); - await enterRTCSession(rtcSession, perParticipantE2EE); - })().catch((e) => { - logger.error("Error joining RTC session", e); - }); + } } else { void enterRTCSession(rtcSession, perParticipantE2EE); }