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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* @flow */
  2. import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../app';
  3. import { CONFERENCE_JOINED } from '../base/conference';
  4. import { i18next } from '../base/i18n';
  5. import { MiddlewareRegistry } from '../base/redux';
  6. import { showNotification } from '../notifications';
  7. import { localRecordingEngaged, localRecordingUnengaged } from './actions';
  8. import { recordingController } from './controller';
  9. MiddlewareRegistry.register(({ getState, dispatch }) => next => action => {
  10. const result = next(action);
  11. switch (action.type) {
  12. case CONFERENCE_JOINED: {
  13. const { conference } = getState()['features/base/conference'];
  14. recordingController.registerEvents(conference);
  15. break;
  16. }
  17. case APP_WILL_MOUNT:
  18. // realize the delegates on recordingController, allowing the UI to
  19. // react to state changes in recordingController.
  20. recordingController.onStateChanged = function(isEngaged) {
  21. if (isEngaged) {
  22. const nowTime = new Date();
  23. dispatch(localRecordingEngaged(nowTime));
  24. } else {
  25. dispatch(localRecordingUnengaged());
  26. }
  27. };
  28. recordingController.onWarning = function(message) {
  29. dispatch(showNotification({
  30. title: i18next.t('localRecording.localRecording'),
  31. description: message
  32. }, 10000));
  33. };
  34. recordingController.onNotify = function(message) {
  35. dispatch(showNotification({
  36. title: i18next.t('localRecording.localRecording'),
  37. description: message
  38. }, 10000));
  39. };
  40. break;
  41. case APP_WILL_UNMOUNT:
  42. recordingController.onStateChanged = null;
  43. recordingController.onNotify = null;
  44. recordingController.onWarning = null;
  45. break;
  46. }
  47. // @todo: detect change in features/base/settings micDeviceID
  48. // @todo: SET_AUDIO_MUTED, when audio is muted
  49. return result;
  50. });