Browse Source

Introduce Platform in React

React Native provides a Platform abstraction which React does not
provide.
j8
Lyubomir Marinov 8 years ago
parent
commit
62bafcaf63

+ 0
- 11
react/features/app/actionTypes.js View File

@@ -1,16 +1,5 @@
1 1
 import { Symbol } from '../base/react';
2 2
 
3
-/**
4
- * The type of this action sets the platform of user agent in order to decide to
5
- * show the landing or not.
6
- *
7
- * {
8
- *      type: APP_SET_PLATFORM,
9
- *      platform: string
10
- * }
11
- */
12
-export const APP_SET_PLATFORM = Symbol('APP_SET_PLATFORM');
13
-
14 3
 /**
15 4
  * The type of the actions which signals that a specific App will mount (in the
16 5
  * terms of React).

+ 9
- 46
react/features/app/actions.js View File

@@ -1,16 +1,9 @@
1 1
 import { setRoom } from '../base/conference';
2 2
 import { getDomain, setDomain } from '../base/connection';
3 3
 import { loadConfig, setConfig } from '../base/lib-jitsi-meet';
4
-import {
5
-    detectAndroid,
6
-    detectIOS
7
-} from '../base/util';
4
+import { Platform } from '../base/react';
8 5
 
9
-import {
10
-    APP_WILL_MOUNT,
11
-    APP_WILL_UNMOUNT,
12
-    APP_SET_PLATFORM
13
-} from './actionTypes';
6
+import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes';
14 7
 import {
15 8
     _getRoomAndDomainFromUrlString,
16 9
     _getRouteToRender,
@@ -134,21 +127,6 @@ export function appWillUnmount(app) {
134 127
     };
135 128
 }
136 129
 
137
-/**
138
- * Detects the platform of user agent and signals that platform detected.
139
- *
140
- * @returns {Function}
141
- */
142
-export function detectPlatform() {
143
-    return dispatch => {
144
-        if (detectAndroid()) {
145
-            dispatch(_setPlatform('android'));
146
-        } else if (detectIOS()) {
147
-            dispatch(_setPlatform('ios'));
148
-        }
149
-    };
150
-}
151
-
152 130
 /**
153 131
  * Navigates to route corresponding to current room name.
154 132
  *
@@ -163,23 +141,6 @@ function _navigate(state) {
163 141
     app._navigate(routeToRender);
164 142
 }
165 143
 
166
-/**
167
- * Signals that user agent platform is mobile and it has been already detected.
168
- *
169
- * @param {string} platform - Mobile user agent platform.
170
- * @returns {{
171
- *     type: APP_SET_PLATFORM,
172
- *     platform: string
173
- * }}
174
- * @private
175
- */
176
-function _setPlatform(platform) {
177
-    return {
178
-        type: APP_SET_PLATFORM,
179
-        platform
180
-    };
181
-}
182
-
183 144
 /**
184 145
  * Sets room and navigates to new route if needed.
185 146
  *
@@ -194,13 +155,15 @@ function _setRoomAndNavigate(newRoom) {
194 155
         dispatch(setRoom(newRoom));
195 156
 
196 157
         const state = getState();
197
-        const { platform } = state['features/app'];
198 158
         const { room } = state['features/base/conference'];
199
-        const { landingIsShown } = state['features/landing'];
159
+        const { landingIsShown } = state['features/unsupported-browser'];
160
+
161
+        // If the user agent is a mobile browser and landing hasn't been shown
162
+        // yet, we should recheck which component to render.
163
+        const OS = Platform.OS;
200 164
 
201
-        // If user agent is mobile browser and landing wasn't shown we
202
-        // should recheck which component to render.
203
-        if ((platform && !landingIsShown) || room !== oldRoom) {
165
+        if (((OS === 'android' || OS === 'ios') && !landingIsShown)
166
+                || room !== oldRoom) {
204 167
             _navigate(state);
205 168
         }
206 169
     };

+ 1
- 2
react/features/app/components/App.web.js View File

@@ -1,4 +1,4 @@
1
-import { appInit, detectPlatform } from '../actions';
1
+import { appInit } from '../actions';
2 2
 import { AbstractApp } from './AbstractApp';
3 3
 
4 4
 /**
@@ -22,7 +22,6 @@ export class App extends AbstractApp {
22 22
     componentWillMount(...args) {
23 23
         super.componentWillMount(...args);
24 24
 
25
-        this.props.store.dispatch(detectPlatform());
26 25
         this.props.store.dispatch(appInit());
27 26
     }
28 27
 

+ 16
- 14
react/features/app/functions.web.js View File

@@ -1,5 +1,12 @@
1 1
 /* global APP, JitsiMeetJS, loggingConfig */
2 2
 
