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

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