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 BroadcastInfo from './components/broadcast-info';
import HardwareInfo from './components/hardware-info'; import HardwareInfo from './components/hardware-info';
import ViewerInfo from './components/viewer-info'; import ViewerInfo from './components/viewer-info';
import ConnectedClients from './components/connected-clients';
export default function HomeView(props) { export default function HomeView(props) {
const { broadcastActive, broadcaster, message } = props; const { broadcastActive, broadcaster, message } = props;
@@ -12,6 +13,7 @@ export default function HomeView(props) {
<BroadcastInfo {...broadcaster} /> <BroadcastInfo {...broadcaster} />
<HardwareInfo /> <HardwareInfo />
<ViewerInfo /> <ViewerInfo />
<ConnectedClients />
</> </>
) : null; ) : null;
@@ -24,7 +26,8 @@ export default function HomeView(props) {
</p> </p>
<h2>Utilities</h2> <h2>Utilities</h2>
(these dont do anything yet) <p>(these dont do anything yet)</p>
{disconnectButton} {disconnectButton}
<button type="button">Change Stream Key</button> <button type="button">Change Stream Key</button>
<button type="button">Server Config</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 // Get viewer count over time
export const VIEWERS_OVER_TIME = `${API_LOCATION}viewersOverTime`; export const VIEWERS_OVER_TIME = `${API_LOCATION}viewersOverTime`;
// Get currently connected clients
export const CONNECTED_CLIENTS = `${API_LOCATION}clients`;
// Get hardware stats // Get hardware stats
export const HARDWARE_STATS = `${API_LOCATION}hardwarestats`; export const HARDWARE_STATS = `${API_LOCATION}hardwarestats`;