您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

getRouteToRender.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // @flow
  2. import type { Component } from 'react';
  3. import { isRoomValid } from '../base/conference';
  4. import JitsiMeetJS from '../base/lib-jitsi-meet';
  5. import { Platform } from '../base/react';
  6. import { toState } from '../base/redux';
  7. import { Conference } from '../conference';
  8. import { getDeepLinkingPage } from '../deep-linking';
  9. import { UnsupportedDesktopBrowser } from '../unsupported-browser';
  10. import {
  11. BlankPage,
  12. WelcomePage,
  13. generateRoomWithoutSeparator,
  14. isWelcomePageAppEnabled,
  15. isWelcomePageUserEnabled
  16. } from '../welcome';
  17. declare var interfaceConfig: Object;
  18. /**
  19. * Object describing application route.
  20. *
  21. * @typedef {Object} Route
  22. * @property {Component} component - React Component constructor.
  23. * @property {string|undefined} href - New location, in case navigation involves
  24. * a location change.
  25. */
  26. export type Route = {
  27. component: Class<Component<*>>,
  28. href: ?string
  29. };
  30. /**
  31. * Determines which route is to be rendered in order to depict a specific Redux
  32. * store.
  33. *
  34. * @param {(Function|Object)} stateful - THe redux store, state, or
  35. * {@code getState} function.
  36. * @returns {Promise<Route>}
  37. */
  38. export function _getRouteToRender(stateful: Function | Object): Promise<Route> {
  39. const state = toState(stateful);
  40. const { room } = state['features/base/conference'];
  41. const isMobileApp = navigator.product === 'ReactNative';
  42. const isMobileBrowser
  43. = !isMobileApp && (Platform.OS === 'android' || Platform.OS === 'ios');
  44. const route: Route = {
  45. component: BlankPage,
  46. href: undefined
  47. };
  48. return new Promise(resolve => {
  49. // First, check if the current endpoint supports WebRTC. We are
  50. // intentionally not performing the check for mobile browsers because:
  51. // - the WelcomePage is mobile ready;
  52. // - if the URL points to a conference, getDeepLinkingPage will take
  53. // care of it.
  54. if (!isMobileBrowser && !JitsiMeetJS.isWebRtcSupported()) {
  55. route.component = UnsupportedDesktopBrowser;
  56. resolve(route);
  57. return;
  58. }
  59. if (isRoomValid(room)) {
  60. if (isMobileApp) {
  61. route.component = Conference;
  62. resolve(route);
  63. } else {
  64. // Update the location if it doesn't match. This happens when a
  65. // room is joined from the welcome page. The reason for doing
  66. // this instead of using the history API is that we want to load
  67. // the config.js which takes the room into account.
  68. const { locationURL } = state['features/base/connection'];
  69. // eslint-disable-next-line no-negated-condition
  70. if (window.location.href !== locationURL.href) {
  71. route.href = locationURL.href;
  72. resolve(route);
  73. } else {
  74. // Maybe show deep-linking, otherwise go to Conference.
  75. getDeepLinkingPage(state).then(component => {
  76. route.component = component || Conference;
  77. resolve(route);
  78. });
  79. }
  80. }
  81. return;
  82. }
  83. if (!isWelcomePageUserEnabled(state)) {
  84. // Web: if the welcome page is disabled, go directly to a random
  85. // room.
  86. let href = window.location.href;
  87. href.endsWith('/') || (href += '/');
  88. route.href = href + generateRoomWithoutSeparator();
  89. } else if (isWelcomePageAppEnabled(state)) {
  90. // Mobile: only go to the welcome page if enabled.
  91. route.component = WelcomePage;
  92. }
  93. resolve(route);
  94. });
  95. }