You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

middleware.js 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* @flow */
  2. import { createShortcutEvent, sendAnalytics } from '../analytics';
  3. import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../base/app';
  4. import { CONFERENCE_JOINED } from '../base/conference';
  5. import { toggleDialog } from '../base/dialog';
  6. import { i18next } from '../base/i18n';
  7. import { SET_AUDIO_MUTED } from '../base/media';
  8. import { MiddlewareRegistry } from '../base/redux';
  9. import { showNotification } from '../notifications';
  10. import { localRecordingEngaged, localRecordingUnengaged } from './actions';
  11. import { LocalRecordingInfoDialog } from './components';
  12. import { recordingController } from './controller';
  13. declare var APP: Object;
  14. declare var config: Object;
  15. const isFeatureEnabled = config.localRecording
  16. && config.localRecording.enabled === true;
  17. isFeatureEnabled
  18. && MiddlewareRegistry.register(({ getState, dispatch }) => next => action => {
  19. const result = next(action);
  20. switch (action.type) {
  21. case CONFERENCE_JOINED: {
  22. const { conference } = getState()['features/base/conference'];
  23. const { localRecording } = getState()['features/base/config'];
  24. if (localRecording && localRecording.format) {
  25. recordingController.switchFormat(localRecording.format);
  26. }
  27. recordingController.registerEvents(conference);
  28. break;
  29. }
  30. case APP_WILL_MOUNT:
  31. // realize the delegates on recordingController, allowing the UI to
  32. // react to state changes in recordingController.
  33. recordingController.onStateChanged = isEngaged => {
  34. if (isEngaged) {
  35. const nowTime = new Date();
  36. dispatch(localRecordingEngaged(nowTime));
  37. } else {
  38. dispatch(localRecordingUnengaged());
  39. }
  40. };
  41. recordingController.onWarning = (messageKey, messageParams) => {
  42. dispatch(showNotification({
  43. title: i18next.t('localRecording.localRecording'),
  44. description: i18next.t(messageKey, messageParams)
  45. }, 10000));
  46. };
  47. recordingController.onNotify = (messageKey, messageParams) => {
  48. dispatch(showNotification({
  49. title: i18next.t('localRecording.localRecording'),
  50. description: i18next.t(messageKey, messageParams)
  51. }, 10000));
  52. };
  53. APP.keyboardshortcut.registerShortcut('L', null, () => {
  54. sendAnalytics(createShortcutEvent('local.recording'));
  55. dispatch(toggleDialog(LocalRecordingInfoDialog));
  56. }, 'keyboardShortcuts.localRecording');
  57. break;
  58. case APP_WILL_UNMOUNT:
  59. recordingController.onStateChanged = null;
  60. recordingController.onNotify = null;
  61. recordingController.onWarning = null;
  62. break;
  63. case SET_AUDIO_MUTED:
  64. recordingController.setMuted(action.muted);
  65. break;
  66. }
  67. // @todo: detect change in features/base/settings micDeviceID
  68. // @todo: SET_AUDIO_MUTED, when audio is muted
  69. return result;
  70. });