Skip to content
Snippets Groups Projects
Verified Commit 7dfafea2 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Disable radio populate after too much consecutive errors

parent dac8d6e0
No related branches found
No related tags found
No related merge requests found
...@@ -86,6 +86,7 @@ export default { ...@@ -86,6 +86,7 @@ export default {
}, },
loaded: function () { loaded: function () {
this.$refs.audio.volume = this.volume this.$refs.audio.volume = this.volume
this.$store.commit('player/resetErrorCount')
if (this.isCurrent) { if (this.isCurrent) {
this.$store.commit('player/duration', this.$refs.audio.duration) this.$store.commit('player/duration', this.$refs.audio.duration)
if (this.startTime) { if (this.startTime) {
......
...@@ -5,6 +5,8 @@ import time from '@/utils/time' ...@@ -5,6 +5,8 @@ import time from '@/utils/time'
export default { export default {
namespaced: true, namespaced: true,
state: { state: {
maxConsecutiveErrors: 5,
errorCount: 0,
playing: false, playing: false,
volume: 0.5, volume: 0.5,
duration: 0, duration: 0,
...@@ -25,6 +27,12 @@ export default { ...@@ -25,6 +27,12 @@ export default {
value = Math.max(value, 0) value = Math.max(value, 0)
state.volume = value state.volume = value
}, },
incrementErrorCount (state) {
state.errorCount += 1
},
resetErrorCount (state) {
state.errorCount = 0
},
duration (state, value) { duration (state, value) {
state.duration = value state.duration = value
}, },
...@@ -89,8 +97,9 @@ export default { ...@@ -89,8 +97,9 @@ export default {
dispatch('queue/next', null, {root: true}) dispatch('queue/next', null, {root: true})
dispatch('queue/next', null, {root: true}) dispatch('queue/next', null, {root: true})
}, },
trackErrored ({commit, dispatch}) { trackErrored ({commit, dispatch, state}) {
commit('errored', true) commit('errored', true)
commit('incrementErrorCount')
dispatch('queue/next', null, {root: true}) dispatch('queue/next', null, {root: true})
}, },
updateProgress ({commit}, t) { updateProgress ({commit}, t) {
......
...@@ -53,10 +53,13 @@ export default { ...@@ -53,10 +53,13 @@ export default {
commit('current', null) commit('current', null)
commit('running', false) commit('running', false)
}, },
populateQueue ({state, dispatch}) { populateQueue ({rootState, state, dispatch}) {
if (!state.running) { if (!state.running) {
return return
} }
if (rootState.player.errorCount >= rootState.player.maxConsecutiveErrors - 1) {
return
}
var params = { var params = {
session: state.current.session session: state.current.session
} }
......
...@@ -74,6 +74,16 @@ describe('store/player', () => { ...@@ -74,6 +74,16 @@ describe('store/player', () => {
store.mutations.toggleLooping(state) store.mutations.toggleLooping(state)
expect(state.looping).to.equal(0) expect(state.looping).to.equal(0)
}) })
it('increment error count', () => {
const state = { errorCount: 0 }
store.mutations.incrementErrorCount(state)
expect(state.errorCount).to.equal(1)
})
it('reset error count', () => {
const state = { errorCount: 10 }
store.mutations.resetErrorCount(state)
expect(state.errorCount).to.equal(0)
})
}) })
describe('getters', () => { describe('getters', () => {
it('durationFormatted', () => { it('durationFormatted', () => {
...@@ -145,8 +155,10 @@ describe('store/player', () => { ...@@ -145,8 +155,10 @@ describe('store/player', () => {
testAction({ testAction({
action: store.actions.trackErrored, action: store.actions.trackErrored,
payload: {test: 'track'}, payload: {test: 'track'},
params: {state: {errorCount: 0, maxConsecutiveErrors: 5}},
expectedMutations: [ expectedMutations: [
{ type: 'errored', payload: true } { type: 'errored', payload: true },
{ type: 'incrementErrorCount' }
], ],
expectedActions: [ expectedActions: [
{ type: 'queue/next', payload: null, options: {root: true} } { type: 'queue/next', payload: null, options: {root: true} }
......
...@@ -69,7 +69,11 @@ describe('store/radios', () => { ...@@ -69,7 +69,11 @@ describe('store/radios', () => {
}) })
testAction({ testAction({
action: store.actions.populateQueue, action: store.actions.populateQueue,
params: {state: {running: true, current: {session: 1}}}, params: {
state: {running: true, current: {session: 1}},
rootState: {player: {errorCount: 0, maxConsecutiveErrors: 5}}
},
expectedActions: [ expectedActions: [
{ type: 'queue/append', payload: {track: {id: 1}}, options: {root: true} } { type: 'queue/append', payload: {track: {id: 1}}, options: {root: true} }
] ]
...@@ -82,5 +86,17 @@ describe('store/radios', () => { ...@@ -82,5 +86,17 @@ describe('store/radios', () => {
expectedActions: [] expectedActions: []
}, done) }, done)
}) })
it('populateQueue does nothing when too much errors', (done) => {
testAction({
action: store.actions.populateQueue,
payload: {test: 'track'},
params: {
rootState: {player: {errorCount: 5, maxConsecutiveErrors: 5}},
state: {running: true}
},
expectedActions: []
}, done)
})
}) })
}) })
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment