1
0
mirror of https://github.com/mastodon/mastodon synced 2024-12-15 23:28:14 +09:00
mastodon/app/assets/javascripts/components/middleware/sounds.jsx

23 lines
439 B
React
Raw Normal View History

const play = audio => {
if (!audio.paused) {
audio.pause();
audio.fastSeek(0);
}
audio.play();
};
export default function soundsMiddleware() {
const soundCache = {
boop: new Audio(['/sounds/boop.mp3'])
};
return ({ dispatch }) => next => (action) => {
if (action.meta && action.meta.sound && soundCache[action.meta.sound]) {
play(soundCache[action.meta.sound]);
}
return next(action);
};
};