sounds.jsx 439 B

12345678910111213141516171819202122
  1. const play = audio => {
  2. if (!audio.paused) {
  3. audio.pause();
  4. audio.fastSeek(0);
  5. }
  6. audio.play();
  7. };
  8. export default function soundsMiddleware() {
  9. const soundCache = {
  10. boop: new Audio(['/sounds/boop.mp3'])
  11. };
  12. return ({ dispatch }) => next => (action) => {
  13. if (action.meta && action.meta.sound && soundCache[action.meta.sound]) {
  14. play(soundCache[action.meta.sound]);
  15. }
  16. return next(action);
  17. };
  18. };