2020-04-12 15:15:10 -04:00
|
|
|
export const state = () => ({
|
2020-04-17 09:02:11 -04:00
|
|
|
playlist: null,
|
2020-04-30 11:16:27 -04:00
|
|
|
playlistToday: [],
|
2020-04-24 09:15:55 -04:00
|
|
|
progressValue: 0,
|
2020-04-21 11:34:37 -04:00
|
|
|
currentClip: 'No clips is playing',
|
2020-05-12 11:43:53 -04:00
|
|
|
currentClipIndex: null,
|
2020-05-12 06:11:56 -04:00
|
|
|
currentClipStart: null,
|
|
|
|
currentClipDuration: null,
|
|
|
|
currentClipIn: null,
|
|
|
|
currentClipOut: null,
|
2020-04-21 11:34:37 -04:00
|
|
|
timeStr: '00:00:00',
|
|
|
|
timeLeft: '00:00:00'
|
2020-04-12 15:15:10 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
export const mutations = {
|
|
|
|
UPDATE_PLAYLIST (state, list) {
|
|
|
|
state.playlist = list
|
2020-04-17 09:02:11 -04:00
|
|
|
},
|
2020-04-30 11:16:27 -04:00
|
|
|
UPDATE_TODAYS_PLAYLIST (state, list) {
|
|
|
|
state.playlistToday = list
|
|
|
|
},
|
2020-04-17 09:02:11 -04:00
|
|
|
SET_PROGRESS_VALUE (state, value) {
|
2020-04-19 15:41:14 -04:00
|
|
|
state.progressValue = value
|
2020-04-17 09:02:11 -04:00
|
|
|
},
|
|
|
|
SET_CURRENT_CLIP (state, clip) {
|
|
|
|
state.currentClip = clip
|
|
|
|
},
|
2020-05-12 11:43:53 -04:00
|
|
|
SET_CURRENT_CLIP_INDEX (state, index) {
|
|
|
|
state.currentClipIndex = index
|
|
|
|
},
|
2020-05-12 06:11:56 -04:00
|
|
|
SET_CURRENT_CLIP_START (state, start) {
|
|
|
|
state.currentClipStart = start
|
|
|
|
},
|
|
|
|
SET_CURRENT_CLIP_DURATION (state, dur) {
|
|
|
|
state.currentClipDuration = dur
|
|
|
|
},
|
|
|
|
SET_CURRENT_CLIP_IN (state, _in) {
|
|
|
|
state.currentClipIn = _in
|
|
|
|
},
|
|
|
|
SET_CURRENT_CLIP_OUT (state, out) {
|
|
|
|
state.currentClipOut = out
|
|
|
|
},
|
2020-04-17 09:02:11 -04:00
|
|
|
SET_TIME (state, time) {
|
|
|
|
state.timeStr = time
|
|
|
|
},
|
|
|
|
SET_TIME_LEFT (state, time) {
|
|
|
|
state.timeLeft = time
|
2020-04-12 15:15:10 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const actions = {
|
2020-04-30 04:53:13 -04:00
|
|
|
async getPlaylist ({ commit, dispatch, state }, { dayStart, date }) {
|
2020-05-03 15:11:25 -04:00
|
|
|
const response = await this.$axios.get(`api/player/playlist/?date=${date}`)
|
2020-04-12 15:15:10 -04:00
|
|
|
|
2020-04-13 15:34:37 -04:00
|
|
|
if (response.data && response.data.program) {
|
2020-04-24 07:58:04 -04:00
|
|
|
commit('UPDATE_PLAYLIST', this.$processPlaylist(dayStart, response.data.program))
|
2020-04-21 09:28:31 -04:00
|
|
|
|
2020-04-30 11:16:27 -04:00
|
|
|
if (date === this.$dayjs().format('YYYY-MM-DD')) {
|
|
|
|
commit('UPDATE_TODAYS_PLAYLIST', JSON.parse(JSON.stringify(response.data.program)))
|
2020-05-12 06:11:56 -04:00
|
|
|
dispatch('setCurrentClip')
|
2020-04-21 09:28:31 -04:00
|
|
|
}
|
2020-04-24 09:15:55 -04:00
|
|
|
} else {
|
|
|
|
commit('UPDATE_PLAYLIST', [])
|
2020-04-17 09:02:11 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-05-12 06:11:56 -04:00
|
|
|
setCurrentClip ({ commit, dispatch, state, rootState }) {
|
2020-09-20 15:07:27 -04:00
|
|
|
let start
|
|
|
|
if (rootState.config.configPlayout.playlist.day_start) {
|
|
|
|
start = this.$timeToSeconds(rootState.config.configPlayout.playlist.day_start)
|
|
|
|
} else {
|
|
|
|
commit('SET_CURRENT_CLIP', 'day_start is not set, cannot calculate current clip')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-04-30 11:16:27 -04:00
|
|
|
for (let i = 0; i < state.playlistToday.length; i++) {
|
|
|
|
const duration = state.playlistToday[i].out - state.playlistToday[i].in
|
|
|
|
|
2020-05-12 06:11:56 -04:00
|
|
|
const playTime = this.$timeToSeconds(this.$dayjs().format('HH:mm:ss')) - start
|
|
|
|
|
|
|
|
// animate the progress bar
|
2020-04-30 11:16:27 -04:00
|
|
|
if (playTime <= duration) {
|
2020-05-12 06:11:56 -04:00
|
|
|
const progValue = playTime * 100 / duration
|
|
|
|
commit('SET_PROGRESS_VALUE', progValue)
|
2020-04-30 13:03:44 -04:00
|
|
|
commit('SET_CURRENT_CLIP', state.playlistToday[i].source)
|
2020-05-12 11:43:53 -04:00
|
|
|
commit('SET_CURRENT_CLIP_INDEX', i)
|
2020-05-12 06:11:56 -04:00
|
|
|
commit('SET_CURRENT_CLIP_START', start)
|
|
|
|
commit('SET_CURRENT_CLIP_DURATION', duration)
|
|
|
|
commit('SET_CURRENT_CLIP_IN', state.playlistToday[i].in)
|
|
|
|
commit('SET_CURRENT_CLIP_OUT', state.playlistToday[i].out)
|
|
|
|
|
2020-04-30 11:16:27 -04:00
|
|
|
break
|
2020-04-17 09:02:11 -04:00
|
|
|
}
|
2020-04-30 11:16:27 -04:00
|
|
|
|
|
|
|
start += duration
|
2020-04-12 15:15:10 -04:00
|
|
|
}
|
2020-05-12 06:11:56 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
animClock ({ commit, dispatch, state }) {
|
|
|
|
const time = this.$dayjs().format('HH:mm:ss')
|
|
|
|
const timeSec = this.$timeToSeconds(time)
|
|
|
|
const playTime = timeSec - state.currentClipStart
|
|
|
|
const progValue = playTime * 100 / state.currentClipDuration
|
|
|
|
|
2020-09-20 15:07:27 -04:00
|
|
|
commit('SET_TIME', time)
|
|
|
|
|
2020-05-12 06:11:56 -04:00
|
|
|
if (timeSec < state.currentClipStart) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// animate the progress bar
|
|
|
|
if (playTime <= state.currentClipDuration && progValue >= 0) {
|
|
|
|
commit('SET_PROGRESS_VALUE', progValue)
|
|
|
|
commit('SET_TIME_LEFT', this.$secToHMS(state.currentClipDuration - playTime))
|
|
|
|
} else {
|
|
|
|
commit('SET_PROGRESS_VALUE', 0)
|
|
|
|
dispatch('setCurrentClip')
|
|
|
|
}
|
2020-04-12 15:15:10 -04:00
|
|
|
}
|
|
|
|
}
|