2022-11-28 10:52:24 +00:00
|
|
|
// @ts-expect-error
|
|
|
|
import { PostMessageTransportBackend, Transport } from '../../../modules/transport';
|
2019-07-12 13:08:34 +00:00
|
|
|
import {
|
|
|
|
CONFERENCE_JOINED,
|
|
|
|
CONFERENCE_LEFT
|
2022-11-28 10:52:24 +00:00
|
|
|
} from '../base/conference/actionTypes';
|
|
|
|
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
|
|
|
|
import { destroyLocalTracks } from '../base/tracks/actions';
|
2019-07-12 13:08:34 +00:00
|
|
|
|
2020-05-20 10:57:03 +00:00
|
|
|
import { SUSPEND_DETECTED } from './actionTypes';
|
|
|
|
import {
|
|
|
|
setTransport,
|
|
|
|
suspendDetected
|
|
|
|
} from './actions';
|
|
|
|
|
2019-07-12 13:08:34 +00:00
|
|
|
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' }
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2022-11-28 10:52:24 +00:00
|
|
|
transport.on('event', (event: { event: string; name: string; }) => {
|
2019-07-12 13:08:34 +00:00
|
|
|
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;
|
|
|
|
});
|