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.any.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // @flow
  2. import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../app';
  3. import {
  4. getParticipantById,
  5. PARTICIPANT_UPDATED,
  6. PARTICIPANT_LEFT
  7. } from '../base/participants';
  8. import { MiddlewareRegistry } from '../base/redux';
  9. import {
  10. playSound,
  11. registerSound,
  12. stopSound,
  13. unregisterSound
  14. } from '../base/sounds';
  15. import {
  16. CALLING,
  17. INVITED,
  18. RINGING
  19. } from '../presence-status';
  20. import { UPDATE_DIAL_IN_NUMBERS_FAILED } from './actionTypes';
  21. import {
  22. OUTGOING_CALL_START_SOUND_ID,
  23. OUTGOING_CALL_RINGING_SOUND_ID
  24. } from './constants';
  25. import {
  26. OUTGOING_CALL_START_FILE,
  27. OUTGOING_CALL_RINGING_FILE
  28. } from './sounds';
  29. const logger = require('jitsi-meet-logger').getLogger(__filename);
  30. declare var interfaceConfig: Object;
  31. /**
  32. * The middleware of the feature invite common to mobile/react-native and
  33. * Web/React.
  34. *
  35. * @param {Store} store - The redux store.
  36. * @returns {Function}
  37. */
  38. MiddlewareRegistry.register(store => next => action => {
  39. let oldParticipantPresence;
  40. if (action.type === PARTICIPANT_UPDATED
  41. || action.type === PARTICIPANT_LEFT) {
  42. oldParticipantPresence
  43. = _getParticipantPresence(store.getState(), action.participant.id);
  44. }
  45. const result = next(action);
  46. switch (action.type) {
  47. case APP_WILL_MOUNT:
  48. store.dispatch(
  49. registerSound(
  50. OUTGOING_CALL_START_SOUND_ID,
  51. OUTGOING_CALL_START_FILE));
  52. store.dispatch(
  53. registerSound(
  54. OUTGOING_CALL_RINGING_SOUND_ID,
  55. OUTGOING_CALL_RINGING_FILE,
  56. { loop: true }));
  57. break;
  58. case APP_WILL_UNMOUNT:
  59. store.dispatch(unregisterSound(OUTGOING_CALL_START_SOUND_ID));
  60. store.dispatch(unregisterSound(OUTGOING_CALL_RINGING_SOUND_ID));
  61. break;
  62. case PARTICIPANT_LEFT:
  63. case PARTICIPANT_UPDATED: {
  64. const newParticipantPresence
  65. = _getParticipantPresence(store.getState(), action.participant.id);
  66. if (oldParticipantPresence === newParticipantPresence) {
  67. break;
  68. }
  69. switch (oldParticipantPresence) {
  70. case CALLING:
  71. case INVITED:
  72. store.dispatch(stopSound(OUTGOING_CALL_START_SOUND_ID));
  73. break;
  74. case RINGING:
  75. store.dispatch(stopSound(OUTGOING_CALL_RINGING_SOUND_ID));
  76. break;
  77. }
  78. switch (newParticipantPresence) {
  79. case CALLING:
  80. case INVITED:
  81. store.dispatch(playSound(OUTGOING_CALL_START_SOUND_ID));
  82. break;
  83. case RINGING:
  84. store.dispatch(playSound(OUTGOING_CALL_RINGING_SOUND_ID));
  85. }
  86. break;
  87. }
  88. case UPDATE_DIAL_IN_NUMBERS_FAILED:
  89. logger.error(
  90. 'Error encountered while fetching dial-in numbers:',
  91. action.error);
  92. break;
  93. }
  94. return result;
  95. });
  96. /**
  97. * Returns the presence status of a participant associated with the passed id.
  98. *
  99. * @param {Object} state - The redux state.
  100. * @param {string} id - The id of the participant.
  101. * @returns {string} - The presence status.
  102. */
  103. function _getParticipantPresence(state, id) {
  104. if (id) {
  105. const participantById = getParticipantById(state, id);
  106. if (participantById) {
  107. return participantById.presence;
  108. }
  109. }
  110. return undefined;
  111. }