stream/app.js

86 lines
2.0 KiB
JavaScript
Raw Normal View History

2021-03-05 12:17:51 +00:00
import { h } from 'preact'
2021-03-11 20:24:44 +00:00
import { useState, useEffect } from 'preact/hooks'
2021-03-05 12:17:51 +00:00
import 'regenerator-runtime/runtime'
2021-03-11 20:24:44 +00:00
import axios from 'axios'
2021-03-05 12:17:51 +00:00
import Video from './src/components/Video'
import config from './src/data/config'
import Info from './src/components/Info'
2021-03-11 20:24:44 +00:00
import { useCalendar } from './src/hooks/data'
import { useTimeout } from './src/hooks/timerHooks'
// const appStates = [
// 'noStream',
// 'streamLive',
// 'streamFinished'
// ]
2021-03-05 12:17:51 +00:00
export default () => {
const [isPlaying, setIsPlaying] = useState(false)
const [videoUrl, setVideoUrl] = useState(null)
2021-03-11 20:24:44 +00:00
const [feedData, setFeedData] = useState([])
const [minLoadTimePassed, setMinTimeUp] = useState(false)
const { data, loading } = useCalendar()
useTimeout(() => {
setMinTimeUp(true)
}, 1500)
useEffect(() => {
if (data && data.length) {
data.forEach(async (calItem, index) => {
if (calItem.url) {
const id = calItem.url.val.split('/').pop()
const {
data: {
account,
category,
channel,
embedPath,
language,
name,
state,
previewPath,
views,
},
} = await axios.get(`https://tv.undersco.re/api/v1/videos/${id}`)
2021-03-05 12:17:51 +00:00
2021-03-11 20:24:44 +00:00
const item = {
name,
account,
category,
channel,
description: calItem.description,
embedPath,
language,
state,
previewPath,
views,
start: calItem.start,
end: calItem.end,
id,
}
setFeedData(arr => [...arr, item])
}
})
}
}, [data])
2021-03-05 12:17:51 +00:00
return (
<div>
2021-03-11 20:24:44 +00:00
{false ? (
<Video
playing={isPlaying}
setPlaying={setIsPlaying}
src={videoUrl}
title={config.next_stream.title}
org={config.next_stream.org}
/>
2021-03-11 20:24:44 +00:00
) : (
<Info data={feedData} loading={loading || !minLoadTimePassed} />
)}
2021-03-05 12:17:51 +00:00
</div>
)
}