ffplayout/stores/playlist.ts

98 lines
3.5 KiB
TypeScript
Raw Normal View History

import dayjs from 'dayjs'
2023-01-11 10:54:25 +01: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 21:33:28 +02:00
listDate: dayjs().format('YYYY-MM-DD'),
2023-01-11 10:54:25 +01:00
progressValue: 0,
2024-04-14 00:01:45 +02:00
currentClip: '',
currentClipIndex: 0,
2024-05-05 21:46:22 +02:00
currentClipTitle: null as null | string,
2023-01-11 10:54:25 +01:00
currentClipStart: 0,
currentClipDuration: 0,
currentClipIn: 0,
currentClipOut: 0,
ingestRuns: false,
elapsedSec: 0,
shift: 0,
playoutIsRunning: false,
2024-06-24 07:51:50 +02:00
last_channel: 0,
firstLoad: true,
2023-01-11 10:54:25 +01:00
}),
getters: {},
actions: {
async getPlaylist(date: string) {
const { $_, $i18n } = useNuxtApp()
2023-05-15 14:08:40 +02:00
const authStore = useAuth()
const configStore = useConfig()
const indexStore = useIndex()
2024-06-12 09:17:44 +02:00
const channel = configStore.configChannel[configStore.configID].id
2023-01-11 10:54:25 +01:00
await $fetch<Playlist>(`/api/playlist/${channel}?date=${date}`, {
2023-01-11 10:54:25 +01:00
method: 'GET',
headers: authStore.authHeader,
})
.then((data) => {
if (data.program) {
const programData = processPlaylist(date, data.program, false)
if (
2024-06-24 07:51:50 +02:00
channel === this.last_channel &&
this.playlist.length > 0 &&
programData.length > 0 &&
2024-05-15 08:53:25 +02: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 10:54:25 +01:00
}
})
.catch((e) => {
2024-06-24 07:53:24 +02:00
if (e.status >= 400) {
indexStore.msgAlert('error', e.data, 5)
2024-06-24 07:51:50 +02: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 10:54:25 +01:00
})
2024-06-24 07:51:50 +02:00
this.last_channel = channel
2023-01-11 10:54:25 +01:00
},
2024-04-29 09:35:26 +02:00
setStatus(item: PlayoutStatus) {
this.playoutIsRunning = true
this.currentClip = item.media.source
this.currentClipIn = item.media.in
this.currentClipOut = item.media.out
this.currentClipDuration = item.media.duration
2024-05-05 21:46:22 +02:00
this.currentClipTitle = item.media.title ?? null
2024-04-29 09:35:26 +02:00
this.currentClipIndex = item.index
this.elapsedSec = item.elapsed
2024-04-29 09:35:26 +02:00
this.ingestRuns = item.ingest
this.shift = item.shift
2023-01-11 10:54:25 +01:00
this.progressValue = (this.elapsedSec * 100) / this.currentClipOut
2023-01-11 10:54:25 +01:00
},
},
})