3
+import { isRoomValid } from '../base/conference';
4
+import { RouteRegistry } from '../base/navigator';
5
+import { Platform } from '../base/react';
6
+import { Conference } from '../conference';
7
+import { Landing } from '../unsupported-browser';
8
+import { WelcomePage } from '../welcome';
9
+
3 10
 import URLProcessor from '../../../modules/config/URLProcessor';
4 11
 import KeyboardShortcut
5 12
     from '../../../modules/keyboardshortcut/keyboardshortcut';
@@ -7,13 +14,6 @@ import settings from '../../../modules/settings/Settings';
7 14
 import getTokenData from '../../../modules/tokendata/TokenData';
8 15
 import JitsiMeetLogStorage from '../../../modules/util/JitsiMeetLogStorage';
9 16
 
10
-import { detectIOS, detectAndroid } from '../base/util';
11
-
12
-// XXX We should import landing feature here in order to update router registry.
13
-import { Landing } from '../landing';
14
-import { Conference } from '../conference';
15
-import { WelcomePage } from '../welcome';
16
-
17 17
 const Logger = require('jitsi-meet-logger');
18 18
 
19 19
 export { _getRoomAndDomainFromUrlString } from './functions.native';
@@ -27,20 +27,22 @@ export { _getRoomAndDomainFromUrlString } from './functions.native';
27 27
  * @returns {Route}
28 28
  */
