ffplayout/frontend/stores/playlist.ts

91 lines
3.1 KiB
TypeScript
Raw Permalink Normal View History

import dayjs from 'dayjs'
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[],
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,
ingestRuns: false,
elapsedSec: 0,
shift: 0,
playoutIsRunning: false,
2024-06-24 01:51:50 -04:00
last_channel: 0,
firstLoad: true,
scrollToItem: false,
2023-01-11 04:54:25 -05:00
}),
getters: {},
actions: {
async getPlaylist(date: string) {
const { $i18n } = useNuxtApp()
2023-05-15 08:08:40 -04:00
const authStore = useAuth()
const configStore = useConfig()
const indexStore = useIndex()
const channel = configStore.channels[configStore.i].id
2023-01-11 04:54:25 -05: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) {
const programData = processPlaylist(date, data.program, false)
if (
2024-06-24 01:51:50 -04:00
channel === this.last_channel &&
this.playlist.length > 0 &&
programData.length > 0 &&
2024-05-15 02:53:25 -04:00
(this.playlist[0].date === date || configStore.playout.playlist.infinit) &&
differenceWith(this.playlist, programData, (a, b) => {
return isEqual(omit(a, ['uid']), omit(b, ['uid']))
}).length > 0
) {
indexStore.msgAlert('warning', $i18n.t('player.unsavedProgram'), 3)
} else {
this.playlist = programData ?? []
}
2023-01-11 04:54:25 -05:00
}
})
.catch((e) => {
2024-06-24 01:53:24 -04:00
if (e.status >= 400) {
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
) {
indexStore.msgAlert('warning', $i18n.t('player.unsavedProgram'), 3)
} else {
this.playlist = []
}
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
this.elapsedSec = item.elapsed
2024-04-29 03:35:26 -04:00
this.ingestRuns = item.ingest
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
},
},
})