mirror of
https://github.com/streamwall/streamwall.git
synced 2026-01-24 22:22:50 -05:00
Use cached stream data if API fails
This commit is contained in:
@@ -20,6 +20,7 @@ function compareStrings(a, b) {
|
||||
export async function* pollPublicData() {
|
||||
const publicDataURL = 'https://woke.net/api/streams.json'
|
||||
const refreshInterval = 5 * 1000
|
||||
let lastData = []
|
||||
while (true) {
|
||||
let data = []
|
||||
try {
|
||||
@@ -28,7 +29,15 @@ export async function* pollPublicData() {
|
||||
} catch (err) {
|
||||
console.warn('error loading stream data', err)
|
||||
}
|
||||
yield filterLive(data)
|
||||
|
||||
// If the endpoint errors or returns an empty dataset, keep the cached data.
|
||||
if (!data.length && lastData.length) {
|
||||
console.warn('using cached stream data')
|
||||
} else {
|
||||
yield filterLive(data)
|
||||
lastData = data
|
||||
}
|
||||
|
||||
await sleep(refreshInterval)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user