Quellcode durchsuchen

Listens for suspend events from jitsi-power-monitor on postis channel. (#4428)

* Listens for suspend events from jitsi-power-monitor on postis channel.

* Removes duplicated type and actions.

* Moves suspendDetected state from overlay to power-monitor feature.
j8
Дамян Минков vor 5 Jahren
Ursprung
Commit
9071cd4813
Es ist kein Account mit der E-Mail-Adresse des Committers verbunden

+ 23
- 31
conference.js Datei anzeigen

@@ -114,10 +114,8 @@ import {
114 114
     maybeOpenFeedbackDialog,
115 115
     submitFeedback
116 116
 } from './react/features/feedback';
117
-import {
118
-    mediaPermissionPromptVisibilityChanged,
119
-    suspendDetected
120
-} from './react/features/overlay';
117
+import { mediaPermissionPromptVisibilityChanged } from './react/features/overlay';
118
+import { suspendDetected } from './react/features/power-monitor';
121 119
 import { setSharedVideoStatus } from './react/features/shared-video';
122 120
 import { isButtonEnabled } from './react/features/toolbox';
123 121
 import { endpointMessageReceived } from './react/features/subtitles';
@@ -1932,33 +1930,6 @@ export default {
1932 1930
 
1933 1931
         room.on(JitsiConferenceEvents.SUSPEND_DETECTED, () => {
1934 1932
             APP.store.dispatch(suspendDetected());
1935
-
1936
-            // After wake up, we will be in a state where conference is left
1937
-            // there will be dialog shown to user.
1938
-            // We do not want video/audio as we show an overlay and after it
1939
-            // user need to rejoin or close, while waking up we can detect
1940
-            // camera wakeup as a problem with device.
1941
-            // We also do not care about device change, which happens
1942
-            // on resume after suspending PC.
1943
-            if (this.deviceChangeListener) {
1944
-                JitsiMeetJS.mediaDevices.removeEventListener(
1945
-                    JitsiMediaDevicesEvents.DEVICE_LIST_CHANGED,
1946
-                    this.deviceChangeListener);
1947
-            }
1948
-
1949
-            // stop local video
1950
-            if (this.localVideo) {
1951
-                this.localVideo.dispose();
1952
-                this.localVideo = null;
1953
-            }
1954
-
1955
-            // stop local audio
1956
-            if (this.localAudio) {
1957
-                this.localAudio.dispose();
1958
-                this.localAudio = null;
1959
-            }
1960
-
1961
-            APP.API.notifySuspendDetected();
1962 1933
         });
1963 1934
 
1964 1935
         APP.UI.addListener(UIEvents.AUDIO_MUTED, muted => {
@@ -2214,6 +2185,27 @@ export default {
2214 2185
             });
2215 2186
     },
2216 2187
 
2188
+    /**
2189
+     * Cleanups local conference on suspend.
2190
+     */
2191
+    onSuspendDetected() {
2192
+        // After wake up, we will be in a state where conference is left
2193
+        // there will be dialog shown to user.
2194
+        // We do not want video/audio as we show an overlay and after it
2195
+        // user need to rejoin or close, while waking up we can detect
2196
+        // camera wakeup as a problem with device.
2197
+        // We also do not care about device change, which happens
2198
+        // on resume after suspending PC.
2199
+        if (this.deviceChangeListener) {
2200
+            JitsiMeetJS.mediaDevices.removeEventListener(
2201
+                JitsiMediaDevicesEvents.DEVICE_LIST_CHANGED,
2202
+                this.deviceChangeListener);
2203
+        }
2204
+
2205
+        this.localVideo = null;
2206
+        this.localAudio = null;
2207
+    },
2208
+
2217 2209
     /**
2218 2210
      * Callback invoked when the conference has been successfully joined.
2219 2211
      * Initializes the UI and various other features.

+ 1
- 0
react/features/app/components/App.web.js Datei anzeigen

@@ -8,6 +8,7 @@ import '../../base/user-interaction';
8 8
 import '../../base/responsive-ui';
9 9
 import '../../chat';
10 10
 import '../../external-api';
11
+import '../../power-monitor';
11 12
 import '../../room-lock';
12 13
 import '../../video-layout';
13 14
 

+ 1
- 1
react/features/invite/_utils.js Datei anzeigen

@@ -9,7 +9,7 @@
9 9
  * Formats the conference pin in readable way for UI to display it.
10 10
  * Formats the pin in 3 groups of digits:
11 11
  * XXXX XXXX XX or XXXXX XXXXX XXX.
12
- * The length of first and second group is Math.ceil(pin.length / 3)
12
+ * The length of first and second group is Math.ceil(pin.length / 3).
13 13
  *
14 14
  * @param {Object} conferenceID - The conference id to format, string or number.
15 15
  * @returns {string} - The formatted conference pin.

+ 0
- 10
react/features/overlay/actionTypes.js Datei anzeigen

@@ -25,13 +25,3 @@ export const MEDIA_PERMISSION_PROMPT_VISIBILITY_CHANGED
25 25
  * @public
26 26
  */
27 27
 export const SET_FATAL_ERROR = 'SET_FATAL_ERROR';
28
-
29
-/**
30
- * The type of the Redux action which signals that a suspend was detected.
31
- *
32
- * {
33
- *     type: SUSPEND_DETECTED
34
- * }
35
- * @public
36
- */
37
-export const SUSPEND_DETECTED = 'SUSPEND_DETECTED';

+ 1
- 16
react/features/overlay/actions.js Datei anzeigen

@@ -2,8 +2,7 @@
2 2
 
3 3
 import {
4 4
     MEDIA_PERMISSION_PROMPT_VISIBILITY_CHANGED,
5
-    SET_FATAL_ERROR,
6
-    SUSPEND_DETECTED
5
+    SET_FATAL_ERROR
7 6
 } from './actionTypes';
8 7
 
9 8
 /**
@@ -27,20 +26,6 @@ export function mediaPermissionPromptVisibilityChanged(isVisible: boolean, brows
27 26
     };
28 27
 }
29 28
 
30
-/**
31
- * Signals that suspend was detected.
32
- *
33
- * @public
34
- * @returns {{
35
- *     type: SUSPEND_DETECTED
36
- * }}
37
- */
38
-export function suspendDetected() {
39
-    return {
40
-        type: SUSPEND_DETECTED
41
-    };
42
-}
43
-
44 29
 /**
45 30
  * The action indicates that an unrecoverable error has occurred and the reload
46 31
  * screen will be displayed or hidden.

+ 1
- 1
react/features/overlay/components/web/AbstractSuspendedOverlay.js Datei anzeigen

@@ -28,6 +28,6 @@ export default class AbstractSuspendedOverlay extends Component<Props> {
28 28
      * {@code false}, otherwise.
29 29
      */
30 30
     static needsRender(state: Object) {
31
-        return state['features/overlay'].suspendDetected;
31
+        return state['features/power-monitor'].suspendDetected;
32 32
     }
33 33
 }

+ 1
- 16
react/features/overlay/reducer.js Datei anzeigen

@@ -5,8 +5,7 @@ import { assign, ReducerRegistry, set } from '../base/redux';
5 5
 
6 6
 import {
7 7
     MEDIA_PERMISSION_PROMPT_VISIBILITY_CHANGED,
8
-    SET_FATAL_ERROR,
9
-    SUSPEND_DETECTED
8
+    SET_FATAL_ERROR
10 9
 } from './actionTypes';
11 10
 
12 11
 /**
@@ -29,8 +28,6 @@ ReducerRegistry.register('features/overlay', (state = { }, action) => {
29 28
     case SET_FATAL_ERROR:
30 29
         return _setFatalError(state, action);
31 30
 
32
-    case SUSPEND_DETECTED:
33
-        return _suspendDetected(state);
34 31
     }
35 32
 
36 33
     return state;
@@ -80,15 +77,3 @@ function _setShowLoadConfigOverlay(state, show) {
80 77
 function _setFatalError(state, { fatalError }) {
81 78
     return set(state, 'fatalError', fatalError);
82 79
 }
83
-
84
-/**
85
- * Reduces a specific redux action SUSPEND_DETECTED of the feature overlay.
86
- *
87
- * @param {Object} state - The redux state of the feature overlay.
88
- * @private
89
- * @returns {Object} The new state of the feature overlay after the reduction of
90
- * the specified action.
91
- */
92
-function _suspendDetected(state) {
93
-    return set(state, 'suspendDetected', true);
94
-}

+ 21
- 0
react/features/power-monitor/actionTypes.js Datei anzeigen

@@ -0,0 +1,21 @@
1
+// @flow
2
+
3
+/**
4
+ * The type of the Redux action which signals that a suspend was detected.
5
+ *
6
+ * {
7
+ *     type: SUSPEND_DETECTED
8
+ * }
9
+ * @public
10
+ */
11
+export const SUSPEND_DETECTED = 'SUSPEND_DETECTED';
12
+
13
+/**
14
+ * The type of the Redux action which signals that a transport needs to be stored.
15
+ *
16
+ * {
17
+ *     type: SET_TRANSPORT
18
+ * }
19
+ * @public
20
+ */
21
+export const SET_TRANSPORT = 'SET_TRANSPORT';

+ 37
- 0
react/features/power-monitor/actions.js Datei anzeigen

@@ -0,0 +1,37 @@
1
+// @flow
2
+
3
+import {
4
+    SET_TRANSPORT,
5
+    SUSPEND_DETECTED
6
+} from './actionTypes';
7
+import { Transport } from '../../../modules/transport';
8
+
9
+/**
10
+ * Signals that suspend was detected.
11
+ *
12
+ * @public
13
+ * @returns {{
14
+ *     type: SUSPEND_DETECTED
15
+ * }}
16
+ */
17
+export function suspendDetected() {
18
+    return {
19
+        type: SUSPEND_DETECTED
20
+    };
21
+}
22
+
23
+/**
24
+ * Signals setting of a transport.
25
+ *
26
+ * @param {Transport} transport - The transport to save in the state.
27
+ * @returns {{
28
+ *      transport: Transport,
29
+ *      type: string
30
+ *  }}
31
+ */
32
+export function setTransport(transport: ?Transport) {
33
+    return {
34
+        type: SET_TRANSPORT,
35
+        transport
36
+    };
37
+}

+ 7
- 0
react/features/power-monitor/index.js Datei anzeigen

@@ -0,0 +1,7 @@
1
+// @flow
2
+
3
+export * from './actions';
4
+export * from './actionTypes';
5
+
6
+import './middleware';
7
+import './reducer';

+ 74
- 0
react/features/power-monitor/middleware.js Datei anzeigen

@@ -0,0 +1,74 @@
1
+// @flow
2
+
3
+import {
4
+    setTransport,
5
+    suspendDetected
6
+} from './actions';
7
+import { SUSPEND_DETECTED } from './actionTypes';
8
+
9
+import {
10
+    CONFERENCE_JOINED,
11
+    CONFERENCE_LEFT
12
+} from '../base/conference';
13
+import { MiddlewareRegistry } from '../base/redux';
14
+import {
15
+    PostMessageTransportBackend,
16
+    Transport
17
+} from '../../../modules/transport';
18
+import { destroyLocalTracks } from '../base/tracks';
19
+
20
+declare var APP: Object;
21
+
22
+MiddlewareRegistry.register(store => next => action => {
23
+    const result = next(action);
24
+    const { dispatch, getState } = store;
25
+
26
+    switch (action.type) {
27
+    case CONFERENCE_JOINED: {
28
+
29
+        // listens for messages about suspend from power-monitor
30
+        const transport = new Transport({
31
+            backend: new PostMessageTransportBackend({
32
+                postisOptions: { scope: 'jitsi-power-monitor' }
33
+            })
34
+        });
35
+
36
+        transport.on('event', event => {
37
+            if (event && event.name === 'power-monitor' && event.event === 'suspend') {
38
+
39
+                dispatch(suspendDetected());
40
+
41
+                return true;
42
+            }
43
+
44
+            return false;
45
+        });
46
+
47
+        dispatch(setTransport(transport));
48
+        break;
49
+    }
50
+
51
+    case CONFERENCE_LEFT: {
52
+        const { transport } = getState()['features/power-monitor'];
53
+
54
+        if (transport) {
55
+            transport.dispose();
56
+        }
57
+
58
+        dispatch(setTransport());
59
+        break;
60
+    }
61
+
62
+    case SUSPEND_DETECTED: {
63
+        dispatch(destroyLocalTracks());
64
+
65
+        // FIXME: when refactoring conference.js
66
+        APP.conference.onSuspendDetected();
67
+
68
+        APP.API.notifySuspendDetected();
69
+        break;
70
+    }
71
+    }
72
+
73
+    return result;
74
+});

+ 51
- 0
react/features/power-monitor/reducer.js Datei anzeigen

@@ -0,0 +1,51 @@
1
+// @flow
2
+
3
+import { ReducerRegistry, set } from '../base/redux';
4
+import { Transport } from '../../../modules/transport';
5
+
6
+import {
7
+    SET_TRANSPORT,
8
+    SUSPEND_DETECTED
9
+} from './actionTypes';
10
+
11
+/**
12
+ * Reduces the redux actions of the feature power monitor.
13
+ */
14
+ReducerRegistry.register('features/power-monitor', (state = { }, action) => {
15
+    switch (action.type) {
16
+    case SET_TRANSPORT:
17
+        return _setTransport(state, action.transport);
18
+
19
+    case SUSPEND_DETECTED:
20
+        return _suspendDetected(state);
21
+
22
+    }
23
+
24
+    return state;
25
+});
26
+
27
+/**
28
+ * Reduces a specific redux action SET_TRANSPORT of the feature power monitor.
29
+ *
30
+ * @param {Object} state - The redux state of the feature power monitor.
31
+ * @param {?Transport} transport - The transport to store in state.
32
+ * @private
33
+ * @returns {Object} The new state of the feature power monitor after the reduction of
34
+ * the specified action.
35
+ */
36
+function _setTransport(state, transport: ?Transport) {
37
+    return set(state, 'transport', transport);
38
+}
39
+
40
+/**
41
+ * Reduces a specific redux action SUSPEND_DETECTED of the feature overlay.
42
+ *
43
+ * @param {Object} state - The redux state of the feature overlay.
44
+ * @private
45
+ * @returns {Object} The new state of the feature overlay after the reduction of
46
+ * the specified action.
47
+ */
48
+function _suspendDetected(state) {
49
+    return set(state, 'suspendDetected', true);
50
+}
51
+

Laden…
Abbrechen
Speichern