Skip to content

Commit a2cf4c8

Browse files
authored
Merge pull request #3479 from robintown/fix-reconnect
Fix the reconnect button
2 parents 65d358d + 32cb854 commit a2cf4c8

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

src/room/GroupCallErrorBoundary.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,10 @@ test("ConnectionLostError: Action handling should reset error state", async () =
132132
const WrapComponent = (): ReactNode => {
133133
const [failState, setFailState] = useState(true);
134134
const reconnectCallback = useCallback(
135-
(action: CallErrorRecoveryAction) => {
135+
async (action: CallErrorRecoveryAction) => {
136136
reconnectCallbackSpy(action);
137137
setFailState(false);
138+
return Promise.resolve();
138139
},
139140
[setFailState],
140141
);

src/room/GroupCallErrorBoundary.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ import { type WidgetHelpers } from "../widget.ts";
3636

3737
export type CallErrorRecoveryAction = "reconnect"; // | "retry" ;
3838

39-
export type RecoveryActionHandler = (action: CallErrorRecoveryAction) => void;
39+
export type RecoveryActionHandler = (
40+
action: CallErrorRecoveryAction,
41+
) => Promise<void>;
4042

4143
interface ErrorPageProps {
4244
error: ElementCallError;
@@ -71,7 +73,7 @@ const ErrorPage: FC<ErrorPageProps> = ({
7173
if (error instanceof ConnectionLostError) {
7274
actions.push({
7375
label: t("call_ended_view.reconnect_button"),
74-
onClick: () => recoveryActionHandler("reconnect"),
76+
onClick: () => void recoveryActionHandler("reconnect"),
7577
});
7678
}
7779

@@ -131,9 +133,9 @@ export const GroupCallErrorBoundary = ({
131133
widget={widget ?? null}
132134
error={callError}
133135
resetError={resetError}
134-
recoveryActionHandler={(action: CallErrorRecoveryAction) => {
136+
recoveryActionHandler={async (action: CallErrorRecoveryAction) => {
137+
await recoveryActionHandler(action);
135138
resetError();
136-
recoveryActionHandler(action);
137139
}}
138140
/>
139141
);

src/room/GroupCallView.test.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ import {
1313
test,
1414
vi,
1515
} from "vitest";
16-
import { render, waitFor, screen } from "@testing-library/react";
16+
import { render, waitFor, screen, act } from "@testing-library/react";
1717
import { type MatrixClient, JoinRule, type RoomState } from "matrix-js-sdk";
18-
import { type MatrixRTCSession } from "matrix-js-sdk/lib/matrixrtc";
18+
import {
19+
MatrixRTCSessionEvent,
20+
type MatrixRTCSession,
21+
} from "matrix-js-sdk/lib/matrixrtc";
1922
import { BrowserRouter } from "react-router-dom";
2023
import userEvent from "@testing-library/user-event";
2124
import { type RelationsContainer } from "matrix-js-sdk/lib/models/relations-container";
@@ -258,3 +261,19 @@ test("GroupCallView shows errors that occur during joining", async () => {
258261
await user.click(screen.getByRole("button", { name: "Join call" }));
259262
screen.getByText("Call is not supported");
260263
});
264+
265+
test("user can reconnect after a membership manager error", async () => {
266+
const user = userEvent.setup();
267+
const { rtcSession } = createGroupCallView(null, true);
268+
await act(() =>
269+
rtcSession.emit(MatrixRTCSessionEvent.MembershipManagerError, undefined),
270+
);
271+
// XXX: Wrapping the following click in act() shouldn't be necessary (the
272+
// async state update should be processed automatically by the waitFor call),
273+
// and yet here we are.
274+
await act(async () =>
275+
user.click(screen.getByRole("button", { name: "Reconnect" })),
276+
);
277+
// In-call controls should be visible again
278+
await waitFor(() => screen.getByRole("button", { name: "Leave" }));
279+
});

src/room/GroupCallView.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,10 +497,11 @@ export const GroupCallView: FC<Props> = ({
497497
return (
498498
<GroupCallErrorBoundary
499499
widget={widget}
500-
recoveryActionHandler={(action) => {
500+
recoveryActionHandler={async (action) => {
501+
setExternalError(null);
501502
if (action == "reconnect") {
502503
setLeft(false);
503-
enterRTCSessionOrError(rtcSession).catch((e) => {
504+
await enterRTCSessionOrError(rtcSession).catch((e) => {
504505
logger.error("Error re-entering RTC session", e);
505506
});
506507
}

0 commit comments

Comments
 (0)