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.
This commit is contained in:
Дамян Минков 2019-07-12 14:08:34 +01:00 committed by GitHub
parent 9bf650c700
commit 9071cd4813
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 218 additions and 75 deletions

View File

@ -114,10 +114,8 @@ import {
maybeOpenFeedbackDialog,
submitFeedback
} from './react/features/feedback';
import {
mediaPermissionPromptVisibilityChanged,
suspendDetected
} from './react/features/overlay';
import { mediaPermissionPromptVisibilityChanged } from './react/features/overlay';
import { suspendDetected } from './react/features/power-monitor';
import { setSharedVideoStatus } from './react/features/shared-video';
import { isButtonEnabled } from './react/features/toolbox';
import { endpointMessageReceived } from './react/features/subtitles';
@ -1932,33 +1930,6 @@ export default {
room.on(JitsiConferenceEvents.SUSPEND_DETECTED, () => {
APP.store.dispatch(suspendDetected());
// After wake up, we will be in a state where conference is left
// there will be dialog shown to user.
// We do not want video/audio as we show an overlay and after it
// user need to rejoin or close, while waking up we can detect
// camera wakeup as a problem with device.
// We also do not care about device change, which happens
// on resume after suspending PC.
if (this.deviceChangeListener) {
JitsiMeetJS.mediaDevices.removeEventListener(
JitsiMediaDevicesEvents.DEVICE_LIST_CHANGED,
this.deviceChangeListener);
}
// stop local video
if (this.localVideo) {
this.localVideo.dispose();
this.localVideo = null;
}
// stop local audio
if (this.localAudio) {
this.localAudio.dispose();
this.localAudio = null;
}
APP.API.notifySuspendDetected();
});
APP.UI.addListener(UIEvents.AUDIO_MUTED, muted => {
@ -2214,6 +2185,27 @@ export default {
});
},
/**
* Cleanups local conference on suspend.
*/
onSuspendDetected() {
// After wake up, we will be in a state where conference is left
// there will be dialog shown to user.
// We do not want video/audio as we show an overlay and after it
// user need to rejoin or close, while waking up we can detect
// camera wakeup as a problem with device.
// We also do not care about device change, which happens
// on resume after suspending PC.
if (this.deviceChangeListener) {
JitsiMeetJS.mediaDevices.removeEventListener(
JitsiMediaDevicesEvents.DEVICE_LIST_CHANGED,
this.deviceChangeListener);
}
this.localVideo = null;
this.localAudio = null;
},
/**
* Callback invoked when the conference has been successfully joined.
* Initializes the UI and various other features.

View File

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

View File

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

View File

@ -25,13 +25,3 @@ export const MEDIA_PERMISSION_PROMPT_VISIBILITY_CHANGED
* @public
*/
export const SET_FATAL_ERROR = 'SET_FATAL_ERROR';
/**
* The type of the Redux action which signals that a suspend was detected.
*
* {
* type: SUSPEND_DETECTED
* }
* @public
*/
export const SUSPEND_DETECTED = 'SUSPEND_DETECTED';

View File

@ -2,8 +2,7 @@
import {
MEDIA_PERMISSION_PROMPT_VISIBILITY_CHANGED,
SET_FATAL_ERROR,
SUSPEND_DETECTED
SET_FATAL_ERROR
} from './actionTypes';
/**
@ -27,20 +26,6 @@ export function mediaPermissionPromptVisibilityChanged(isVisible: boolean, brows
};
}
/**
* Signals that suspend was detected.
*
* @public
* @returns {{
* type: SUSPEND_DETECTED
* }}
*/
export function suspendDetected() {
return {
type: SUSPEND_DETECTED
};
}
/**
* The action indicates that an unrecoverable error has occurred and the reload
* screen will be displayed or hidden.

View File

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

View File

@ -5,8 +5,7 @@ import { assign, ReducerRegistry, set } from '../base/redux';
import {
MEDIA_PERMISSION_PROMPT_VISIBILITY_CHANGED,
SET_FATAL_ERROR,
SUSPEND_DETECTED
SET_FATAL_ERROR
} from './actionTypes';
/**
@ -29,8 +28,6 @@ ReducerRegistry.register('features/overlay', (state = { }, action) => {
case SET_FATAL_ERROR:
return _setFatalError(state, action);
case SUSPEND_DETECTED:
return _suspendDetected(state);
}
return state;
@ -80,15 +77,3 @@ function _setShowLoadConfigOverlay(state, show) {
function _setFatalError(state, { fatalError }) {
return set(state, 'fatalError', fatalError);
}
/**
* Reduces a specific redux action SUSPEND_DETECTED of the feature overlay.
*
* @param {Object} state - The redux state of the feature overlay.
* @private
* @returns {Object} The new state of the feature overlay after the reduction of
* the specified action.
*/
function _suspendDetected(state) {
return set(state, 'suspendDetected', true);
}

View File

@ -0,0 +1,21 @@
// @flow
/**
* The type of the Redux action which signals that a suspend was detected.
*
* {
* type: SUSPEND_DETECTED
* }
* @public
*/
export const SUSPEND_DETECTED = 'SUSPEND_DETECTED';
/**
* The type of the Redux action which signals that a transport needs to be stored.
*
* {
* type: SET_TRANSPORT
* }
* @public
*/
export const SET_TRANSPORT = 'SET_TRANSPORT';

View File

@ -0,0 +1,37 @@
// @flow
import {
SET_TRANSPORT,
SUSPEND_DETECTED
} from './actionTypes';
import { Transport } from '../../../modules/transport';
/**
* Signals that suspend was detected.
*
* @public
* @returns {{
* type: SUSPEND_DETECTED
* }}
*/
export function suspendDetected() {
return {
type: SUSPEND_DETECTED
};
}
/**
* Signals setting of a transport.
*
* @param {Transport} transport - The transport to save in the state.
* @returns {{
* transport: Transport,
* type: string
* }}
*/
export function setTransport(transport: ?Transport) {
return {
type: SET_TRANSPORT,
transport
};
}

View File

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

View File

@ -0,0 +1,74 @@
// @flow
import {
setTransport,
suspendDetected
} from './actions';
import { SUSPEND_DETECTED } from './actionTypes';
import {
CONFERENCE_JOINED,
CONFERENCE_LEFT
} from '../base/conference';
import { MiddlewareRegistry } from '../base/redux';
import {
PostMessageTransportBackend,
Transport
} from '../../../modules/transport';
import { destroyLocalTracks } from '../base/tracks';
declare var APP: Object;
MiddlewareRegistry.register(store => next => action => {
const result = next(action);
const { dispatch, getState } = store;
switch (action.type) {
case CONFERENCE_JOINED: {
// listens for messages about suspend from power-monitor
const transport = new Transport({
backend: new PostMessageTransportBackend({
postisOptions: { scope: 'jitsi-power-monitor' }
})
});
transport.on('event', event => {
if (event && event.name === 'power-monitor' && event.event === 'suspend') {
dispatch(suspendDetected());
return true;
}
return false;
});
dispatch(setTransport(transport));
break;
}
case CONFERENCE_LEFT: {
const { transport } = getState()['features/power-monitor'];
if (transport) {
transport.dispose();
}
dispatch(setTransport());
break;
}
case SUSPEND_DETECTED: {
dispatch(destroyLocalTracks());
// FIXME: when refactoring conference.js
APP.conference.onSuspendDetected();
APP.API.notifySuspendDetected();
break;
}
}
return result;
});

View File

@ -0,0 +1,51 @@
// @flow
import { ReducerRegistry, set } from '../base/redux';
import { Transport } from '../../../modules/transport';
import {
SET_TRANSPORT,
SUSPEND_DETECTED
} from './actionTypes';
/**
* Reduces the redux actions of the feature power monitor.
*/
ReducerRegistry.register('features/power-monitor', (state = { }, action) => {
switch (action.type) {
case SET_TRANSPORT:
return _setTransport(state, action.transport);
case SUSPEND_DETECTED:
return _suspendDetected(state);
}
return state;
});
/**
* Reduces a specific redux action SET_TRANSPORT of the feature power monitor.
*
* @param {Object} state - The redux state of the feature power monitor.
* @param {?Transport} transport - The transport to store in state.
* @private
* @returns {Object} The new state of the feature power monitor after the reduction of
* the specified action.
*/
function _setTransport(state, transport: ?Transport) {
return set(state, 'transport', transport);
}
/**
* Reduces a specific redux action SUSPEND_DETECTED of the feature overlay.
*
* @param {Object} state - The redux state of the feature overlay.
* @private
* @returns {Object} The new state of the feature overlay after the reduction of
* the specified action.
*/
function _suspendDetected(state) {
return set(state, 'suspendDetected', true);
}