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

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