Explorar el Código

ref(mobile/wake-lock): convert middleware to a state listener

If CONFERENCE_LEFT would arrive with a delay while we're in
another conference already, then the wake lock could end up in
an incorrect state.
j8
paweldomas hace 7 años
padre
commit
701552ec8f
Se han modificado 1 ficheros con 12 adiciones y 33 borrados
  1. 12
    33
      react/features/mobile/wake-lock/middleware.js

+ 12
- 33
react/features/mobile/wake-lock/middleware.js Ver fichero

1
 import KeepAwake from 'react-native-keep-awake';
1
 import KeepAwake from 'react-native-keep-awake';
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 that captures conference actions and activates or deactivates the
13
- * wake lock accordingly. If the wake lock is active, it will prevent the screen
14
- * from dimming.
15
- *
16
- * @param {Store} store - Redux store.
17
- * @returns {Function}
7
+ * State listener that activates or deactivates the wake lock accordingly. If
8
+ * the wake lock is active, it will prevent the screen from dimming.
18
  */
9
  */
19
-MiddlewareRegistry.register(store => next => action => {
20
-    switch (action.type) {
21
-    case CONFERENCE_JOINED: {
22
-        const { audioOnly } = store.getState()['features/base/conference'];
23
-
24
-        _setWakeLock(!audioOnly);
25
-        break;
26
-    }
27
-
28
-    case CONFERENCE_FAILED:
29
-    case CONFERENCE_LEFT:
30
-        _setWakeLock(false);
31
-        break;
32
-
33
-    case SET_AUDIO_ONLY:
34
-        _setWakeLock(!action.audioOnly);
35
-        break;
36
-    }
10
+StateListenerRegistry.register(
11
+    /* selector */ state => {
12
+        const { audioOnly } = state['features/base/conference'];
13
+        const conference = getCurrentConference(state);
37
 
14
 
38
-    return next(action);
39
-});
15
+        return Boolean(conference && !audioOnly);
16
+    },
17
+    /* listener */ wakeLock => _setWakeLock(wakeLock)
18
+);
40
 
19
 
41
 /**
20
 /**
42
  * Activates/deactivates the wake lock. If the wake lock is active, it will
21
  * Activates/deactivates the wake lock. If the wake lock is active, it will

Loading…
Cancelar
Guardar