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

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