Files
upstream-jitsi-meet/react/index.web.js
upstream-mirror 1d2bfcac0c
Some checks failed
Prosody Plugin Tests / test (push) Failing after 10m11s
Close stale issues and PRs / stale (push) Failing after 1s
snapshot of https://github.com/jitsi/jitsi-meet.git @ fd1749dd28f4138aa80234fc7f311b19aaffa0e7 (2026-09-15)
2026-09-15 15:56:32 +05:00

94 lines
3.1 KiB
JavaScript

import React from 'react';
import { createRoot } from 'react-dom/client';
import { App } from './features/app/components/App.web';
import { getLogger } from './features/base/logging/functions';
import Platform from './features/base/react/Platform.web';
import { getJitsiMeetGlobalNS, getJitsiMeetGlobalNSConnectionTimes } from './features/base/util/helpers';
import DialInSummaryApp from './features/invite/components/dial-in-summary/web/DialInSummaryApp';
import PrejoinApp from './features/prejoin/components/web/PrejoinApp';
import WhiteboardApp from './features/whiteboard/components/web/WhiteboardApp';
const logger = getLogger('app:index.web');
// Add global loggers.
window.addEventListener('error', ev => {
logger.error(
`UnhandledError: ${ev.message}`,
`Script: ${ev.filename}`,
`Line: ${ev.lineno}`,
`Column: ${ev.colno}`,
'StackTrace: ', ev.error?.stack);
});
window.addEventListener('unhandledrejection', ev => {
logger.error(
`UnhandledPromiseRejection: ${ev.reason}`,
'StackTrace: ', ev.reason?.stack);
});
// Workaround for the issue when returning to a page with the back button and
// the page is loaded from the 'back-forward' cache on iOS which causes nothing
// to be rendered.
if (Platform.OS === 'ios') {
window.addEventListener('pageshow', event => {
// Detect pages loaded from the 'back-forward' cache
// (https://webkit.org/blog/516/webkit-page-cache-ii-the-unload-event/)
if (event.persisted) {
// Maybe there is a more graceful approach but in the moment of
// writing nothing else resolves the issue. I tried to execute our
// DOMContentLoaded handler but it seems that the 'onpageshow' event
// is triggered only when 'window.location.reload()' code exists.
window.location.reload();
}
});
}
const globalNS = getJitsiMeetGlobalNS();
const connectionTimes = getJitsiMeetGlobalNSConnectionTimes();
// Used to check if the load event has been fired.
globalNS.hasLoaded = false;
// Used for automated performance tests.
connectionTimes['index.loaded'] = window.indexLoadedTime;
window.addEventListener('load', () => {
connectionTimes['window.loaded'] = window.loadedEventTime;
globalNS.hasLoaded = true;
});
document.addEventListener('DOMContentLoaded', () => {
const now = window.performance.now();
connectionTimes['document.ready'] = now;
logger.log('(TIME) document ready:\t', now);
});
globalNS.entryPoints = {
APP: App,
PREJOIN: PrejoinApp,
DIALIN: DialInSummaryApp,
WHITEBOARD: WhiteboardApp
};
/**
* React 18 concurrent mode allows only one root per DOM node. Cache roots by
* element ID so {@code renderEntryPoint} never calls {@code createRoot} twice
* on the same element.
*/
const _roots = new Map();
globalNS.renderEntryPoint = ({
Component,
props = {},
elementId = 'react'
}) => {
const element = document.getElementById(elementId);
if (!_roots.has(elementId)) {
_roots.set(elementId, createRoot(element));
}
_roots.get(elementId).render(<Component { ...props } />);
};