2022-05-04 17:09:48 +01:00
|
|
|
/*
|
2024-09-06 10:22:13 +02:00
|
|
|
Copyright 2022-2024 New Vector Ltd.
|
2022-05-04 17:09:48 +01:00
|
|
|
|
2024-09-06 10:22:13 +02: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
|
|
|
*/
|
|
|
|
|
|
2024-04-23 15:15:13 +02:00
|
|
|
import { useCallback } from "react";
|
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";
|
2023-09-19 17:57:16 +01:00
|
|
|
import { useHistory } from "react-router-dom";
|
2023-09-19 18:27:53 +01:00
|
|
|
import { Heading, Link, Text } from "@vector-im/compound-web";
|
2022-08-02 00:46:16 +02:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2022-07-11 13:23:03 +01:00
|
|
|
export function GroupCallLoader({
|
|
|
|
|
client,
|
2022-07-27 16:14:05 -04:00
|
|
|
roomIdOrAlias,
|
2022-07-11 13:23:03 +01:00
|
|
|
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
|
|
|
|
2023-09-19 17:57:16 +01:00
|
|
|
const history = useHistory();
|
2023-09-19 18:29:09 +01:00
|
|
|
const onHomeClick = useCallback(
|
2023-09-19 18:36:51 +01:00
|
|
|
(ev: React.MouseEvent) => {
|
2023-09-19 18:29:09 +01:00
|
|
|
ev.preventDefault();
|
|
|
|
|
history.push("/");
|
|
|
|
|
},
|
2023-10-11 10:42:04 -04:00
|
|
|
[history],
|
2023-09-19 18:29:09 +01:00
|
|
|
);
|
2023-09-19 17:57:16 +01:00
|
|
|
|
2023-07-03 19:14:03 +01:00
|
|
|
switch (groupCallState.kind) {
|
2024-04-23 15:15:13 +02:00
|
|
|
case "loaded":
|
|
|
|
|
case "waitForInvite":
|
|
|
|
|
case "canKnock":
|
|
|
|
|
return children(groupCallState);
|
2023-07-03 19:14:03 +01:00
|
|
|
case "loading":
|
|
|
|
|
return (
|
|
|
|
|
<FullScreenView>
|
2023-11-20 11:05:18 +00:00
|
|
|
<h1>{t("common.loading")}</h1>
|
2023-07-03 19:14:03 +01:00
|
|
|
</FullScreenView>
|
|
|
|
|
);
|
|
|
|
|
case "failed":
|
2023-09-19 17:57:16 +01:00
|
|
|
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>
|
2023-09-19 17:57:16 +01:00
|
|
|
{/* 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 href="/" onClick={onHomeClick}>
|
2023-11-20 11:05:18 +00:00
|
|
|
{t("common.home")}
|
2023-09-19 17:57:16 +01:00
|
|
|
</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 href="/" onClick={onHomeClick}>
|
|
|
|
|
{t("common.home")}
|
|
|
|
|
</Link>
|
|
|
|
|
</FullScreenView>
|
|
|
|
|
);
|
2023-09-19 17:57:16 +01:00
|
|
|
} else {
|
|
|
|
|
return <ErrorView error={groupCallState.error} />;
|
|
|
|
|
}
|
2022-01-05 15:35:12 -08:00
|
|
|
}
|
|
|
|
|
}
|