2020-10-08 09:26:24 +02:00
|
|
|
import React, { useState, useEffect } from 'react';
|
|
|
|
import { CONNECTED_CLIENTS, fetchData, FETCH_INTERVAL } from '../utils/apis';
|
|
|
|
|
|
|
|
export default function HardwareInfo() {
|
|
|
|
const [clients, setClients] = useState({});
|
|
|
|
|
2020-10-12 04:46:48 +02:00
|
|
|
/*
|
|
|
|
geo data looks like this
|
|
|
|
"geo": {
|
|
|
|
"countryCode": "US",
|
|
|
|
"regionName": "California",
|
|
|
|
"timeZone": "America/Los_Angeles"
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2020-10-08 09:26:24 +02:00
|
|
|
const getInfo = async () => {
|
|
|
|
try {
|
|
|
|
const result = await fetchData(CONNECTED_CLIENTS);
|
2020-10-12 04:46:48 +02:00
|
|
|
console.log("================ result", result)
|
2020-10-08 09:26:24 +02:00
|
|
|
|
|
|
|
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>
|
2020-10-12 04:46:48 +02:00
|
|
|
<p>a table of info..</p>
|
|
|
|
<p>who's watching, how long they've been there, have they chatted? where they from?</p>
|
2020-10-08 09:26:24 +02:00
|
|
|
<div style={{border: '1px solid purple', height: '300px', width: '100%', overflow:'auto'}}>
|
|
|
|
{JSON.stringify(clients)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|