Переглянути джерело

Comply w/ coding style

master
Lyubomir Marinov 8 роки тому
джерело
коміт
e29db31d91

+ 1
- 1
react/features/app/components/App.native.js Переглянути файл

@@ -2,9 +2,9 @@
2 2
 
3 3
 import { Linking } from 'react-native';
4 4
 
5
-import { Platform } from '../../base/react';
6 5
 import '../../audio-mode';
7 6
 import '../../background';
7
+import { Platform } from '../../base/react';
8 8
 import '../../full-screen';
9 9
 import '../../wake-lock';
10 10
 

+ 9
- 10
react/features/background/actionTypes.js Переглянути файл

@@ -1,38 +1,36 @@
1 1
 import { Symbol } from '../base/react';
2 2
 
3 3
 /**
4
- * Action to set the AppState API change event listener.
4
+ * The type of redux action to set the AppState API change event listener.
5 5
  *
6 6
  * {
7 7
  *      type: _SET_APP_STATE_LISTENER,
8 8
  *      listener: Function
9 9
  * }
10 10
  *
11
- * @private
11
+ * @protected
12 12
  */
13 13
 export const _SET_APP_STATE_LISTENER
14 14
     = Symbol('_SET_APP_STATE_LISTENER');
15 15
 
16 16
 /**
17
- * Action to signal video will be muted because the app is going to the
18
- * background.
17
+ * The type of redux action which signals that video will be muted because the
18
+ * app is going to the background.
19 19
  *
20 20
  * {
21 21
  *      type: _SET_BACKGROUND_VIDEO_MUTED,
22 22
  *      muted: boolean
23 23
  * }
24 24
  *
25
- * @private
25
+ * @protected
26 26
  */
27 27
 export const _SET_BACKGROUND_VIDEO_MUTED
28 28
     = Symbol('_SET_BACKGROUND_VIDEO_MUTED');
29 29
 
30 30
 /**
31
- * Action which signals that the App state has changed (in terms
32
- * of execution mode).
33
- *
34
- * The application state can be one of 'active', 'inactive' or 'background',
35
- * see: https://facebook.github.io/react-native/docs/appstate.html
31
+ * The type of redux action which signals that the app state has changed (in
32
+ * terms of execution mode). The app state can be one of 'active', 'inactive',
33
+ * or 'background'.
36 34
  *
37 35
  * {
38 36
  *      type: APP_STATE_CHANGED,
@@ -40,5 +38,6 @@ export const _SET_BACKGROUND_VIDEO_MUTED
40 38
  * }
41 39
  *
42 40
  * @public
41
+ * @see {@link https://facebook.github.io/react-native/docs/appstate.html}
43 42
  */
44 43
 export const APP_STATE_CHANGED = Symbol('APP_STATE_CHANGED');

+ 37
- 55
react/features/background/actions.js Переглянути файл

@@ -1,22 +1,24 @@
1
+import { setVideoMuted } from '../base/media';
2
+
1 3
 import {
2 4
     _SET_APP_STATE_LISTENER,
3 5
     _SET_BACKGROUND_VIDEO_MUTED,
4 6
     APP_STATE_CHANGED
5 7
 } from './actionTypes';
6
-import { setVideoMuted } from '../base/media';
7
-
8
+import './middleware';
9
+import './reducer';
8 10
 
9 11
 /**
10
- * Signals that the App state has changed (in terms of execution mode). The
12
+ * Signals that the App state has changed (in terms of execution state). The
11 13
  * application can be in 3 states: 'active', 'inactive' and 'background'.
12 14
  *
13
- * @see https://facebook.github.io/react-native/docs/appstate.html
14
- *
15
- * @param  {string} appState - The new App state.
15
+ * @param {string} appState - The new App state.
16
+ * @public
16 17
  * @returns {{
17 18
  *      type: APP_STATE_CHANGED,
18 19
  *      appState: string
19 20
  * }}
21
+ * @see {@link https://facebook.github.io/react-native/docs/appstate.html}
20 22
  */
