2022-01-05 15:06:51 -08:00
|
|
|
/*
|
2022-07-27 16:14:05 -04:00
|
|
|
Copyright 2021-2022 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.
|
|
|
|
*/
|
|
|
|
|
2022-09-09 02:10:45 -04:00
|
|
|
import React, { FC, useEffect, useState, useCallback } from "react";
|
2022-10-10 09:19:10 -04:00
|
|
|
import { useTranslation } from "react-i18next";
|
2022-08-02 00:46:16 +02:00
|
|
|
|
2022-09-09 02:10:45 -04:00
|
|
|
import type { GroupCall } from "matrix-js-sdk/src/webrtc/groupCall";
|
2022-01-05 17:19:03 -08:00
|
|
|
import { useClient } 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-02-22 18:32:51 -08:00
|
|
|
import { MediaHandlerProvider } from "../settings/useMediaHandler";
|
2022-07-13 14:34:15 +01:00
|
|
|
import { useRegisterPasswordlessUser } from "../auth/useRegisterPasswordlessUser";
|
2022-10-10 09:19:10 -04:00
|
|
|
import { translatedError } from "../TranslatedError";
|
2022-01-05 15:06:51 -08:00
|
|
|
|
2022-08-05 16:16:59 -04:00
|
|
|
export const RoomPage: FC = () => {
|
2022-10-10 09:19:10 -04:00
|
|
|
const { t } = useTranslation();
|
2022-01-05 15:06:51 -08:00
|
|
|
const { loading, isAuthenticated, error, client, isPasswordlessUser } =
|
|
|
|
useClient();
|
|
|
|
|
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,
|
|
|
|
isPtt,
|
|
|
|
displayName,
|
2022-10-10 09:19:10 -04:00
|
|
|
} = useUrlParams();
|
2022-07-27 16:14:05 -04:00
|
|
|
const roomIdOrAlias = roomId ?? roomAlias;
|
2022-10-10 09:19:10 -04:00
|
|
|
if (!roomIdOrAlias) throw translatedError("No room specified", t);
|
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
|
|
|
|
2022-07-13 14:34:15 +01:00
|
|
|
useEffect(() => {
|
|
|
|
// If we're not already authed and we've been given a display name as
|
|
|
|
// a URL param, automatically register a passwordless user
|
|
|
|
if (!isAuthenticated && displayName) {
|
|
|
|
setIsRegistering(true);
|
|
|
|
registerPasswordlessUser(displayName).finally(() => {
|
|
|
|
setIsRegistering(false);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, [
|
|
|
|
isAuthenticated,
|
|
|
|
displayName,
|
|
|
|
setIsRegistering,
|
|
|
|
registerPasswordlessUser,
|
|
|
|
]);
|
|
|
|
|
2022-09-09 02:04:53 -04:00
|
|
|
const groupCallView = useCallback(
|
|
|
|
(groupCall: GroupCall) => (
|
|
|
|
<GroupCallView
|
|
|
|
client={client}
|
|
|
|
roomIdOrAlias={roomIdOrAlias}
|
|
|
|
groupCall={groupCall}
|
|
|
|
isPasswordlessUser={isPasswordlessUser}
|
|
|
|
isEmbedded={isEmbedded}
|
2022-09-09 02:10:45 -04:00
|
|
|
preload={preload}
|
2022-09-09 02:04:53 -04:00
|
|
|
hideHeader={hideHeader}
|
|
|
|
/>
|
|
|
|
),
|
2022-09-09 02:10:45 -04:00
|
|
|
[client, roomIdOrAlias, isPasswordlessUser, isEmbedded, preload, hideHeader]
|
2022-09-09 02:04:53 -04:00
|
|
|
);
|
|
|
|
|
2022-07-13 14:34:15 +01:00
|
|
|
if (loading || isRegistering) {
|
2022-01-05 15:35:12 -08:00
|
|
|
return <LoadingView />;
|
2022-01-05 15:06:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
return <ErrorView error={error} />;
|
|
|
|
}
|
|
|
|
|
2022-01-05 15:35:12 -08:00
|
|
|
if (!isAuthenticated) {
|
|
|
|
return <RoomAuthView />;
|
|
|
|
}
|
|
|
|
|
2022-01-05 15:06:51 -08:00
|
|
|
return (
|
2022-02-22 18:32:51 -08:00
|
|
|
<MediaHandlerProvider client={client}>
|
2022-07-11 13:23:03 +01:00
|
|
|
<GroupCallLoader
|
|
|
|
client={client}
|
2022-07-27 16:14:05 -04:00
|
|
|
roomIdOrAlias={roomIdOrAlias}
|
2022-07-11 13:23:03 +01:00
|
|
|
viaServers={viaServers}
|
|
|
|
createPtt={isPtt}
|
|
|
|
>
|
2022-09-09 02:04:53 -04:00
|
|
|
{groupCallView}
|
2022-02-22 18:32:51 -08:00
|
|
|
</GroupCallLoader>
|
|
|
|
</MediaHandlerProvider>
|
2022-01-05 15:06:51 -08:00
|
|
|
);
|
2022-08-05 16:16:59 -04:00
|
|
|
};
|