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.

22 lines
439 B

  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. };