feat: add WHEP control, WHEPStatus badge, Wild Dragon Logo components: WHEPStatus.js

This commit is contained in:
Zac Gaetano 2026-05-06 16:17:41 -04:00
parent 9e1b2c2b4b
commit 86d7b3b1c2

View file

@ -0,0 +1,42 @@
import React from 'react';
import { Trans } from '@lingui/macro';
import Chip from '@mui/material/Chip';
export default function WHEPStatus({ address, channelid }) {
const [count, setCount] = React.useState(null);
React.useEffect(() => {
if (!address || !channelid) return;
const poll = () => {
fetch(`${address}/api/v3/webrtc/streams/${channelid}/peers`, { credentials: 'include' })
.then((r) => (r.ok ? r.json() : null))
.then((data) => {
if (data !== null && typeof data.count === 'number') {
setCount(data.count);
}
})
.catch(() => {});
};
poll();
const t = setInterval(poll, 5000);
return () => clearInterval(t);
}, [address, channelid]);
if (count === null) return null;
return (
<Chip
size="small"
label={
<Trans>
{count} viewer{count !== 1 ? 's' : ''}
</Trans>
}
color={count > 0 ? 'primary' : 'default'}
variant="outlined"
/>
);
}