Ver código fonte

Introduce Platform in React

React Native provides a Platform abstraction which React does not
provide.
j8
Lyubomir Marinov 8 anos atrás
pai
commit
62bafcaf63

+ 0
- 11
react/features/app/actionTypes.js Ver arquivo

1
 import { Symbol } from '../base/react';
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
  * The type of the actions which signals that a specific App will mount (in the
4
  * The type of the actions which signals that a specific App will mount (in the
16
  * terms of React).
5
  * terms of React).

+ 9
- 46
react/features/app/actions.js Ver arquivo

1
 import { setRoom } from '../base/conference';
1
 import { setRoom } from '../base/conference';
2
 import { getDomain, setDomain } from '../base/connection';
2
 import { getDomain, setDomain } from '../base/connection';
3
 import { loadConfig, setConfig } from '../base/lib-jitsi-meet';
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
 import {
7
 import {
15
     _getRoomAndDomainFromUrlString,
8
     _getRoomAndDomainFromUrlString,
16
     _getRouteToRender,
9
     _getRouteToRender,
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
  * Navigates to route corresponding to current room name.
131
  * Navigates to route corresponding to current room name.
154
  *
132
  *
163
     app._navigate(routeToRender);
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
  * Sets room and navigates to new route if needed.
145
  * Sets room and navigates to new route if needed.
185
  *
146
  *
194
         dispatch(setRoom(newRoom));
155
         dispatch(setRoom(newRoom));
195
 
156
 
196
         const state = getState();
157
         const state = getState();
197
-        const { platform } = state['features/app'];
198
         const { room } = state['features/base/conference'];
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
             _navigate(state);
167
             _navigate(state);
205
         }
168
         }
206
     };
169
     };

+ 1
- 2
react/features/app/components/App.web.js Ver arquivo

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

+ 16
- 14
react/features/app/functions.web.js Ver arquivo

1
 /* global APP, JitsiMeetJS, loggingConfig */
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
 import URLProcessor from '../../../modules/config/URLProcessor';
10
 import URLProcessor from '../../../modules/config/URLProcessor';
4
 import KeyboardShortcut
11
 import KeyboardShortcut
5
     from '../../../modules/keyboardshortcut/keyboardshortcut';
12
     from '../../../modules/keyboardshortcut/keyboardshortcut';
7
 import getTokenData from '../../../modules/tokendata/TokenData';
14
 import getTokenData from '../../../modules/tokendata/TokenData';
8
 import JitsiMeetLogStorage from '../../../modules/util/JitsiMeetLogStorage';
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
 const Logger = require('jitsi-meet-logger');
17
 const Logger = require('jitsi-meet-logger');
18
 
18
 
19
 export { _getRoomAndDomainFromUrlString } from './functions.native';
19
 export { _getRoomAndDomainFromUrlString } from './functions.native';
27
  * @returns {Route}
27
  * @returns {Route}
28
  */
28
  */
