2020-10-08 09:26:24 +02:00
|
|
|
import React, { useState, useEffect } from 'react';
|
2020-10-21 10:19:29 +02:00
|
|
|
import { Table } from 'antd';
|
|
|
|
|
2020-10-08 09:26:24 +02:00
|
|
|
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-21 10:19:29 +02:00
|
|
|
setClients(result);
|
2020-10-08 09:26:24 +02:00
|
|
|
|
|
|
|
} catch (error) {
|
2020-10-21 10:19:29 +02:00
|
|
|
console.log("==== error", error)
|
2020-10-08 09:26:24 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
let getStatusIntervalId = null;
|
|
|
|
|
|
|
|
getInfo();
|
|
|
|
getStatusIntervalId = setInterval(getInfo, FETCH_INTERVAL);
|
|
|
|
|
|
|
|
// returned function will be called on component unmount
|
|
|
|
return () => {
|
|
|
|
clearInterval(getStatusIntervalId);
|
|
|
|
}
|
|
|
|
}, []);
|
2020-10-21 10:19:29 +02:00
|
|
|
|
|
|
|
const columns = [
|
|
|
|
{
|
|
|
|
title: 'User name',
|
|
|
|
dataIndex: 'username',
|
|
|
|
key: 'username',
|
|
|
|
render: username => username || '-',
|
|
|
|
sorter: (a, b) => a.username - b.username,
|
|
|
|
sortDirections: ['descend', 'ascend'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Messages sent',
|
|
|
|
dataIndex: 'messageCount',
|
|
|
|
key: 'messageCount',
|
|
|
|
sorter: (a, b) => a.messageCount - b.messageCount,
|
|
|
|
sortDirections: ['descend', 'ascend'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Connected Time',
|
|
|
|
dataIndex: 'connectedAt',
|
|
|
|
key: 'connectedAt',
|
|
|
|
render: time => (Date.now() - (new Date(time).getTime())) / 1000 / 60,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'User Agent',
|
|
|
|
dataIndex: 'userAgent',
|
|
|
|
key: 'userAgent',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Location',
|
|
|
|
dataIndex: 'geo',
|
|
|
|
key: 'geo',
|
|
|
|
render: geo => geo && `${geo.regionName}, ${geo.countryCode}`,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2020-10-08 09:26:24 +02:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<h2>Connected Clients</h2>
|
2020-10-21 10:19:29 +02:00
|
|
|
<Table dataSource={clients} columns={columns} />;
|
2020-10-08 09:26:24 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|