29 29
 export function _getRouteToRender(stateOrGetState) {
30
+    const OS = Platform.OS;
30 31
     const state
31 32
         = typeof stateOrGetState === 'function'
32 33
             ? stateOrGetState()
33 34
             : stateOrGetState;
34 35
 
35
-    const { platform } = state['features/app'];
36
-    const { room } = state['features/base/conference'];
37
-    const { landingIsShown } = state['features/landing'];
36
+    // If landing was shown, there is no need to show it again.
37
+    const { landingIsShown } = state['features/unsupported-browser'];
38
+    let component;
38 39
 
39
-    let component = isRoomValid(room) ? Conference : WelcomePage;
40
+    if ((OS === 'android' || OS === 'ios') && !landingIsShown) {
41
+        component = Landing;
42
+    } else {
43
+        const { room } = state['features/base/conference'];
40 44
 
41
-    // If landing was shown there is no need to show it again.
42
-    if (platform && !landingIsShown) {
43
-        component = detectAndroid() || detectIOS() ? Landing : component;
45
+        component = isRoomValid(room) ? Conference : WelcomePage;
44 46
     }
45 47
 
46 48
     return RouteRegistry.getRouteByComponent(component);

+ 1
- 12
react/features/app/reducer.js View File

@@ -1,10 +1,6 @@
1 1
 import { ReducerRegistry } from '../base/redux';
2 2
 
3
-import {
4
-    APP_WILL_MOUNT,
5
-    APP_WILL_UNMOUNT,
6
-    APP_SET_PLATFORM
7
-} from './actionTypes';
3
+import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes';
8 4
 
9 5
 ReducerRegistry.register('features/app', (state = {}, action) => {
10 6
     switch (action.type) {
@@ -32,13 +28,6 @@ ReducerRegistry.register('features/app', (state = {}, action) => {
32 28
             };
33 29
         }
34 30
         break;
35
-
36
-    case APP_SET_PLATFORM:
37
-        return {
38
-            ...state,
39
-            platform: action.platform
40
-        };
41
-
42 31
     }
43 32
 
44 33
     return state;

+ 0
- 17
react/features/base/util/detectDevices.js View File

@@ -1,17 +0,0 @@
1
-/**
2
- * Returns true if user agent is run on Android.
3
- *
4
- * @returns {boolean}
5
- */
6
-export function detectAndroid() {
7
-    return Boolean(navigator.userAgent.match(/Android/i));
8
-}
9
-
10
-/**
11
- * Returns true if user agent is run on iOS.
12
- *
13
- * @returns {boolean}
14
- */
15
-export function detectIOS() {
16
-    return Boolean(navigator.userAgent.match(/iP(ad|hone|od)/i));
17
-}

+ 0
- 1
react/features/base/util/index.js View File

@@ -1,3 +1,2 @@
1
-export * from './detectDevices';
2 1
 export * from './loadScript';
3 2
 export * from './roomnameGenerator';

+ 0
- 21
react/features/landing/reducer.js View File

@@ -1,21 +0,0 @@
1
-import { ReducerRegistry } from '../base/redux';
2
-
3
-import { LANDING_IS_SHOWN } from './actionTypes';
4
-
5
-ReducerRegistry.register('features/landing', (state = {}, action) => {
6
-    switch (action.type) {
7
-    case LANDING_IS_SHOWN:
8
-        return {
9
-            ...state,
10
-
11
-            /**
12
-             * Flag that shows that mobile landing is shown.
13
-             *
14
-             * @type {boolean}
15
-             */
16
-            landingIsShown: true
17
-        };
18
-    }
19
-
20
-    return state;
21
-});

react/features/landing/actionTypes.js → react/features/unsupported-browser/actionTypes.js View File


react/features/landing/actions.js → react/features/unsupported-browser/actions.js View File


react/features/landing/components/Landing.js → react/features/unsupported-browser/components/Landing.js View File

@@ -2,11 +2,17 @@ import React, { Component } from 'react';
2 2
 import { connect } from 'react-redux';
3 3
 import { Link } from 'react-router';
4 4
 
5
+import { Platform } from '../../base/react';
6
+
5 7
 import { landingIsShown } from '../actions';
6 8
 
7
-const LINKS = {
8
-    'android': 'https://play.google.com/store/apps/details?id=org.jitsi.meet',
9
-    'ios': 'https://itunes.apple.com/us/app/jitsi-meet/id1165103905'
9
+/**
10
+ * The map of platforms to URLs at which the mobile app for the associated
11
+ * platform is available for download.
12
+ */
13
+const URLS = {
14
+    android: 'https://play.google.com/store/apps/details?id=org.jitsi.meet',
15
+    ios: 'https://itunes.apple.com/us/app/jitsi-meet/id1165103905'
10 16
 };
11 17
 
12 18
 /**
@@ -15,9 +21,13 @@ const LINKS = {
15 21
  * @class Landing
16 22
  */
17 23
 class Landing extends Component {
24
+    /**
25
+     * Landing component's property types.
26
+     *
27
+     * @static
28
+     */
18 29
     static propTypes = {
19 30
         dispatch: React.PropTypes.func,
20
-        platform: React.PropTypes.string,
21 31
         room: React.PropTypes.string
22 32
     }
23 33
 
@@ -59,7 +69,6 @@ class Landing extends Component {
59 69
      * @returns {ReactElement}
60 70
      */
61 71
     render() {
62
-        const { platform } = this.props;
63 72
         const { btnText, link } = this.state;
64 73
         const primaryButtonClasses = 'landing__button landing__button_primary';
65 74
 
@@ -70,22 +79,23 @@ class Landing extends Component {
70 79
                         className = 'landing__logo'
71 80
                         src = '/images/logo-blue.svg' />
72 81
                     <p className = 'landing__text'>
73
-                       You need <strong>Jitsi Meet</strong> to join a
74
-                       conversation on your mobile
82
+                        You need <strong>Jitsi Meet</strong> to join a
83
+                        conversation on your mobile
75 84
                     </p>
76
-                    <a href = { LINKS[platform] }>
77
-                        <button
78
-                            className = { primaryButtonClasses }>
85
+                    <a href = { URLS[Platform.OS] }>
86
+                        <button className = { primaryButtonClasses }>
79 87
                             Download the App
80 88
                         </button>
81 89
                     </a>
82 90
                     <p className = 'landing__text landing__text_small'>
83
-                       or if you already have it
84
-                       <br /><strong>then</strong>
91
+                        or if you already have it
92
+                        <br />
93
+                        <strong>then</strong>
85 94
                     </p>
86 95
                     <Link to = { link }>
87
-                        <button
88
-                            className = 'landing__button'>{ btnText }</button>
96
+                        <button className = 'landing__button'>
97
+                            { btnText }
98
+                        </button>
89 99
                     </Link>
90 100
                 </div>
91 101
             </div>
@@ -98,13 +108,11 @@ class Landing extends Component {
98 108
  *
99 109
  * @param {Object} state - Redux state.
100 110
  * @returns {{
101
- *     platform: string,
102 111
  *     room: string
103 112
  * }}
104 113
  */
105 114
 function mapStateToProps(state) {
106 115
     return {
107
-        platform: state['features/app'].platform,
108 116
         room: state['features/base/conference'].room
109 117
     };
110 118
 }

react/features/landing/components/index.js → react/features/unsupported-browser/components/index.js View File


react/features/landing/index.js → react/features/unsupported-browser/index.js View File


+ 23
- 0
react/features/unsupported-browser/reducer.js View File

@@ -0,0 +1,23 @@
1
+import { ReducerRegistry } from '../base/redux';
2
+
3
+import { LANDING_IS_SHOWN } from './actionTypes';
4
+
5
+ReducerRegistry.register(
6
+        'features/unsupported-browser',
7
+        (state = {}, action) => {
8
+            switch (action.type) {
9
+            case LANDING_IS_SHOWN:
10
+                return {
11
+                    ...state,
12
+
13
+                    /**
14
+                     * Flag that shows that mobile landing is shown.
15
+                     *
16
+                     * @type {boolean}
17
+                     */
18
+                    landingIsShown: true
19
+                };
20
+            }
21
+
22
+            return state;
23
+        });

react/features/landing/route.js → react/features/unsupported-browser/route.js View File


Loading…
Cancel
Save