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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 { MiddlewareRegistry } from '../base/redux';
  8. import { showNotification } from '../notifications';
  9. import { localRecordingEngaged, localRecordingUnengaged } from './actions';
  10. import { LocalRecordingInfoDialog } from './components';
  11. import { recordingController } from './controller';
  12. declare var APP: Object;
  13. MiddlewareRegistry.register(({ getState, dispatch }) => next => action => {
  14. const result = next(action);
  15. switch (action.type) {
  16. case CONFERENCE_JOINED: {
  17. const { conference } = getState()['features/base/conference'];
  18. recordingController.registerEvents(conference);
  19. break;
  20. }
  21. case APP_WILL_MOUNT:
  22. // realize the delegates on recordingController, allowing the UI to
  23. // react to state changes in recordingController.
  24. recordingController.onStateChanged = function(isEngaged) {
  25. if (isEngaged) {
  26. const nowTime = new Date();
  27. dispatch(localRecordingEngaged(nowTime));
  28. } else {
  29. dispatch(localRecordingUnengaged());
  30. }
  31. };
  32. recordingController.onWarning = (messageKey, messageParams) => {
  33. dispatch(showNotification({
  34. title: i18next.t('localRecording.localRecording'),
  35. description: i18next.t(messageKey, messageParams)
  36. }, 10000));
  37. };
  38. recordingController.onNotify = (messageKey, messageParams) => {
  39. dispatch(showNotification({
  40. title: i18next.t('localRecording.localRecording'),
  41. description: i18next.t(messageKey, messageParams)
  42. }, 10000));
  43. };
  44. APP.keyboardshortcut.registerShortcut('L', null, () => {
  45. sendAnalytics(createShortcutEvent('local.recording'));
  46. dispatch(toggleDialog(LocalRecordingInfoDialog));
  47. }, 'keyboardShortcuts.localRecording');
  48. break;
  49. case APP_WILL_UNMOUNT:
  50. recordingController.onStateChanged = null;
  51. recordingController.onNotify = null;
  52. recordingController.onWarning = null;
  53. break;
  54. }
  55. // @todo: detect change in features/base/settings micDeviceID
  56. // @todo: SET_AUDIO_MUTED, when audio is muted
  57. return result;
  58. });