Przeglądaj źródła

Simplify route navigation

I see it as the first step in simplifying the route navigate of the
JavaScript app by removing BlankWelcomePage from _getRouteToRender. From
a faraway point of view, the app is at the route at which it is not in a
conference. Historically, the route was known as the Welcome page. But
mobile complicated the route by saying that actually it may not want to
see the room name input and join button.

Additionally, I renamed BlankWelcomePage to BlankPage because I don't
think of it as a WelcomePage alternative but rather as a more generic
BlankPage which may be utilized elsewhere in the future.

I plan for the next steps to:
* Merge Entryway, _interceptComponent, and _getRouteToRender in one
React Component rendered by AbstractApp so that the whole logic is in
one file;
* Get rid of RouteRegistry and routes.
j8
Lyubo Marinov 8 lat temu
rodzic
commit
0b8c12de0e

+ 5
- 18
react/features/app/functions.native.js Wyświetl plik

@@ -1,7 +1,9 @@
1
+/* @flow */
2
+
1 3
 import { isRoomValid } from '../base/conference';
2 4
 import { RouteRegistry } from '../base/react';
3 5
 import { Conference } from '../conference';
4
-import { BlankWelcomePage, WelcomePage } from '../welcome';
6
+import { Entryway } from '../welcome';
5 7
 
6 8
 /**
7 9
  * Determines which route is to be rendered in order to depict a specific Redux
@@ -11,28 +13,13 @@ import { BlankWelcomePage, WelcomePage } from '../welcome';
11 13
  * method.
12 14
  * @returns {Route}
13 15
  */
