diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2017-03-13 17:12:30 +0100 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2017-03-13 17:12:30 +0100 |
commit | 952bce302373c6903458c2a11236ae145e0bea71 (patch) | |
tree | 216f521d0f2a28a360984441af154e828a582ece /app/assets/javascripts | |
parent | a5daa806f2e4f824925aa1558202458bd3af7a0a (diff) |
Replace howler.js with simple <audio />, will hopefully resolve
some weird mobile browser behaviours
Diffstat (limited to 'app/assets/javascripts')
-rw-r--r-- | app/assets/javascripts/components/middleware/sounds.jsx | 22 | ||||
-rw-r--r-- | app/assets/javascripts/components/store/configureStore.jsx | 11 |
2 files changed, 24 insertions, 9 deletions
diff --git a/app/assets/javascripts/components/middleware/sounds.jsx b/app/assets/javascripts/components/middleware/sounds.jsx new file mode 100644 index 000000000..200efa3d7 --- /dev/null +++ b/app/assets/javascripts/components/middleware/sounds.jsx @@ -0,0 +1,22 @@ +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); + }; +}; diff --git a/app/assets/javascripts/components/store/configureStore.jsx b/app/assets/javascripts/components/store/configureStore.jsx index ad0427b52..a92d756f5 100644 --- a/app/assets/javascripts/components/store/configureStore.jsx +++ b/app/assets/javascripts/components/store/configureStore.jsx @@ -3,21 +3,14 @@ import thunk from 'redux-thunk'; import appReducer from '../reducers'; import loadingBarMiddleware from '../middleware/loading_bar'; import errorsMiddleware from '../middleware/errors'; -import soundsMiddleware from 'redux-sounds'; -import Howler from 'howler'; +import soundsMiddleware from '../middleware/sounds'; import Immutable from 'immutable'; -Howler.mobileAutoEnable = false; - -const soundsData = { - boop: '/sounds/boop.mp3' -}; - export default function configureStore() { return createStore(appReducer, compose(applyMiddleware( thunk, loadingBarMiddleware({ promiseTypeSuffixes: ['REQUEST', 'SUCCESS', 'FAIL'] }), errorsMiddleware(), - soundsMiddleware(soundsData) + soundsMiddleware() ), window.devToolsExtension ? window.devToolsExtension() : f => f)); }; |