2021-03-23 05:40:57 -04:00
|
|
|
import _ from 'lodash'
|
|
|
|
|
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 = {
|
2021-03-23 16:47:15 -04:00
|
|
|
async getPlaylist ({ commit, dispatch, state, rootState }, { date }) {
|
2021-03-23 08:57:30 -04:00
|
|
|
const timeInSec = this.$timeToSeconds(this.$dayjs().tz(rootState.config.timezone).format('HH:mm:ss'))
|
2021-03-23 16:47:15 -04:00
|
|
|
const configPath = rootState.config.configGui[rootState.config.configID].playout_config
|
2021-03-23 08:57:30 -04:00
|
|
|
let dateToday = this.$dayjs().tz(this.timezone).format('YYYY-MM-DD')
|
2021-01-28 09:53:18 -05:00
|
|
|
|
|
|
|
if (rootState.config.startInSec > timeInSec) {
|
2021-03-23 08:57:30 -04:00
|
|
|
dateToday = this.$dayjs(dateToday).tz(rootState.config.timezone).subtract(1, 'day').format('YYYY-MM-DD')
|
2021-01-28 09:53:18 -05:00
|
|
|
}
|
|
|
|
|
2021-03-18 13:16:47 -04:00
|
|
|
const response = await this.$axios.get(`api/player/playlist/?date=${date}&config_path=${configPath}`)
|
2021-03-23 16:47:15 -04:00
|
|
|
console.log(rootState.config.configPlayout.playlist.day_start)
|
2020-04-12 15:15:10 -04:00
|
|
|
|
2020-04-13 15:34:37 -04:00
|
|
|
if (response.data && response.data.program) {
|
2021-03-23 16:47:15 -04:00
|
|
|
commit('UPDATE_PLAYLIST', this.$processPlaylist(rootState.config.startInSec, response.data.program))
|
2020-04-21 09:28:31 -04:00
|
|
|
|
2021-01-28 09:53:18 -05:00
|
|
|
if (date === dateToday) {
|
2021-03-23 05:40:57 -04:00
|
|
|
commit('UPDATE_TODAYS_PLAYLIST', _.cloneDeep(response.data.program))
|
2020-05-12 06:11:56 -04:00
|
|
|
dispatch('setCurrentClip')
|
2021-01-28 09:53:18 -05:00
|
|
|
} else {
|
|
|
|
commit('SET_CURRENT_CLIP_INDEX', null)
|
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 }) {
|
2021-01-28 09:53:18 -05:00
|
|
|
let begin
|
2021-03-23 08:57:30 -04:00
|
|
|
let lastTime = this.$timeToSeconds(this.$dayjs().tz(rootState.config.timezone).format('HH:mm:ss'))
|
2021-01-28 09:53:18 -05:00
|
|
|
|
2021-02-02 03:15:44 -05:00
|
|
|
if (Number.isFinite(rootState.config.startInSec)) {
|
2021-01-28 09:53:18 -05:00
|
|
|
begin = rootState.config.startInSec
|
2020-09-20 15:07:27 -04:00
|
|
|
} else {
|
|
|
|
commit('SET_CURRENT_CLIP', 'day_start is not set, cannot calculate current clip')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-01-28 09:53:18 -05:00
|
|
|
if (lastTime < begin) {
|
|
|
|
lastTime += rootState.config.playlistLength
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// animate the progress bar
|
2021-01-28 09:53:18 -05:00
|
|
|
if (lastTime < begin + duration) {
|
|
|
|
const progValue = (lastTime - begin) * 100 / duration
|
2020-05-12 06:11:56 -04:00
|
|
|
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)
|
2021-01-28 09:53:18 -05:00
|
|
|
commit('SET_CURRENT_CLIP_START', begin)
|
2020-05-12 06:11:56 -04:00
|
|
|
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
|
|
|
|
2021-01-28 09:53:18 -05:00
|
|
|
begin += duration
|
2020-04-12 15:15:10 -04:00
|
|
|
}
|
2020-05-12 06:11:56 -04:00
|
|
|
},
|
|
|
|
|
2021-01-28 09:53:18 -05:00
|
|
|
animClock ({ commit, dispatch, state, rootState }) {
|
2021-03-23 08:57:30 -04:00
|
|
|
const time = this.$dayjs().tz(rootState.config.timezone).format('HH:mm:ss')
|
2021-01-28 09:53:18 -05:00
|
|
|
let timeSec = this.$timeToSeconds(time)
|
2020-05-12 06:11:56 -04:00
|
|
|
|
2020-09-20 15:07:27 -04:00
|
|
|
commit('SET_TIME', time)
|
|
|
|
|
2021-01-28 09:53:18 -05:00
|
|
|
if (timeSec < rootState.config.startInSec) {
|
|
|
|
timeSec += rootState.config.playlistLength
|
|
|
|
}
|
|
|
|
|
2020-05-12 06:11:56 -04:00
|
|
|
if (timeSec < state.currentClipStart) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-01-28 09:53:18 -05:00
|
|
|
const playTime = timeSec - state.currentClipStart
|
|
|
|
const progValue = playTime * 100 / state.currentClipDuration
|
|
|
|
|
|
|
|
// set progress bar value
|
2020-05-12 06:11:56 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|