ソースを参照

ref(mobile/proximity): convert middleware to a state listener

j8
paweldomas 7年前
コミット
d26d1ff925
1個のファイルの変更12行の追加32行の削除
  1. 12
    32
      react/features/mobile/proximity/middleware.js

+ 12
- 32
react/features/mobile/proximity/middleware.js ファイルの表示

@@ -1,43 +1,23 @@
1 1
 import { NativeModules } from 'react-native';
2 2
 
3
-import {
4
-    CONFERENCE_FAILED,
5
-    CONFERENCE_JOINED,
6
-    CONFERENCE_LEFT,
7
-    SET_AUDIO_ONLY
8
-} from '../../base/conference';
9
-import { MiddlewareRegistry } from '../../base/redux';
3
+import { getCurrentConference } from '../../base/conference';
4
+import { StateListenerRegistry } from '../../base/redux';
10 5
 
11 6
 /**
12
- * Middleware which enables / disables the proximity sensor in accord with
13
- * conference-related actions. If the proximity sensor is enabled, it will dim
7
+ * State listener which enables / disables the proximity sensor based on the
8
+ * current conference state. If the proximity sensor is enabled, it will dim
14 9
  * the screen and disable touch controls when an object is nearby. The
15 10
  * functionality is  enabled when a conference is in audio-only mode.
16
- *
17
- * @param {Store} store - The redux store.
18
- * @returns {Function}
19 11
  */
20
-MiddlewareRegistry.register(({ getState }) => next => action => {
21
-    const result = next(action);
22
-
23
-    switch (action.type) {
24
-    case CONFERENCE_FAILED:
25
-    case CONFERENCE_LEFT:
26
-        _setProximityEnabled(false);
27
-        break;
28
-
29
-    case CONFERENCE_JOINED:
30
-    case SET_AUDIO_ONLY: {
31
-        const { audioOnly, conference }
32
-            = getState()['features/base/conference'];
33
-
34
-        conference && _setProximityEnabled(audioOnly);
35
-        break;
36
-    }
37
-    }
12
+StateListenerRegistry.register(
13
+    /* selector */ state => {
14
+        const { audioOnly } = state['features/base/conference'];
15
+        const conference = getCurrentConference(state);
38 16
 
39
-    return result;
40
-});
17
+        return Boolean(conference && audioOnly);
18
+    },
19
+    /* listener */ proximityEnabled => _setProximityEnabled(proximityEnabled)
20
+);
41 21
 
42 22
 /**
43 23
  * Enables / disables the proximity sensor. If the proximity sensor is enabled,

読み込み中…
キャンセル
保存