owncast/web/pages/index2.tsx

33 lines
772 B
TypeScript
Raw Normal View History

2020-10-04 05:59:25 +02:00
import React, { useState, useEffect } from 'react';
import { BROADCASTER, fetchData } from './utils/apis';
export default function Admin() {
const [broadcasterStatus, setBroadcasterStatus] = useState({});
2020-10-04 08:07:37 +02:00
const getStatusIntervalId = null;
2020-10-04 05:59:25 +02:00
const getBroadcastStatus = async () => {
try {
const result = await fetchData(BROADCASTER);
const active = !!result.broadcaster;
setBroadcasterStatus({ ...result, active });
2020-10-04 08:07:37 +02:00
} catch (error) {
2020-10-04 05:59:25 +02:00
setBroadcasterStatus({ ...broadcasterStatus, message: error.message });
};
};
useEffect(() => { getBroadcastStatus(); }, []);
// getStatusIntervalId = setInterval(getBroadcastStatus, 15000);
return (
<div>
{JSON.stringify(broadcasterStatus)}
</div>
);
}