2022-05-04 17:09:48 +01:00
|
|
|
/*
|
2023-01-03 16:55:26 +00:00
|
|
|
Copyright 2022 New Vector Ltd
|
2022-05-04 17:09:48 +01:00
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2023-09-19 17:57:16 +01:00
|
|
|
import { ReactNode, 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";
|
2023-08-16 18:41:27 +01:00
|
|
|
import { MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSession";
|
2023-09-19 17:57:16 +01:00
|
|
|
import { MatrixError } from "matrix-js-sdk";
|
|
|
|
|
import { useHistory } from "react-router-dom";
|
|
|
|
|
import { Link } from "@vector-im/compound-web";
|
2022-08-02 00:46:16 +02:00
|
|
|
|
2022-01-05 16:51:24 -08:00
|
|
|
import { useLoadGroupCall } 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[];
|
2023-08-16 18:41:27 +01:00
|
|
|
children: (rtcSession: MatrixRTCSession) => ReactNode;
|
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();
|
|
|
|
|
const onHomeClick = useCallback(() => history.push("/"), [history]);
|
|
|
|
|
|
2023-07-03 19:14:03 +01:00
|
|
|
switch (groupCallState.kind) {
|
|
|
|
|
case "loading":
|
|
|
|
|
return (
|
|
|
|
|
<FullScreenView>
|
|
|
|
|
<h1>{t("Loading…")}</h1>
|
|
|
|
|
</FullScreenView>
|
|
|
|
|
);
|
|
|
|
|
case "loaded":
|
2023-08-16 18:41:27 +01:00
|
|
|
return <>{children(groupCallState.rtcSession)}</>;
|
2023-07-03 19:14:03 +01:00
|
|
|
case "failed":
|
2023-09-19 17:57:16 +01:00
|
|
|
if ((groupCallState.error as MatrixError).errcode === "M_NOT_FOUND") {
|
|
|
|
|
return (
|
|
|
|
|
<FullScreenView>
|
|
|
|
|
<h1>{t("Call not found")}</h1>
|
|
|
|
|
<p>
|
|
|
|
|
{t(
|
2023-09-19 18:26:08 +01:00
|
|
|
"Calls are now end-to-end encrypted and need to be created from the home page. This helps make sure everyone's using the same encryption key."
|
2023-09-19 17:57:16 +01:00
|
|
|
)}
|
|
|
|
|
</p>
|
|
|
|
|
{/* 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}>
|
|
|
|
|
{t("Home")}
|
|
|
|
|
</Link>
|
|
|
|
|
</FullScreenView>
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
return <ErrorView error={groupCallState.error} />;
|
|
|
|
|
}
|
2022-01-05 15:35:12 -08:00
|
|
|
}
|
|
|
|
|
}
|