2023-01-11 07:41:22 -05:00
|
|
|
import dayjs from 'dayjs'
|
2024-10-01 12:19:14 -04:00
|
|
|
import { differenceWith, isEqual, omit } from 'lodash-es'
|
2023-01-11 04:54:25 -05:00
|
|
|
import utc from 'dayjs/plugin/utc.js'
|
|
|
|
import timezone from 'dayjs/plugin/timezone.js'
|
|
|
|
|
|
|
|
import { defineStore } from 'pinia'
|
|
|
|
|
|
|
|
dayjs.extend(utc)
|
|
|
|
dayjs.extend(timezone)
|
|
|
|
|
|
|
|
const { processPlaylist } = playlistOperations()
|
|
|
|
|
|
|
|
export const usePlaylist = defineStore('playlist', {
|
|
|
|
state: () => ({
|
|
|
|
playlist: [] as PlaylistItem[],
|
2024-04-15 11:08:44 -04:00
|
|
|
isLoading: true,
|
2024-04-08 15:33:28 -04:00
|
|
|
listDate: dayjs().format('YYYY-MM-DD'),
|
2023-01-11 04:54:25 -05:00
|
|
|
progressValue: 0,
|
2024-09-11 03:51:16 -04:00
|
|
|
current: {} as PlaylistItem,
|
|
|
|
currentIndex: 0,
|
2023-04-09 16:28:57 -04:00
|
|
|
ingestRuns: false,
|
2024-04-30 03:11:26 -04:00
|
|
|
elapsedSec: 0,
|
|
|
|
shift: 0,
|
2023-10-20 02:28:09 -04:00
|
|
|
playoutIsRunning: false,
|
2024-06-24 01:51:50 -04:00
|
|
|
last_channel: 0,
|
2024-07-22 04:32:21 -04:00
|
|
|
firstLoad: true,
|
2024-10-23 09:09:46 -04:00
|
|
|
scrollToItem: false,
|
2023-01-11 04:54:25 -05:00
|
|
|
}),
|
|
|
|
|
|
|
|
getters: {},
|
|
|
|
actions: {
|
|
|
|
async getPlaylist(date: string) {
|
2024-10-01 12:19:14 -04:00
|
|
|
const { $i18n } = useNuxtApp()
|
2023-05-15 08:08:40 -04:00
|
|
|
const authStore = useAuth()
|
|
|
|
const configStore = useConfig()
|
2024-04-16 02:57:45 -04:00
|
|
|
const indexStore = useIndex()
|
2024-10-01 15:33:18 -04:00
|
|
|
const channel = configStore.channels[configStore.i].id
|
2023-01-11 04:54:25 -05:00
|
|
|
|
2024-10-01 12:19:14 -04:00
|
|
|
await $fetch(`/api/playlist/${channel}?date=${date}`, {
|
2023-01-11 04:54:25 -05:00
|
|
|
method: 'GET',
|
|
|
|
headers: authStore.authHeader,
|
|
|
|
})
|
|
|
|
.then((data) => {
|
|
|
|
if (data.program) {
|
2024-04-17 03:55:57 -04:00
|
|
|
const programData = processPlaylist(date, data.program, false)
|
2024-04-16 02:57:45 -04:00
|
|
|
|
|
|
|
if (
|
2024-06-24 01:51:50 -04:00
|
|
|
channel === this.last_channel &&
|
2024-04-16 02:57:45 -04:00
|
|
|
this.playlist.length > 0 &&
|
2024-04-17 03:55:57 -04:00
|
|
|
programData.length > 0 &&
|
2024-05-15 02:53:25 -04:00
|
|
|
(this.playlist[0].date === date || configStore.playout.playlist.infinit) &&
|
2024-10-01 12:19:14 -04:00
|
|
|
differenceWith(this.playlist, programData, (a, b) => {
|
|
|
|
return isEqual(omit(a, ['uid']), omit(b, ['uid']))
|
2024-04-16 02:57:45 -04:00
|
|
|
}).length > 0
|
|
|
|
) {
|
|
|
|
indexStore.msgAlert('warning', $i18n.t('player.unsavedProgram'), 3)
|
2024-04-17 03:55:57 -04:00
|
|
|
} else {
|
|
|
|
this.playlist = programData ?? []
|
2024-04-16 02:57:45 -04:00
|
|
|
}
|
2023-01-11 04:54:25 -05:00
|
|
|
}
|
|
|
|
})
|
2024-04-16 02:57:45 -04:00
|
|
|
.catch((e) => {
|
2024-06-24 01:53:24 -04:00
|
|
|
if (e.status >= 400) {
|
2024-05-27 06:01:31 -04:00
|
|
|
indexStore.msgAlert('error', e.data, 5)
|
2024-06-24 01:51:50 -04:00
|
|
|
} else if (
|
|
|
|
channel === this.last_channel &&
|
|
|
|
this.playlist.length > 0 &&
|
|
|
|
this.playlist[0].date === date
|
|
|
|
) {
|
2024-04-16 02:57:45 -04:00
|
|
|
indexStore.msgAlert('warning', $i18n.t('player.unsavedProgram'), 3)
|
2024-04-17 03:55:57 -04:00
|
|
|
} else {
|
|
|
|
this.playlist = []
|
2024-04-16 02:57:45 -04:00
|
|
|
}
|
2023-01-11 04:54:25 -05:00
|
|
|
})
|
2024-06-24 01:51:50 -04:00
|
|
|
|
|
|
|
this.last_channel = channel
|
2023-01-11 04:54:25 -05:00
|
|
|
},
|
|
|
|
|
2024-04-29 03:35:26 -04:00
|
|
|
setStatus(item: PlayoutStatus) {
|
|
|
|
this.playoutIsRunning = true
|
2024-09-11 03:51:16 -04:00
|
|
|
this.current = item.media
|
|
|
|
this.currentIndex = item.index
|
2024-04-30 03:11:26 -04:00
|
|
|
this.elapsedSec = item.elapsed
|
2024-04-29 03:35:26 -04:00
|
|
|
this.ingestRuns = item.ingest
|
2024-04-30 03:11:26 -04:00
|
|
|
this.shift = item.shift
|
2023-01-11 04:54:25 -05:00
|
|
|
|
2024-09-11 03:51:16 -04:00
|
|
|
this.progressValue = (this.elapsedSec * 100) / this.current.out
|
2023-01-11 04:54:25 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|