Files
element-call/src/main.tsx

73 lines
2.2 KiB
TypeScript
Raw Normal View History

2021-07-16 14:38:44 -07:00
/*
Copyright 2021-2024 New Vector Ltd.
2021-07-16 14:38:44 -07:00
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
2021-07-16 14:38:44 -07:00
*/
// We need to import this somewhere, once, so that the correct 'request'
// function gets set. It needs to be not in the same file as we use
// createClient, or the typescript transpiler gets confused about
// dependency references.
2025-03-13 13:58:43 +01:00
import "matrix-js-sdk/lib/browser-index";
2025-10-08 16:39:27 -04:00
import { StrictMode } from "react";
2022-10-27 08:55:04 -04:00
import { createRoot } from "react-dom/client";
2022-06-01 11:48:17 -04:00
import "./index.css";
2025-03-13 13:58:43 +01:00
import { logger } from "matrix-js-sdk/lib/logger";
import {
setLogExtension as setLKLogExtension,
2024-09-11 14:02:59 +01:00
setLogLevel as setLKLogLevel,
} from "livekit-client";
2023-09-21 16:50:31 +01:00
import { App } from "./App";
2022-04-07 14:22:36 -07:00
import { init as initRageshake } from "./settings/rageshake";
import { Initializer } from "./initializer";
import { AppViewModel } from "./state/AppViewModel";
import { globalScope } from "./state/ObservableScope";
2022-02-01 15:11:06 -08:00
window.setLKLogLevel = setLKLogLevel;
initRageshake().catch((e) => {
logger.error("Failed to initialize rageshake", e);
});
2025-05-27 17:38:45 +02:00
setLKLogLevel("info");
2024-09-11 14:02:59 +01:00
setLKLogExtension((level, msg, context) => {
// we pass a synthetic logger name of "livekit" to the rageshake to make it easier to read
global.mx_rage_logger.log(level, "livekit", msg, context);
});
2021-10-06 11:38:26 -07:00
logger.info(`Element Call ${import.meta.env.VITE_APP_VERSION || "dev"}`);
2022-10-27 08:55:04 -04:00
const root = createRoot(document.getElementById("root")!);
let fatalError: Error | null = null;
if (!window.isSecureContext) {
fatalError = new Error(
"This app cannot run in an insecure context. To fix this, access the app " +
"via a local loopback address, or serve it over HTTPS.\n" +
2023-10-11 10:42:04 -04:00
"https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts",
);
} else if (!navigator.mediaDevices) {
fatalError = new Error("Your browser does not support WebRTC.");
}
if (fatalError !== null) {
2022-10-27 08:55:04 -04:00
root.render(fatalError.message);
throw fatalError; // Stop the app early
}
Initializer.initBeforeReact()
.then(() => {
root.render(
2025-10-08 16:39:27 -04:00
<StrictMode>
<App vm={new AppViewModel(globalScope)} />
2025-10-08 16:39:27 -04:00
</StrictMode>,
);
})
.catch((e) => {
logger.error("Failed to initialize app", e);
root.render(e.message);
});