您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

middleware.js 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // @flow
  2. import { MiddlewareRegistry } from '../redux';
  3. import { PLAY_SOUND, STOP_SOUND } from './actionTypes';
  4. const logger = require('jitsi-meet-logger').getLogger(__filename);
  5. /**
  6. * Implements the entry point of the middleware of the feature base/media.
  7. *
  8. * @param {Store} store - The redux store.
  9. * @returns {Function}
  10. */
  11. MiddlewareRegistry.register(store => next => action => {
  12. switch (action.type) {
  13. case PLAY_SOUND:
  14. _playSound(store, action.soundId);
  15. break;
  16. case STOP_SOUND:
  17. _stopSound(store, action.soundId);
  18. break;
  19. }
  20. return next(action);
  21. });
  22. /**
  23. * Plays sound from audio element registered in the Redux store.
  24. *
  25. * @param {Store} store - The Redux store instance.
  26. * @param {string} soundId - Audio element identifier.
  27. * @private
  28. * @returns {void}
  29. */
  30. function _playSound({ getState }, soundId) {
  31. const sounds = getState()['features/base/sounds'];
  32. const sound = sounds.get(soundId);
  33. if (sound) {
  34. if (sound.audioElement) {
  35. sound.audioElement.play();
  36. } else {
  37. logger.warn(`PLAY_SOUND: sound not loaded yet for id: ${soundId}`);
  38. }
  39. } else {
  40. logger.warn(`PLAY_SOUND: no sound found for id: ${soundId}`);
  41. }
  42. }
  43. /**
  44. * Stop sound from audio element registered in the Redux store.
  45. *
  46. * @param {Store} store - The Redux store instance.
  47. * @param {string} soundId - Audio element identifier.
  48. * @private
  49. * @returns {void}
  50. */
  51. function _stopSound({ getState }, soundId) {
  52. const sounds = getState()['features/base/sounds'];
  53. const sound = sounds.get(soundId);
  54. if (sound) {
  55. const { audioElement } = sound;
  56. if (audioElement) {
  57. audioElement.stop();
  58. } else {
  59. logger.warn(`STOP_SOUND: sound not loaded yet for id: ${soundId}`);
  60. }
  61. } else {
  62. logger.warn(`STOP_SOUND: no sound found for id: ${soundId}`);
  63. }
  64. }