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 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 { SETTINGS_UPDATED } from '../base/settings/actionTypes';
  10. import { showNotification } from '../notifications';
  11. import { localRecordingEngaged, localRecordingUnengaged } from './actions';
  12. import { LocalRecordingInfoDialog } from './components';
  13. import { recordingController } from './controller';
  14. declare var APP: Object;
  15. declare var config: Object;
  16. const isFeatureEnabled = typeof config === 'object' && config.localRecording
  17. && config.localRecording.enabled === true;
  18. isFeatureEnabled
  19. && MiddlewareRegistry.register(({ getState, dispatch }) => next => action => {
  20. const result = next(action);
  21. switch (action.type) {
  22. case CONFERENCE_JOINED: {
  23. const { conference } = getState()['features/base/conference'];
  24. const { localRecording } = getState()['features/base/config'];
  25. if (localRecording && localRecording.format) {
  26. recordingController.switchFormat(localRecording.format);
  27. }
  28. recordingController.registerEvents(conference);
  29. break;
  30. }
  31. case APP_WILL_MOUNT:
  32. // realize the delegates on recordingController, allowing the UI to
  33. // react to state changes in recordingController.
  34. recordingController.onStateChanged = isEngaged => {
  35. if (isEngaged) {
  36. const nowTime = new Date();
  37. dispatch(localRecordingEngaged(nowTime));
  38. } else {
  39. dispatch(localRecordingUnengaged());
  40. }
  41. };
  42. recordingController.onWarning = (messageKey, messageParams) => {
  43. dispatch(showNotification({
  44. title: i18next.t('localRecording.localRecording'),
  45. description: i18next.t(messageKey, messageParams)
  46. }, 10000));
  47. };
  48. recordingController.onNotify = (messageKey, messageParams) => {
  49. dispatch(showNotification({
  50. title: i18next.t('localRecording.localRecording'),
  51. description: i18next.t(messageKey, messageParams)
  52. }, 10000));
  53. };
  54. typeof APP === 'object' && typeof APP.keyboardshortcut === 'object'
  55. && APP.keyboardshortcut.registerShortcut('L', null, () => {
  56. sendAnalytics(createShortcutEvent('local.recording'));
  57. dispatch(toggleDialog(LocalRecordingInfoDialog));
  58. }, 'keyboardShortcuts.localRecording');
  59. break;
  60. case APP_WILL_UNMOUNT:
  61. recordingController.onStateChanged = null;
  62. recordingController.onNotify = null;
  63. recordingController.onWarning = null;
  64. break;
  65. case SET_AUDIO_MUTED:
  66. recordingController.setMuted(action.muted);
  67. break;
  68. case SETTINGS_UPDATED: {
  69. const { micDeviceId } = getState()['features/base/settings'];
  70. if (micDeviceId) {
  71. recordingController.setMicDevice(micDeviceId);
  72. }
  73. break;
  74. }
  75. }
  76. return result;
  77. });