14
-export function _getRouteToRender(stateOrGetState) {
16
+export function _getRouteToRender(stateOrGetState: Object | Function) {
15 17
     const state
16 18
         = typeof stateOrGetState === 'function'
17 19
             ? stateOrGetState()
18 20
             : stateOrGetState;
19 21
     const { room } = state['features/base/conference'];
20
-    let component;
21
-
22
-    if (isRoomValid(room)) {
23
-        component = Conference;
24
-    } else {
25
-        // The value of the App prop welcomePageEnabled was stored in redux in
26
-        // saghul's PR. But I removed the redux state, action, action type, etc.
27
-        // because I didn't like the name. We are not using the prop is a
28
-        // React-ive way anyway so it's all the same difference.
29
-        const { app } = state['features/app'];
30
-
31
-        component
32
-            = app && app.props.welcomePageEnabled
33
-                ? WelcomePage
34
-                : BlankWelcomePage;
35
-    }
22
+    const component = isRoomValid(room) ? Conference : Entryway;
36 23
 
37 24
     return RouteRegistry.getRouteByComponent(component);
38 25
 }

+ 11
- 18
react/features/app/functions.web.js Wyświetl plik

@@ -1,15 +1,17 @@
1 1
 /* @flow */
2 2
 
3
-import { isRoomValid } from '../base/conference';
4
-import { Platform, RouteRegistry } from '../base/react';
5
-import { Conference } from '../conference';
3
+import { Platform } from '../base/react';
6 4
 import {
7 5
     NoMobileApp,
8 6
     PluginRequiredBrowser,
9 7
     UnsupportedDesktopBrowser,
10 8
     UnsupportedMobileBrowser
11 9
 } from '../unsupported-browser';
12
-import { WelcomePage } from '../welcome';
10
+
11
+import {
12
+    // eslint-disable-next-line camelcase
13
+    _getRouteToRender as _super_getRouteToRender
14
+} from './functions.native';
13 15
 
14 16
 declare var APP: Object;
15 17
 declare var interfaceConfig: Object;
@@ -61,8 +63,7 @@ const _INTERCEPT_COMPONENT_RULES = [
61 63
             break;
62 64
 
63 65
         case 'undefined':
64
-            // If webRTCReady is not set, then we cannot use it to take a
65
-            // decision.
66
+            // If webRTCReady is not set, then we cannot base a decision on it.
66 67
             break;
67 68
 
68 69
         default:
@@ -80,19 +81,11 @@ const _INTERCEPT_COMPONENT_RULES = [
80 81
  * @returns {Route}
81 82
  */
82 83
 export function _getRouteToRender(stateOrGetState: Object | Function) {
83
-    const state
84
-        = typeof stateOrGetState === 'function'
85
-            ? stateOrGetState()
86
-            : stateOrGetState;
87
-
88
-    // If mobile browser page was shown, there is no need to show it again.
89
-    const { room } = state['features/base/conference'];
90
-    const component = isRoomValid(room) ? Conference : WelcomePage;
91
-    const route = RouteRegistry.getRouteByComponent(component);
84
+    const route = _super_getRouteToRender(stateOrGetState);
92 85
 
93
-    // Intercepts route components if any of component interceptor rules
94
-    // is satisfied.
95
-    route.component = _interceptComponent(state, component);
86
+    // Intercepts route components if any of component interceptor rules is
87
+    // satisfied.
88
+    route.component = _interceptComponent(stateOrGetState, route.component);
96 89
 
97 90
     return route;
98 91
 }

react/features/welcome/components/BlankWelcomePage.js → react/features/welcome/components/BlankPage.js Wyświetl plik

@@ -5,16 +5,16 @@ import { connect } from 'react-redux';
5 5
 import { destroyLocalTracks } from '../../base/tracks';
6 6
 
7 7
 /**
8
- * Component for rendering a blank welcome page. It renders absolutely nothing
9
- * and destroys local tracks upon being mounted, since no media is desired when
8
+ * A React <tt>Component<tt> which represents a blank page. It renders nothing
9
+ * and destroys local tracks upon being mounted since no media is desired when
10 10
  * this component is rendered.
11 11
  *
12
- * The use case is mainly mobile, where SDK users probably disable the welcome
13
- * page, but using it on the web in the future is not out of the question.
12
+ * The use case which prompted the introduction of this component is mobile
13
+ * where SDK users probably disable the Welcome page.
14 14
  */
15
-class BlankWelcomePage extends Component {
15
+class BlankPage extends Component {
16 16
     /**
17
-     * {@code BlankWelcomePage} component's property types.
17
+     * {@code BlankPage} component's property types.
18 18
      *
19 19
      * @static
20 20
      */
@@ -46,4 +46,4 @@ class BlankWelcomePage extends Component {
46 46
     }
47 47
 }
48 48
 
49
-export default connect()(BlankWelcomePage);
49
+export default connect()(BlankPage);

+ 74
- 0
react/features/welcome/components/Entryway.js Wyświetl plik

@@ -0,0 +1,74 @@
1
+import PropTypes from 'prop-types';
2
+import React, { Component } from 'react';
3
+import { connect } from 'react-redux';
4
+
5
+import BlankPage from './BlankPage';
6
+import WelcomePage from './WelcomePage';
7
+
8
+/**
9
+ * A React <tt>Component</tt> which is rendered when there is no (valid) room
10
+ * (name) i.e. it is the opposite of <tt>Conference</tt>. Generally and
11
+ * historically, it is <tt>WelcomePage</tt>. However, Jitsi Meet SDK for Android
12
+ * and iOS allows the use of the (JavaScript) app without <tt>WelcomePage</tt>
13
+ * and it needs to display something between conferences.
14
+ */
15
+class Entryway extends Component {
16
+    /**
17
+     * <tt>Entryway</tt>'s React <tt>Component</tt> prop types.
18
+     */
19
+    static propTypes = {
20
+        /**
21
+         * The indicator which determines whether <tt>WelcomePage</tt> is (to
22
+         * be) rendered.
23
+         *
24
+         * @private
25
+         */
26
+        _welcomePageEnabled: PropTypes.bool
27
+    };
28
+
29
+    /**
30
+     * Implements React's {@link Component#render()}.
31
+     *
32
+     * @inheritdoc
33
+     * @returns {ReactElement}
34
+     */
35
+    render() {
36
+        return (
37
+            this.props._welcomePageEnabled ? <WelcomePage /> : <BlankPage />
38
+        );
39
+    }
40
+}
41
+
42
+/**
43
+ * Maps (parts of) the redux state to the associated Entryway's props.
44
+ *
45
+ * @param {Object} state - The redux state.
46
+ * @private
47
+ * @returns {{
48
+ *     _welcomePageEnabled: boolean
49
+ * }}
50
+ */
51
+function _mapStateToProps(state) {
52
+    let welcomePageEnabled;
53
+
54
+    if (navigator.product === 'ReactNative') {
55
+        // We introduced the welcomePageEnabled prop on App in Jitsi Meet SDK
56
+        // for Android and iOS. There isn't a strong reason not to introduce it
57
+        // on Web but there're a few considerations to be taken before I go
58
+        // there among which:
59
+        // - Enabling/disabling the Welcome page on Web historically
60
+        // automatically redirects to a random room and that does not make sense
61
+        // on mobile (right now).
62
+        const { app } = state['features/app'];
63
+
64
+        welcomePageEnabled = Boolean(app && app.props.welcomePageEnabled);
65
+    } else {
66
+        welcomePageEnabled = true;
67
+    }
68
+
69
+    return {
70
+        _welcomePageEnabled: welcomePageEnabled
71
+    };
72
+}
73
+
74
+export default connect(_mapStateToProps)(Entryway);

+ 2
- 1
react/features/welcome/components/index.js Wyświetl plik

@@ -1,2 +1,3 @@
1
-export { default as BlankWelcomePage } from './BlankWelcomePage';
1
+export { default as BlankPage } from './BlankPage';
2
+export { default as Entryway } from './Entryway';
2 3
 export { default as WelcomePage } from './WelcomePage';

+ 3
- 12
react/features/welcome/route.js Wyświetl plik

@@ -2,26 +2,17 @@
2 2
 
3 3
 import { RouteRegistry } from '../base/react';
4 4
 
5
-import { BlankWelcomePage, WelcomePage } from './components';
5
+import { Entryway } from './components';
6 6
 import { generateRoomWithoutSeparator } from './roomnameGenerator';
7 7
 
8 8
 declare var APP: Object;
9 9
 declare var config: Object;
10 10
 
11 11
 /**
12
- * Register route for BlankWelcomePage.
12
+ * Register route for Entryway.
13 13
  */
14 14
 RouteRegistry.register({
15
-    component: BlankWelcomePage,
16
-    undefined,
17
-    path: '/#blank'
18
-});
19
-
20
-/**
21
- * Register route for WelcomePage.
22
- */
23
-RouteRegistry.register({
24
-    component: WelcomePage,
15
+    component: Entryway,
25 16
     onEnter,
26 17
     path: '/'
27 18
 });

Ładowanie…
Anuluj
Zapisz