2021-03-23 10:40:57 +01:00
|
|
|
import _ from 'lodash'
|
|
|
|
|
2020-04-12 21:15:10 +02:00
|
|
|
export const state = () => ({
|
2020-04-17 15:02:11 +02:00
|
|
|
playlist: null,
|
2020-04-30 17:16:27 +02:00
|
|
|
playlistToday: [],
|
2020-04-24 15:15:55 +02:00
|
|
|
progressValue: 0,
|
2020-04-21 17:34:37 +02:00
|
|
|
currentClip: 'No clips is playing',
|
2020-05-12 17:43:53 +02:00
|
|
|
currentClipIndex: null,
|
2020-05-12 12:11:56 +02:00
|
|
|
currentClipStart: null,
|
|
|
|
currentClipDuration: null,
|
|
|
|
currentClipIn: null,
|
|
|
|
currentClipOut: null,
|
2020-04-21 17:34:37 +02:00
|
|
|
timeStr: '00:00:00',
|
|
|
|
timeLeft: '00:00:00'
|
2020-04-12 21:15:10 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
export const mutations = {
|
|
|
|
UPDATE_PLAYLIST (state, list) {
|
|
|
|
state.playlist = list
|
2020-04-17 15:02:11 +02:00
|
|
|
},
|
2020-04-30 17:16:27 +02:00
|
|
|
UPDATE_TODAYS_PLAYLIST (state, list) {
|
|
|
|
state.playlistToday = list
|
|
|
|
},
|
2020-04-17 15:02:11 +02:00
|
|
|
SET_PROGRESS_VALUE (state, value) {
|
2020-04-19 21:41:14 +02:00
|
|
|
state.progressValue = value
|
2020-04-17 15:02:11 +02:00
|
|
|
},
|
|
|
|
SET_CURRENT_CLIP (state, clip) {
|
|
|
|
state.currentClip = clip
|
|
|
|
},
|
2020-05-12 17:43:53 +02:00
|
|
|
SET_CURRENT_CLIP_INDEX (state, index) {
|
|
|
|
state.currentClipIndex = index
|
|
|
|
},
|
2020-05-12 12:11:56 +02: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 15:02:11 +02:00
|
|
|
SET_TIME (state, time) {
|
|
|
|
state.timeStr = time
|
|
|
|
},
|
|
|
|
SET_TIME_LEFT (state, time) {
|
|
|
|
state.timeLeft = time
|
2020-04-12 21:15:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const actions = {
|
2021-03-23 21:47:15 +01:00
|
|
|
async getPlaylist ({ commit, dispatch, state, rootState }, { date }) {
|
2021-03-23 13:57:30 +01:00
|
|
|
const timeInSec = this.$timeToSeconds(this.$dayjs().tz(rootState.config.timezone).format('HH:mm:ss'))
|
2021-03-30 11:39:38 +02:00
|
|
|
const channel = rootState.config.configGui[rootState.config.configID].id
|
2021-03-23 13:57:30 +01:00
|
|
|
let dateToday = this.$dayjs().tz(this.timezone).format('YYYY-MM-DD')
|
2021-01-28 15:53:18 +01:00
|
|
|
|
|
|
|
if (rootState.config.startInSec > timeInSec) {
|
2021-03-23 13:57:30 +01:00
|
|
|
dateToday = this.$dayjs(dateToday).tz(rootState.config.timezone).subtract(1, 'day').format('YYYY-MM-DD')
|
2021-01-28 15:53:18 +01:00
|
|
|
}
|
|
|
|
|
2022-07-04 18:00:56 +02:00
|
|
|
const response = await this.$axios.get(`api/playlist/${channel}?date=${date}`)
|
2020-04-12 21:15:10 +02:00
|
|
|
|
2020-04-13 21:34:37 +02:00
|
|
|
if (response.data && response.data.program) {
|
2021-03-23 21:47:15 +01:00
|
|
|
commit('UPDATE_PLAYLIST', this.$processPlaylist(rootState.config.startInSec, response.data.program))
|
2020-04-21 15:28:31 +02:00
|
|
|
|
2021-01-28 15:53:18 +01:00
|
|
|
if (date === dateToday) {
|
2021-03-23 10:40:57 +01:00
|
|
|
commit('UPDATE_TODAYS_PLAYLIST', _.cloneDeep(response.data.program))
|
2021-01-28 15:53:18 +01:00
|
|
|
} else {
|
|
|
|
commit('SET_CURRENT_CLIP_INDEX', null)
|
2020-04-21 15:28:31 +02:00
|
|
|
}
|
2020-04-24 15:15:55 +02:00
|
|
|
} else {
|
|
|
|
commit('UPDATE_PLAYLIST', [])
|
2020-04-17 15:02:11 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-07-05 18:08:51 +02:00
|
|
|
async playoutStat ({ commit, dispatch, state, rootState }) {
|
|
|
|
const channel = rootState.config.configGui[rootState.config.configID].id
|
2021-03-23 13:57:30 +01:00
|
|
|
const time = this.$dayjs().tz(rootState.config.timezone).format('HH:mm:ss')
|
2021-01-28 15:53:18 +01:00
|
|
|
let timeSec = this.$timeToSeconds(time)
|
2020-05-12 12:11:56 +02:00
|
|
|
|
2020-09-20 21:07:27 +02:00
|
|
|
commit('SET_TIME', time)
|
|
|
|
|
2021-01-28 15:53:18 +01:00
|
|
|
if (timeSec < rootState.config.startInSec) {
|
|
|
|
timeSec += rootState.config.playlistLength
|
|
|
|
}
|
|
|
|
|
2020-05-12 12:11:56 +02:00
|
|
|
if (timeSec < state.currentClipStart) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-07-05 18:08:51 +02:00
|
|
|
const response = await this.$axios.get(`api/control/${channel}/media/current`)
|
2021-01-28 15:53:18 +01:00
|
|
|
|
2022-07-05 18:08:51 +02:00
|
|
|
if (response.data) {
|
|
|
|
const obj = response.data.result
|
|
|
|
const progValue = obj.played_sec * 100 / obj.current_media.out
|
2020-05-12 12:11:56 +02:00
|
|
|
commit('SET_PROGRESS_VALUE', progValue)
|
2022-07-05 18:08:51 +02:00
|
|
|
commit('SET_CURRENT_CLIP', obj.current_media.source)
|
|
|
|
commit('SET_CURRENT_CLIP_INDEX', obj.index)
|
|
|
|
commit('SET_CURRENT_CLIP_START', obj.start_sec)
|
|
|
|
commit('SET_CURRENT_CLIP_DURATION', obj.current_media.duration)
|
|
|
|
commit('SET_CURRENT_CLIP_IN', obj.current_media.seek)
|
|
|
|
commit('SET_CURRENT_CLIP_OUT', obj.current_media.out)
|
|
|
|
commit('SET_TIME_LEFT', this.$secToHMS(obj.remaining_sec))
|
2020-05-12 12:11:56 +02:00
|
|
|
}
|
2020-04-12 21:15:10 +02:00
|
|
|
}
|
|
|
|
}
|