2021-07-16 21:38:44 +00:00
|
|
|
/*
|
|
|
|
Copyright 2021 New Vector Ltd
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2021-07-27 19:27:59 +00:00
|
|
|
import React from "react";
|
2021-07-19 19:55:30 +00:00
|
|
|
import {
|
|
|
|
BrowserRouter as Router,
|
|
|
|
Switch,
|
|
|
|
Route,
|
|
|
|
Redirect,
|
2021-08-10 01:38:19 +00:00
|
|
|
useLocation,
|
2021-07-19 19:55:30 +00:00
|
|
|
} from "react-router-dom";
|
2021-07-27 19:27:59 +00:00
|
|
|
import { useConferenceCallManager } from "./ConferenceCallManagerHooks";
|
|
|
|
import { JoinOrCreateRoom } from "./JoinOrCreateRoom";
|
|
|
|
import { LoginOrRegister } from "./LoginOrRegister";
|
|
|
|
import { Room } from "./Room";
|
2021-08-11 23:02:40 +00:00
|
|
|
import { GridDemo } from "./GridDemo";
|
2021-07-16 21:22:03 +00:00
|
|
|
|
|
|
|
export default function App() {
|
|
|
|
const { protocol, host } = window.location;
|
|
|
|
// Assume homeserver is hosted on same domain (proxied in development by vite)
|
|
|
|
const homeserverUrl = `${protocol}//${host}`;
|
2021-07-27 18:40:19 +00:00
|
|
|
const { loading, authenticated, error, manager, login, register } =
|
|
|
|
useConferenceCallManager(homeserverUrl);
|
2021-07-16 21:22:03 +00:00
|
|
|
|
|
|
|
return (
|
2021-07-19 19:55:30 +00:00
|
|
|
<Router>
|
2021-07-27 19:27:59 +00:00
|
|
|
<div>
|
2021-07-16 21:22:03 +00:00
|
|
|
{error && <p>{error.message}</p>}
|
|
|
|
{loading ? (
|
|
|
|
<p>Loading...</p>
|
|
|
|
) : (
|
2021-07-19 19:55:30 +00:00
|
|
|
<Switch>
|
|
|
|
<Route exact path="/">
|
|
|
|
{authenticated ? (
|
2021-07-27 18:40:19 +00:00
|
|
|
<JoinOrCreateRoom manager={manager} />
|
2021-07-19 19:55:30 +00:00
|
|
|
) : (
|
2021-07-27 18:55:45 +00:00
|
|
|
<LoginOrRegister onRegister={register} onLogin={login} />
|
2021-07-19 19:55:30 +00:00
|
|
|
)}
|
|
|
|
</Route>
|
2021-08-10 01:38:19 +00:00
|
|
|
<AuthenticatedRoute
|
|
|
|
authenticated={authenticated}
|
|
|
|
path="/room/:roomId"
|
|
|
|
>
|
|
|
|
<Room manager={manager} />
|
|
|
|
</AuthenticatedRoute>
|
2021-08-11 23:02:40 +00:00
|
|
|
<Route exact path="/grid">
|
|
|
|
<GridDemo />
|
|
|
|
</Route>
|
2021-07-19 19:55:30 +00:00
|
|
|
</Switch>
|
2021-07-16 21:22:03 +00:00
|
|
|
)}
|
|
|
|
</div>
|
2021-07-19 19:55:30 +00:00
|
|
|
</Router>
|
2021-07-16 21:22:03 +00:00
|
|
|
);
|
|
|
|
}
|
2021-08-10 01:38:19 +00:00
|
|
|
|
|
|
|
function AuthenticatedRoute({ authenticated, children, ...rest }) {
|
|
|
|
const location = useLocation();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Route {...rest}>
|
|
|
|
{authenticated ? (
|
|
|
|
children
|
|
|
|
) : (
|
|
|
|
<Redirect
|
|
|
|
to={{
|
|
|
|
pathname: "/",
|
|
|
|
state: { from: location },
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Route>
|
|
|
|
);
|
|
|
|
}
|