Skip to content

Commit f12e660

Browse files
authored
Refactor if expression (#2758)
Split the check on a boolean into another branch
1 parent 4b2d840 commit f12e660

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

src/room/GroupCallView.tsx

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -178,29 +178,33 @@ export const GroupCallView: FC<Props> = ({
178178
};
179179

180180
if (skipLobby) {
181-
if (widget && preload) {
182-
// In preload mode without lobby we wait for a join action before entering
183-
const onJoin = (ev: CustomEvent<IWidgetApiRequest>): void => {
181+
if (widget) {
182+
if (preload) {
183+
// In preload mode without lobby we wait for a join action before entering
184+
const onJoin = (ev: CustomEvent<IWidgetApiRequest>): void => {
185+
(async (): Promise<void> => {
186+
await defaultDeviceSetup(
187+
ev.detail.data as unknown as JoinCallData,
188+
);
189+
await enterRTCSession(rtcSession, perParticipantE2EE);
190+
widget!.api.transport.reply(ev.detail, {});
191+
})().catch((e) => {
192+
logger.error("Error joining RTC session", e);
193+
});
194+
};
195+
widget.lazyActions.on(ElementWidgetActions.JoinCall, onJoin);
196+
return (): void => {
197+
widget!.lazyActions.off(ElementWidgetActions.JoinCall, onJoin);
198+
};
199+
} else {
200+
// No lobby and no preload: we enter the rtc session right away
184201
(async (): Promise<void> => {
185-
await defaultDeviceSetup(ev.detail.data as unknown as JoinCallData);
202+
await defaultDeviceSetup({ audioInput: null, videoInput: null });
186203
await enterRTCSession(rtcSession, perParticipantE2EE);
187-
widget!.api.transport.reply(ev.detail, {});
188204
})().catch((e) => {
189205
logger.error("Error joining RTC session", e);
190206
});
191-
};
192-
widget.lazyActions.on(ElementWidgetActions.JoinCall, onJoin);
193-
return (): void => {
194-
widget!.lazyActions.off(ElementWidgetActions.JoinCall, onJoin);
195-
};
196-
} else if (widget && !preload) {
197-
// No lobby and no preload: we enter the rtc session right away
198-
(async (): Promise<void> => {
199-
await defaultDeviceSetup({ audioInput: null, videoInput: null });
200-
await enterRTCSession(rtcSession, perParticipantE2EE);
201-
})().catch((e) => {
202-
logger.error("Error joining RTC session", e);
203-
});
207+
}
204208
} else {
205209
void enterRTCSession(rtcSession, perParticipantE2EE);
206210
}

0 commit comments

Comments
 (0)