29
 export function _getRouteToRender(stateOrGetState) {
29
 export function _getRouteToRender(stateOrGetState) {
30
+    const OS = Platform.OS;
30
     const state
31
     const state
31
         = typeof stateOrGetState === 'function'
32
         = typeof stateOrGetState === 'function'
32
             ? stateOrGetState()
33
             ? stateOrGetState()
33
             : stateOrGetState;
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
     return RouteRegistry.getRouteByComponent(component);
48
     return RouteRegistry.getRouteByComponent(component);

+ 1
- 12
react/features/app/reducer.js Ver arquivo

1
 import { ReducerRegistry } from '../base/redux';
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
 ReducerRegistry.register('features/app', (state = {}, action) => {
5
 ReducerRegistry.register('features/app', (state = {}, action) => {
10
     switch (action.type) {
6
     switch (action.type) {
32
             };
28
             };
33
         }
29
         }
34
         break;
30
         break;
35
-
36
-    case APP_SET_PLATFORM:
37
-        return {
38
-            ...state,
39
-            platform: action.platform
40
-        };
41
-
42
     }
31
     }
43
 
32
 
44
     return state;
33
     return state;

+ 0
- 17
react/features/base/util/detectDevices.js Ver arquivo

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 Ver arquivo

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

+ 0
- 21
react/features/landing/reducer.js Ver arquivo

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 Ver arquivo


react/features/landing/actions.js → react/features/unsupported-browser/actions.js Ver arquivo


react/features/landing/components/Landing.js → react/features/unsupported-browser/components/Landing.js Ver arquivo

2
 import { connect } from 'react-redux';
2
 import { connect } from 'react-redux';
3
 import { Link } from 'react-router';
3
 import { Link } from 'react-router';
4
 
4
 
5
+import { Platform } from '../../base/react';
6
+
5
 import { landingIsShown } from '../actions';
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
  * @class Landing
21
  * @class Landing
16
  */
22
  */
17
 class Landing extends Component {
23
 class Landing extends Component {
24
+    /**
25
+     * Landing component's property types.
26
+     *
27
+     * @static
28
+     */
18
     static propTypes = {
29
     static propTypes = {
19
         dispatch: React.PropTypes.func,
30
         dispatch: React.PropTypes.func,
20
-        platform: React.PropTypes.string,
21
         room: React.PropTypes.string
31
         room: React.PropTypes.string
22
     }
32
     }
23
 
33
 
59
      * @returns {ReactElement}
69
      * @returns {ReactElement}
60
      */
70
      */
61
     render() {
71
     render() {
62
-        const { platform } = this.props;
63
         const { btnText, link } = this.state;
72
         const { btnText, link } = this.state;
64
         const primaryButtonClasses = 'landing__button landing__button_primary';
73
         const primaryButtonClasses = 'landing__button landing__button_primary';
65
 
74
 
70
                         className = 'landing__logo'
79
                         className = 'landing__logo'
71
                         src = '/images/logo-blue.svg' />
80
                         src = '/images/logo-blue.svg' />
72
                     <p className = 'landing__text'>
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
                     </p>
84
                     </p>
76
-                    <a href = { LINKS[platform] }>
77
-                        <button
78
-                            className = { primaryButtonClasses }>
85
+                    <a href = { URLS[Platform.OS] }>
86
+                        <button className = { primaryButtonClasses }>
79
                             Download the App
87
                             Download the App
80
                         </button>
88
                         </button>
81
                     </a>
89
                     </a>
82
                     <p className = 'landing__text landing__text_small'>
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
                     </p>
94
                     </p>
86
                     <Link to = { link }>
95
                     <Link to = { link }>
87
-                        <button
88
-                            className = 'landing__button'>{ btnText }</button>
96
+                        <button className = 'landing__button'>
97
+                            { btnText }
98
+                        </button>
89
                     </Link>
99
                     </Link>
90
                 </div>
100
                 </div>
91
             </div>
101
             </div>
98
  *
108
  *
99
  * @param {Object} state - Redux state.
109
  * @param {Object} state - Redux state.
100
  * @returns {{
110
  * @returns {{
101
- *     platform: string,
102
  *     room: string
111
  *     room: string
103
  * }}
112
  * }}
104
  */
113
  */
105
 function mapStateToProps(state) {
114
 function mapStateToProps(state) {
106
     return {
115
     return {
107
-        platform: state['features/app'].platform,
108
         room: state['features/base/conference'].room
116
         room: state['features/base/conference'].room
109
     };
117
     };
110
 }
118
 }

react/features/landing/components/index.js → react/features/unsupported-browser/components/index.js Ver arquivo


react/features/landing/index.js → react/features/unsupported-browser/index.js Ver arquivo


+ 23
- 0
react/features/unsupported-browser/reducer.js Ver arquivo

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 Ver arquivo


Carregando…
Cancelar
Salvar