jiti-meet/react/features/local-recording/middleware.js

61 lines
2.1 KiB
JavaScript
Raw Normal View History

/* @flow */
2018-07-16 05:10:15 +00:00
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../base/app';
import { CONFERENCE_JOINED } from '../base/conference';
import { i18next } from '../base/i18n';
import { MiddlewareRegistry } from '../base/redux';
import { showNotification } from '../notifications';
2018-07-09 18:09:14 +00:00
import { localRecordingEngaged, localRecordingUnengaged } from './actions';
import { recordingController } from './controller';
MiddlewareRegistry.register(({ getState, dispatch }) => next => action => {
const result = next(action);
switch (action.type) {
case CONFERENCE_JOINED: {
const { conference } = getState()['features/base/conference'];
recordingController.registerEvents(conference);
break;
}
case APP_WILL_MOUNT:
2018-07-09 18:09:14 +00:00
// realize the delegates on recordingController, allowing the UI to
// react to state changes in recordingController.
recordingController.onStateChanged = function(isEngaged) {
if (isEngaged) {
2018-07-10 14:26:16 +00:00
const nowTime = new Date();
dispatch(localRecordingEngaged(nowTime));
2018-07-09 18:09:14 +00:00
} else {
dispatch(localRecordingUnengaged());
}
};
2018-07-16 05:10:15 +00:00
recordingController.onWarning = function(messageKey, messageParams) {
dispatch(showNotification({
title: i18next.t('localRecording.localRecording'),
2018-07-16 05:10:15 +00:00
description: i18next.t(messageKey, messageParams)
}, 10000));
};
2018-07-16 05:10:15 +00:00
recordingController.onNotify = function(messageKey, messageParams) {
dispatch(showNotification({
title: i18next.t('localRecording.localRecording'),
2018-07-16 05:10:15 +00:00
description: i18next.t(messageKey, messageParams)
}, 10000));
};
break;
case APP_WILL_UNMOUNT:
recordingController.onStateChanged = null;
recordingController.onNotify = null;
recordingController.onWarning = null;
break;
}
// @todo: detect change in features/base/settings micDeviceID
// @todo: SET_AUDIO_MUTED, when audio is muted
return result;
});