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

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