mirror of
https://github.com/vector-im/element-call.git
synced 2026-02-08 04:19:11 +00:00
* Refactor media devices to live outside React as Observables This moves the media devices state out of React to further our transition to a MVVM architecture in which we can more easily model and store complex application state. I have created an AppViewModel to act as the overarching state holder for any future non-React state we end up creating, and the MediaDevices reside within this. We should move more application logic (including the CallViewModel itself) there in the future. * Address review feedback * Fixes from ios debugging session: (#3342) - dont use preferred vs selected concept in controlled media. Its not needed since we dont use the id for actual browser media devices (the id's are not even actual browser media devices) - add more logging - add more conditions to not accidently set a deviceId that is not a browser deviceId but one provided via controlled. --------- Co-authored-by: Timo <16718859+toger5@users.noreply.github.com>
72 lines
2.1 KiB
TypeScript
72 lines
2.1 KiB
TypeScript
/*
|
|
Copyright 2021-2024 New Vector Ltd.
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|
Please see LICENSE in the repository root for full details.
|
|
*/
|
|
|
|
// 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.
|
|
import "matrix-js-sdk/lib/browser-index";
|
|
|
|
import { StrictMode } from "react";
|
|
import { createRoot } from "react-dom/client";
|
|
import "./index.css";
|
|
import { logger } from "matrix-js-sdk/lib/logger";
|
|
import {
|
|
setLogExtension as setLKLogExtension,
|
|
setLogLevel as setLKLogLevel,
|
|
} from "livekit-client";
|
|
|
|
import { App } from "./App";
|
|
import { init as initRageshake } from "./settings/rageshake";
|
|
import { Initializer } from "./initializer";
|
|
import { AppViewModel } from "./state/AppViewModel";
|
|
|
|
window.setLKLogLevel = setLKLogLevel;
|
|
|
|
initRageshake().catch((e) => {
|
|
logger.error("Failed to initialize rageshake", e);
|
|
});
|
|
setLKLogLevel("info");
|
|
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);
|
|
});
|
|
|
|
logger.info(`Element Call ${import.meta.env.VITE_APP_VERSION || "dev"}`);
|
|
|
|
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" +
|
|
"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) {
|
|
root.render(fatalError.message);
|
|
throw fatalError; // Stop the app early
|
|
}
|
|
|
|
Initializer.initBeforeReact()
|
|
.then(() => {
|
|
root.render(
|
|
<StrictMode>
|
|
<App vm={new AppViewModel()} />
|
|
</StrictMode>,
|
|
);
|
|
})
|
|
.catch((e) => {
|
|
logger.error("Failed to initialize app", e);
|
|
root.render(e.message);
|
|
});
|