21 23
 export function appStateChanged(appState: string) {
22 24
     return {
@@ -25,20 +27,34 @@ export function appStateChanged(appState: string) {
25 27
     };
26 28
 }
27 29
 
28
-
29 30
 /**
30
- * Signals that the app should mute video because it's now running in
31
- * the background, or unmute it, if it came back from the background.
31
+ * Sets the listener to be used with React Native's AppState API.
32 32
  *
33
- * If video was already muted nothing will happen, otherwise it will be
34
- * muted. When coming back from the background the previous state will
35
- * be restored.
33
+ * @param {Function} listener - Function to be set as the change event listener.
34
+ * @protected
35
+ * @returns {{
36
+ *     type: _SET_APP_STATE_LISTENER,
37
+ *     listener: Function
38
+ * }}
39
+ */
40
+export function _setAppStateListener(listener: ?Function) {
41
+    return {
42
+        type: _SET_APP_STATE_LISTENER,
43
+        listener
44
+    };
45
+}
46
+
47
+/**
48
+ * Signals that the app should mute video because it's now running in the
49
+ * background, or unmute it because it came back from the background. If video
50
+ * was already muted nothing will happen; otherwise, it will be muted. When
51
+ * coming back from the background the previous state will be restored.
36 52
  *
37
- * @param  {boolean} muted - Set to true if video should be muted, false
38
- * otherwise.
53
+ * @param {boolean} muted - True if video should be muted; false, otherwise.
54
+ * @protected
39 55
  * @returns {Function}
40 56
  */
41
-export function setBackgroundVideoMuted(muted: boolean) {
57
+export function _setBackgroundVideoMuted(muted: boolean) {
42 58
     return (dispatch, getState) => {
43 59
         if (muted) {
44 60
             const mediaState = getState()['features/base/media'];
@@ -56,46 +72,12 @@ export function setBackgroundVideoMuted(muted: boolean) {
56 72
             }
57 73
         }
58 74
 
59
-        dispatch(_setBackgroundVideoMuted(muted));
75
+        // Remember that video was muted due to the app going to the background
76
+        // vs user's choice.
77
+        dispatch({
78
+            type: _SET_BACKGROUND_VIDEO_MUTED,
79
+            muted
80
+        });
60 81
         dispatch(setVideoMuted(muted));
61 82
     };
62 83
 }
63
-
64
-
65
-/**
66
- * Internal action which sets the listener to be used with React Native's
67
- * AppState API.
68
- *
69
- * @param  {Function} listener - Function to be set as the change event
70
- * listener.
71
- * @returns {{
72
- *      type: _SET_APP_STATE_LISTENER,
73
- *      listener: Function
74
- * }}
75
- */
76
-export function _setAppStateListener(listener: ?Function) {
77
-    return {
78
-        type: _SET_APP_STATE_LISTENER,
79
-        listener
80
-    };
81
-}
82
-
83
-
84
-/**
85
- * Internal action which signals that video is going to be muted because the
86
- * application is going to the background. This action is used to remember if
87
- * video was muted due to the app going to the background vs user's choice.
88
- *
89
- * @param  {type} muted - Set to true if video will be muted, false otherwise.
90
- * @private
91
- * @returns {{
92
- *      type: _SET_BACKGROUND_VIDEO_MUTED,
93
- *      muted: boolean
94
- * }}
95
- */
96
-function _setBackgroundVideoMuted(muted: boolean) {
97
-    return {
98
-        type: _SET_BACKGROUND_VIDEO_MUTED,
99
-        muted
100
-    };
101
-}

+ 1
- 2
react/features/background/index.js Переглянути файл

@@ -1,3 +1,2 @@
1
+export * from './actions';
1 2
 export * from './actionTypes';
2
-import './middleware';
3
-import './reducer';

+ 49
- 36
react/features/background/middleware.js Переглянути файл

@@ -3,56 +3,59 @@
3 3
 import { AppState } from 'react-native';
4 4
 import type { Dispatch } from 'redux';
5 5
 
6
+import {
7
+    APP_WILL_MOUNT,
8
+    APP_WILL_UNMOUNT
9
+} from '../app';
10
+import { MiddlewareRegistry } from '../base/redux';
11
+
6 12
 import {
7 13
     _setAppStateListener,
8
-    appStateChanged,
9
-    setBackgroundVideoMuted
14
+    _setBackgroundVideoMuted,
15
+    appStateChanged
10 16
 } from './actions';
11 17
 import {
12 18
     _SET_APP_STATE_LISTENER,
13 19
     APP_STATE_CHANGED
14 20
 } from './actionTypes';
15 21
 
16
-import {
17
-    APP_WILL_MOUNT,
18
-    APP_WILL_UNMOUNT
19
-} from '../app';
20
-import { MiddlewareRegistry } from '../base/redux';
21
-
22
-
23 22
 /**
24 23
  * Middleware that captures App lifetime actions and subscribes to application
25 24
  * state changes. When the application state changes it will fire the action
26
- * requred to mute or unmute the local video in case the application goes to
27
- * the backgound or comes back from it.
25
+ * required to mute or unmute the local video in case the application goes to
26
+ * the background or comes back from it.
28 27
  *
29
- * @see https://facebook.github.io/react-native/docs/appstate.html
30 28
  * @param {Store} store - Redux store.
31 29
  * @returns {Function}
30
+ * @see {@link https://facebook.github.io/react-native/docs/appstate.html}
32 31
  */
33 32
 MiddlewareRegistry.register(store => next => action => {
34 33
     switch (action.type) {
35 34
     case _SET_APP_STATE_LISTENER: {
35
+        // Remove the current/old AppState listener.
36 36
         const { appStateListener } = store.getState()['features/background'];
37 37
 
38 38
         if (appStateListener) {
39 39
             AppState.removeEventListener('change', appStateListener);
40 40
         }
41
+
42
+        // Add the new AppState listener.
41 43
         if (action.listener) {
42 44
             AppState.addEventListener('change', action.listener);
43 45
         }
44 46
         break;
45 47
     }
48
+
46 49
     case APP_STATE_CHANGED:
47
-        _handleAppStateChange(store.dispatch, action.appState);
50
+        _appStateChanged(store.dispatch, action.appState);
48 51
         break;
49
-    case APP_WILL_MOUNT: {
50
-        const listener
51
-            = __onAppStateChanged.bind(undefined, store.dispatch);
52 52
 
53
-        store.dispatch(_setAppStateListener(listener));
53
+    case APP_WILL_MOUNT:
54
+        store.dispatch(
55
+                _setAppStateListener(
56
+                        _onAppStateChange.bind(undefined, store.dispatch)));
54 57
         break;
55
-    }
58
+
56 59
     case APP_WILL_UNMOUNT:
57 60
         store.dispatch(_setAppStateListener(null));
58 61
         break;
@@ -61,36 +64,46 @@ MiddlewareRegistry.register(store => next => action => {
61 64
     return next(action);
62 65
 });
63 66
 
64
-
65 67
 /**
66
- * Handler for app state changes. If will fire the necessary actions for
67
- * local video to be muted when the app goes to the background, and to
68
- * unmute it when it comes back.
68
+ * Handles app state changes. Dispatches the necessary Redux actions for the
69
+ * local video to be muted when the app goes to the background, and to be
70
+ * unmuted when the app comes back.
69 71
  *
70
- * @param  {Dispatch} dispatch - Redux dispatch function.
71
- * @param  {string} appState - Current app state.
72
+ * @param {Dispatch} dispatch - Redux dispatch function.
73
+ * @param {string} appState - The current app state.
72 74
  * @private
73 75
  * @returns {void}
74 76
  */
75
-function _handleAppStateChange(dispatch: Dispatch<*>, appState: string) {
76
-    // XXX: we purposely don't handle the 'inactive' state.
77
-    if (appState === 'background') {
78
-        dispatch(setBackgroundVideoMuted(true));
79
-    } else if (appState === 'active') {
80
-        dispatch(setBackgroundVideoMuted(false));
77
+function _appStateChanged(dispatch: Dispatch<*>, appState: string) {
78
+    let muted;
79
+
80
+    switch (appState) {
81
+    case 'active':
82
+        muted = false;
83
+        break;
84
+
85
+    case 'background':
86
+        muted = true;
87
+        break;
88
+
89
+    case 'inactive':
90
+    default:
91
+        // XXX: We purposely don't handle the 'inactive' app state.
92
+        return;
81 93
     }
82
-}
83 94
 
95
+    dispatch(_setBackgroundVideoMuted(muted));
96
+}
84 97
 
85 98
 /**
86
- * Handler called by React's AppState API indicating that the application state
87
- * has changed.
99
+ * Called by React Native's AppState API to notify that the application state
100
+ * has changed. Dispatches the change within the (associated) Redux store.
88 101
  *
89
- * @param  {Dispatch} dispatch - Redux dispatch function.
90
- * @param  {string} appState - The current application execution state.
102
+ * @param {Dispatch} dispatch - Redux dispatch function.
103
+ * @param {string} appState - The current application execution state.
91 104
  * @private
92 105
  * @returns {void}
93 106
  */
94
-function __onAppStateChanged(dispatch: Dispatch<*>, appState: string) {
107
+function _onAppStateChange(dispatch: Dispatch<*>, appState: string) {
95 108
     dispatch(appStateChanged(appState));
96 109
 }

+ 2
- 2
react/features/background/reducer.js Переглянути файл

@@ -1,10 +1,10 @@
1
+import { ReducerRegistry } from '../base/redux';
2
+
1 3
 import {
2 4
     _SET_APP_STATE_LISTENER,
3 5
     _SET_BACKGROUND_VIDEO_MUTED,
4 6
     APP_STATE_CHANGED
5 7
 } from './actionTypes';
6
-import { ReducerRegistry } from '../base/redux';
7
-
8 8
 
9 9
 ReducerRegistry.register('features/background', (state = {}, action) => {
10 10
     switch (action.type) {

Завантаження…
Відмінити
Зберегти