Files
element-call/src/room/GroupCallLoader.tsx
T

78 lines
2.3 KiB
TypeScript
Raw Normal View History

2022-05-04 17:09:48 +01:00
/*
Copyright 2022-2024 New Vector Ltd.
2022-05-04 17:09:48 +01:00
SPDX-License-Identifier: AGPL-3.0-only
Please see LICENSE in the repository root for full details.
2022-05-04 17:09:48 +01:00
*/
2022-08-12 16:46:53 -04:00
import { MatrixClient } from "matrix-js-sdk/src/client";
2022-10-10 09:19:10 -04:00
import { useTranslation } from "react-i18next";
2024-08-29 17:37:52 +01:00
import { MatrixError } from "matrix-js-sdk/src/matrix";
import { Heading, Text } from "@vector-im/compound-web";
2022-08-02 00:46:16 +02:00
import { Link } from "../button/Link";
2024-04-23 15:15:13 +02:00
import {
useLoadGroupCall,
GroupCallStatus,
CallTerminatedMessage,
} from "./useLoadGroupCall";
2022-01-05 15:35:12 -08:00
import { ErrorView, FullScreenView } from "../FullScreenView";
2022-08-02 00:46:16 +02:00
interface Props {
client: MatrixClient;
2022-08-05 16:16:59 -04:00
roomIdOrAlias: string;
2022-08-02 00:46:16 +02:00
viaServers: string[];
2024-04-23 15:15:13 +02:00
children: (groupCallState: GroupCallStatus) => JSX.Element;
2022-08-02 00:46:16 +02:00
}
export function GroupCallLoader({
client,
2022-07-27 16:14:05 -04:00
roomIdOrAlias,
viaServers,
children,
2022-08-02 00:46:16 +02:00
}: Props): JSX.Element {
2022-10-10 09:19:10 -04:00
const { t } = useTranslation();
2023-09-18 11:06:06 -04:00
const groupCallState = useLoadGroupCall(client, roomIdOrAlias, viaServers);
2022-01-05 15:35:12 -08:00
switch (groupCallState.kind) {
2024-04-23 15:15:13 +02:00
case "loaded":
case "waitForInvite":
case "canKnock":
return children(groupCallState);
case "loading":
return (
<FullScreenView>
<h1>{t("common.loading")}</h1>
</FullScreenView>
);
case "failed":
if ((groupCallState.error as MatrixError).errcode === "M_NOT_FOUND") {
return (
<FullScreenView>
2024-04-23 15:15:13 +02:00
<Heading>{t("group_call_loader.failed_heading")}</Heading>
<Text>{t("group_call_loader.failed_text")}</Text>
{/* XXX: A 'create it for me' button would be the obvious UX here. Two screens already have
dupes of this flow, let's make a common component and put it here. */}
<Link to="/">{t("common.home")}</Link>
</FullScreenView>
);
2024-04-23 15:15:13 +02:00
} else if (groupCallState.error instanceof CallTerminatedMessage) {
return (
<FullScreenView>
<Heading>{groupCallState.error.message}</Heading>
<Text>{groupCallState.error.messageBody}</Text>
{groupCallState.error.reason && (
<>
{t("group_call_loader.reason")}:
<Text size="sm">"{groupCallState.error.reason}"</Text>
</>
)}
<Link to="/">{t("common.home")}</Link>
2024-04-23 15:15:13 +02:00
</FullScreenView>
);
} else {
return <ErrorView error={groupCallState.error} />;
}
2022-01-05 15:35:12 -08:00
}
}