Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

middleware.js 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. // @flow
  2. import { batch } from 'react-redux';
  3. import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../base/app';
  4. import { getParticipantCount } from '../base/participants';
  5. import { MiddlewareRegistry } from '../base/redux';
  6. import { updateSettings } from '../base/settings';
  7. import { playSound, registerSound, unregisterSound } from '../base/sounds';
  8. import { getDisabledSounds } from '../base/sounds/functions.any';
  9. import { isVpaasMeeting } from '../jaas/functions';
  10. import { NOTIFICATION_TIMEOUT, showNotification } from '../notifications';
  11. import {
  12. ADD_REACTION_BUFFER,
  13. FLUSH_REACTION_BUFFER,
  14. SEND_REACTIONS,
  15. PUSH_REACTIONS,
  16. SHOW_SOUNDS_NOTIFICATION
  17. } from './actionTypes';
  18. import { displayReactionSoundsNotification } from './actions';
  19. import {
  20. addReactionsToChat,
  21. flushReactionBuffer,
  22. pushReactions,
  23. sendReactions,
  24. setReactionQueue
  25. } from './actions.any';
  26. import {
  27. ENDPOINT_REACTION_NAME,
  28. RAISE_HAND_SOUND_ID,
  29. REACTIONS,
  30. REACTION_SOUND,
  31. SOUNDS_THRESHOLDS
  32. } from './constants';
  33. import {
  34. getReactionMessageFromBuffer,
  35. getReactionsSoundsThresholds,
  36. getReactionsWithId,
  37. sendReactionsWebhook
  38. } from './functions.any';
  39. import { RAISE_HAND_SOUND_FILE } from './sounds';
  40. declare var APP: Object;
  41. /**
  42. * Middleware which intercepts Reactions actions to handle changes to the
  43. * visibility timeout of the Reactions.
  44. *
  45. * @param {Store} store - The redux store.
  46. * @returns {Function}
  47. */
  48. MiddlewareRegistry.register(store => next => action => {
  49. const { dispatch, getState } = store;
  50. switch (action.type) {
  51. case APP_WILL_MOUNT:
  52. batch(() => {
  53. Object.keys(REACTIONS).forEach(key => {
  54. for (let i = 0; i < SOUNDS_THRESHOLDS.length; i++) {
  55. dispatch(registerSound(
  56. `${REACTIONS[key].soundId}${SOUNDS_THRESHOLDS[i]}`,
  57. REACTIONS[key].soundFiles[i]
  58. )
  59. );
  60. }
  61. }
  62. );
  63. dispatch(registerSound(RAISE_HAND_SOUND_ID, RAISE_HAND_SOUND_FILE));
  64. });
  65. break;
  66. case APP_WILL_UNMOUNT:
  67. batch(() => {
  68. Object.keys(REACTIONS).forEach(key => {
  69. for (let i = 0; i < SOUNDS_THRESHOLDS.length; i++) {
  70. dispatch(unregisterSound(`${REACTIONS[key].soundId}${SOUNDS_THRESHOLDS[i]}`));
  71. }
  72. });
  73. dispatch(unregisterSound(RAISE_HAND_SOUND_ID));
  74. });
  75. break;
  76. case ADD_REACTION_BUFFER: {
  77. const { timeoutID, buffer } = getState()['features/reactions'];
  78. const { reaction } = action;
  79. clearTimeout(timeoutID);
  80. buffer.push(reaction);
  81. action.buffer = buffer;
  82. action.timeoutID = setTimeout(() => {
  83. dispatch(flushReactionBuffer());
  84. }, 500);
  85. break;
  86. }
  87. case FLUSH_REACTION_BUFFER: {
  88. const state = getState();
  89. const { buffer } = state['features/reactions'];
  90. const participantCount = getParticipantCount(state);
  91. batch(() => {
  92. if (participantCount > 1) {
  93. dispatch(sendReactions());
  94. }
  95. dispatch(addReactionsToChat(getReactionMessageFromBuffer(buffer)));
  96. dispatch(pushReactions(buffer));
  97. });
  98. if (isVpaasMeeting(state)) {
  99. sendReactionsWebhook(state, buffer);
  100. }
  101. break;
  102. }
  103. case SEND_REACTIONS: {
  104. const state = getState();
  105. const { buffer } = state['features/reactions'];
  106. const { conference } = state['features/base/conference'];
  107. if (conference) {
  108. conference.sendEndpointMessage('', {
  109. name: ENDPOINT_REACTION_NAME,
  110. reactions: buffer,
  111. timestamp: Date.now()
  112. });
  113. }
  114. break;
  115. }
  116. case PUSH_REACTIONS: {
  117. const state = getState();
  118. const { queue, notificationDisplayed } = state['features/reactions'];
  119. const { soundsReactions } = state['features/base/settings'];
  120. const disabledSounds = getDisabledSounds(state);
  121. const reactions = action.reactions;
  122. batch(() => {
  123. if (!notificationDisplayed && soundsReactions && !disabledSounds.includes(REACTION_SOUND)
  124. && displayReactionSoundsNotification) {
  125. dispatch(displayReactionSoundsNotification());
  126. }
  127. if (soundsReactions) {
  128. const reactionSoundsThresholds = getReactionsSoundsThresholds(reactions);
  129. reactionSoundsThresholds.forEach(reaction =>
  130. dispatch(playSound(`${REACTIONS[reaction.reaction].soundId}${reaction.threshold}`))
  131. );
  132. }
  133. dispatch(setReactionQueue([ ...queue, ...getReactionsWithId(reactions) ]));
  134. });
  135. break;
  136. }
  137. case SHOW_SOUNDS_NOTIFICATION: {
  138. dispatch(showNotification({
  139. titleKey: 'toolbar.disableReactionSounds',
  140. customActionNameKey: 'notify.reactionSounds',
  141. customActionHandler: () => dispatch(updateSettings({
  142. soundsReactions: false
  143. }))
  144. }, NOTIFICATION_TIMEOUT));
  145. break;
  146. }
  147. }
  148. return next(action);
  149. });