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.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 = 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. APP.keyboardshortcut.registerShortcut('L', null, () => {
  55. sendAnalytics(createShortcutEvent('local.recording'));
  56. dispatch(toggleDialog(LocalRecordingInfoDialog));
  57. }, 'keyboardShortcuts.localRecording');
  58. break;
  59. case APP_WILL_UNMOUNT:
  60. recordingController.onStateChanged = null;
  61. recordingController.onNotify = null;
  62. recordingController.onWarning = null;
  63. break;
  64. case SET_AUDIO_MUTED:
  65. recordingController.setMuted(action.muted);
  66. break;
  67. case SETTINGS_UPDATED: {
  68. const { micDeviceId } = getState()['features/base/settings'];
  69. if (micDeviceId) {
  70. recordingController.setMicDevice(micDeviceId);
  71. }
  72. break;
  73. }
  74. }
  75. return result;
  76. });