2022-01-05 15:06:51 -08:00
|
|
|
/*
|
2023-05-05 11:44:35 +02:00
|
|
|
Copyright 2021-2023 New Vector Ltd
|
2022-01-05 15:06:51 -08: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-17 17:48:03 -04:00
|
|
|
import { FC, useEffect, useState, useCallback, ReactNode } from "react";
|
2023-08-16 18:41:27 +01:00
|
|
|
import { MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSession";
|
2022-08-02 00:46:16 +02:00
|
|
|
|
2023-06-30 16:43:28 +01:00
|
|
|
import { useClientLegacy } from "../ClientContext";
|
2022-01-05 15:35:12 -08:00
|
|
|
import { ErrorView, LoadingView } from "../FullScreenView";
|
|
|
|
|
import { RoomAuthView } from "./RoomAuthView";
|
|
|
|
|
import { GroupCallLoader } from "./GroupCallLoader";
|
|
|
|
|
import { GroupCallView } from "./GroupCallView";
|
2022-10-10 09:19:10 -04:00
|
|
|
import { useUrlParams } from "../UrlParams";
|
2022-07-13 14:34:15 +01:00
|
|
|
import { useRegisterPasswordlessUser } from "../auth/useRegisterPasswordlessUser";
|
2023-03-13 18:40:16 -04:00
|
|
|
import { useOptInAnalytics } from "../settings/useSetting";
|
2023-07-29 20:42:16 +02:00
|
|
|
import { HomePage } from "../home/HomePage";
|
2023-09-17 17:48:03 -04:00
|
|
|
import { platform } from "../Platform";
|
|
|
|
|
import { AppSelectionModal } from "./AppSelectionModal";
|
2022-01-05 15:06:51 -08:00
|
|
|
|
2022-08-05 16:16:59 -04:00
|
|
|
export const RoomPage: FC = () => {
|
2022-09-09 02:04:53 -04:00
|
|
|
const {
|
|
|
|
|
roomAlias,
|
|
|
|
|
roomId,
|
|
|
|
|
viaServers,
|
|
|
|
|
isEmbedded,
|
2022-09-09 02:10:45 -04:00
|
|
|
preload,
|
2022-09-09 02:04:53 -04:00
|
|
|
hideHeader,
|
|
|
|
|
displayName,
|
2022-10-10 09:19:10 -04:00
|
|
|
} = useUrlParams();
|
2022-07-27 16:14:05 -04:00
|
|
|
const roomIdOrAlias = roomId ?? roomAlias;
|
2023-07-29 20:31:18 +02:00
|
|
|
if (!roomIdOrAlias) {
|
|
|
|
|
console.error("No room specified");
|
|
|
|
|
}
|
2022-07-27 16:14:05 -04:00
|
|
|
|
2023-03-13 18:40:16 -04:00
|
|
|
const [optInAnalytics, setOptInAnalytics] = useOptInAnalytics();
|
2022-07-27 16:14:05 -04:00
|
|
|
const { registerPasswordlessUser } = useRegisterPasswordlessUser();
|
2022-07-13 14:34:15 +01:00
|
|
|
const [isRegistering, setIsRegistering] = useState(false);
|
2022-01-05 15:06:51 -08:00
|
|
|
|
2023-03-13 18:40:16 -04:00
|
|
|
useEffect(() => {
|
|
|
|
|
// During the beta, opt into analytics by default
|
2023-06-30 16:43:28 +01:00
|
|
|
if (optInAnalytics === null && setOptInAnalytics) setOptInAnalytics(true);
|
2023-03-13 18:40:16 -04:00
|
|
|
}, [optInAnalytics, setOptInAnalytics]);
|
|
|
|
|
|
2023-06-30 16:43:28 +01:00
|
|
|
const { loading, authenticated, client, error, passwordlessUser } =
|
|
|
|
|
useClientLegacy();
|
|
|
|
|
|
2022-07-13 14:34:15 +01:00
|
|
|
useEffect(() => {
|
2023-01-20 17:59:57 +00:00
|
|
|
// If we've finished loading, are not already authed and we've been given a display name as
|
2022-07-13 14:34:15 +01:00
|
|
|
// a URL param, automatically register a passwordless user
|
2023-06-30 16:43:28 +01:00
|
|
|
if (!loading && !authenticated && displayName) {
|
2022-07-13 14:34:15 +01:00
|
|
|
setIsRegistering(true);
|
|
|
|
|
registerPasswordlessUser(displayName).finally(() => {
|
|
|
|
|
setIsRegistering(false);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, [
|
2023-06-30 16:43:28 +01:00
|
|
|
loading,
|
|
|
|
|
authenticated,
|
2022-07-13 14:34:15 +01:00
|
|
|
displayName,
|
|
|
|
|
setIsRegistering,
|
|
|
|
|
registerPasswordlessUser,
|
|
|
|
|
]);
|
|
|
|
|
|
2022-09-09 02:04:53 -04:00
|
|
|
const groupCallView = useCallback(
|
2023-08-16 18:41:27 +01:00
|
|
|
(rtcSession: MatrixRTCSession) => (
|
2022-09-09 02:04:53 -04:00
|
|
|
<GroupCallView
|
2023-06-30 16:43:28 +01:00
|
|
|
client={client!}
|
2023-08-16 18:41:27 +01:00
|
|
|
rtcSession={rtcSession}
|
2023-06-30 16:43:28 +01:00
|
|
|
isPasswordlessUser={passwordlessUser}
|
2022-09-09 02:04:53 -04:00
|
|
|
isEmbedded={isEmbedded}
|
2022-09-09 02:10:45 -04:00
|
|
|
preload={preload}
|
2022-09-09 02:04:53 -04:00
|
|
|
hideHeader={hideHeader}
|
|
|
|
|
/>
|
|
|
|
|
),
|
2023-07-04 18:46:27 +01:00
|
|
|
[client, passwordlessUser, isEmbedded, preload, hideHeader]
|
2022-09-09 02:04:53 -04:00
|
|
|
);
|
|
|
|
|
|
2023-09-17 17:48:03 -04:00
|
|
|
let content: ReactNode;
|
2022-07-13 14:34:15 +01:00
|
|
|
if (loading || isRegistering) {
|
2023-09-17 17:48:03 -04:00
|
|
|
content = <LoadingView />;
|
|
|
|
|
} else if (error) {
|
|
|
|
|
content = <ErrorView error={error} />;
|
|
|
|
|
} else if (!client) {
|
|
|
|
|
content = <RoomAuthView />;
|
|
|
|
|
} else if (!roomIdOrAlias) {
|
|
|
|
|
// TODO: This doesn't belong here, the app routes need to be reworked
|
|
|
|
|
content = <HomePage />;
|
|
|
|
|
} else {
|
|
|
|
|
content = (
|
|
|
|
|
<GroupCallLoader
|
|
|
|
|
client={client}
|
|
|
|
|
roomIdOrAlias={roomIdOrAlias}
|
|
|
|
|
viaServers={viaServers}
|
|
|
|
|
>
|
|
|
|
|
{groupCallView}
|
|
|
|
|
</GroupCallLoader>
|
|
|
|
|
);
|
2023-07-29 20:42:16 +02:00
|
|
|
}
|
|
|
|
|
|
2022-01-05 15:06:51 -08:00
|
|
|
return (
|
2023-09-17 17:48:03 -04:00
|
|
|
<>
|
|
|
|
|
{content}
|
|
|
|
|
{/* On mobile, show a prompt to launch the mobile app. If in embedded mode,
|
|
|
|
|
that means we *are* in the mobile app and should show no further prompt. */}
|
|
|
|
|
{(platform === "android" || platform === "ios") && !isEmbedded && (
|
|
|
|
|
<AppSelectionModal roomId={roomId} />
|
|
|
|
|
)}
|
|
|
|
|
</>
|
2022-01-05 15:06:51 -08:00
|
|
|
);
|
2022-08-05 16:16:59 -04:00
|
|
|
};
|