Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

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

paweldomas701552ec8f21
diff --git a/react/features/mobile/wake-lock/middleware.js b/react/features/mobile/wake-lock/middleware.js
index 1071c1c51f..08b4b75466 100644
--- a/react/features/mobile/wake-lock/middleware.js
+++ b/react/features/mobile/wake-lock/middleware.js
@@ -1,42 +1,21 @@
import KeepAwake from 'react-native-keep-awake';
-import {
- CONFERENCE_FAILED,
- CONFERENCE_JOINED,
- CONFERENCE_LEFT,
- SET_AUDIO_ONLY
-} from '../../base/conference';
-import { MiddlewareRegistry } from '../../base/redux';
+import { getCurrentConference } from '../../base/conference';
+import { StateListenerRegistry } from '../../base/redux';
/**
- * Middleware that captures conference actions and activates or deactivates the
- * wake lock accordingly. If the wake lock is active, it will prevent the screen
- * from dimming.
- *
- * @param {Store} store - Redux store.
- * @returns {Function}
+ * State listener that activates or deactivates the wake lock accordingly. If
+ * the wake lock is active, it will prevent the screen from dimming.
*/
-MiddlewareRegistry.register(store => next => action => {
- switch (action.type) {
- case CONFERENCE_JOINED: {
- const { audioOnly } = store.getState()['features/base/conference'];
-
- _setWakeLock(!audioOnly);
- break;
- }
-
- case CONFERENCE_FAILED:
- case CONFERENCE_LEFT:
- _setWakeLock(false);
- break;
-
- case SET_AUDIO_ONLY:
- _setWakeLock(!action.audioOnly);
- break;
- }
+StateListenerRegistry.register(
+ /* selector */ state => {
+ const { audioOnly } = state['features/base/conference'];
+ const conference = getCurrentConference(state);
- return next(action);
-});
+ return Boolean(conference && !audioOnly);
+ },
+ /* listener */ wakeLock => _setWakeLock(wakeLock)
+);
/**
* Activates/deactivates the wake lock. If the wake lock is active, it will