You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.web.js 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* global APP */
  2. import React from 'react';
  3. import ReactDOM from 'react-dom';
  4. import { getJitsiMeetTransport } from '../modules/transport';
  5. import { App } from './features/app/components';
  6. import { browser } from './features/base/lib-jitsi-meet';
  7. import { getLogger } from './features/base/logging/functions';
  8. import { Platform } from './features/base/react';
  9. import { getJitsiMeetGlobalNS } from './features/base/util';
  10. import { loadScript } from './features/base/util/loadScript';
  11. import PrejoinApp from './features/prejoin/components/PrejoinApp';
  12. const logger = getLogger('index.web');
  13. const OS = Platform.OS;
  14. /**
  15. * Renders the app when the DOM tree has been loaded.
  16. */
  17. document.addEventListener('DOMContentLoaded', () => {
  18. const now = window.performance.now();
  19. APP.connectionTimes['document.ready'] = now;
  20. logger.log('(TIME) document ready:\t', now);
  21. if (!browser.isElectron()) {
  22. const base = window.location.origin;
  23. loadScript(`${base}/static/pwa/registrator.js`);
  24. }
  25. });
  26. // Workaround for the issue when returning to a page with the back button and
  27. // the page is loaded from the 'back-forward' cache on iOS which causes nothing
  28. // to be rendered.
  29. if (OS === 'ios') {
  30. window.addEventListener('pageshow', event => {
  31. // Detect pages loaded from the 'back-forward' cache
  32. // (https://webkit.org/blog/516/webkit-page-cache-ii-the-unload-event/)
  33. if (event.persisted) {
  34. // Maybe there is a more graceful approach but in the moment of
  35. // writing nothing else resolves the issue. I tried to execute our
  36. // DOMContentLoaded handler but it seems that the 'onpageshow' event
  37. // is triggered only when 'window.location.reload()' code exists.
  38. window.location.reload();
  39. }
  40. });
  41. }
  42. /**
  43. * Stops collecting the logs and disposing the API when the user closes the
  44. * page.
  45. */
  46. window.addEventListener('beforeunload', () => {
  47. // Stop the LogCollector
  48. if (APP.logCollectorStarted) {
  49. APP.logCollector.stop();
  50. APP.logCollectorStarted = false;
  51. }
  52. APP.API.notifyConferenceLeft(APP.conference.roomName);
  53. APP.API.dispose();
  54. getJitsiMeetTransport().dispose();
  55. });
  56. const globalNS = getJitsiMeetGlobalNS();
  57. globalNS.entryPoints = {
  58. APP: App,
  59. PREJOIN: PrejoinApp
  60. };
  61. globalNS.renderEntryPoint = ({
  62. Component,
  63. props = {},
  64. elementId = 'react'
  65. }) => {
  66. ReactDOM.render(
  67. <Component { ...props } />,
  68. document.getElementById(elementId)
  69. );
  70. };