add connectedclients endpoint

This commit is contained in:
Ginger Wong 2020-10-08 00:26:24 -07:00
parent c6c14bf216
commit e554a2a877
3 changed files with 47 additions and 1 deletions

View file

@ -0,0 +1,39 @@
import React, { useState, useEffect } from 'react';
import { CONNECTED_CLIENTS, fetchData, FETCH_INTERVAL } from '../utils/apis';
export default function HardwareInfo() {
const [clients, setClients] = useState({});
const getInfo = async () => {
try {
const result = await fetchData(CONNECTED_CLIENTS);
console.log("viewers result", result)
setClients({ ...result });
} catch (error) {
setClients({ ...clients, message: error.message });
}
};
useEffect(() => {
let getStatusIntervalId = null;
getInfo();
getStatusIntervalId = setInterval(getInfo, FETCH_INTERVAL);
// returned function will be called on component unmount
return () => {
clearInterval(getStatusIntervalId);
}
}, []);
return (
<div>
<h2>Connected Clients</h2>
<div style={{border: '1px solid purple', height: '300px', width: '100%', overflow:'auto'}}>
{JSON.stringify(clients)}
</div>
</div>
);
}

View file

@ -3,6 +3,7 @@ import React, { useState, useEffect } from 'react';
import BroadcastInfo from './components/broadcast-info';
import HardwareInfo from './components/hardware-info';
import ViewerInfo from './components/viewer-info';
import ConnectedClients from './components/connected-clients';
export default function HomeView(props) {
const { broadcastActive, broadcaster, message } = props;
@ -12,6 +13,7 @@ export default function HomeView(props) {
<BroadcastInfo {...broadcaster} />
<HardwareInfo />
<ViewerInfo />
<ConnectedClients />
</>
) : null;
@ -24,7 +26,8 @@ export default function HomeView(props) {
</p>
<h2>Utilities</h2>
(these dont do anything yet)
<p>(these dont do anything yet)</p>
{disconnectButton}
<button type="button">Change Stream Key</button>
<button type="button">Server Config</button>

View file

@ -22,6 +22,10 @@ export const SERVER_CONFIG = `${API_LOCATION}serverconfig`;
// Get viewer count over time
export const VIEWERS_OVER_TIME = `${API_LOCATION}viewersOverTime`;
// Get currently connected clients
export const CONNECTED_CLIENTS = `${API_LOCATION}clients`;
// Get hardware stats
export const HARDWARE_STATS = `${API_LOCATION}hardwarestats`;