2022-09-03 15:36:59 +03:00
|
|
|
import useSWR from "swr";
|
|
|
|
|
|
|
|
import Widget from "../widget";
|
|
|
|
import Block from "../block";
|
|
|
|
|
2022-09-04 21:58:42 +03:00
|
|
|
import { formatApiUrl } from "utils/api-helpers";
|
|
|
|
|
2022-09-03 15:36:59 +03:00
|
|
|
export default function Tautulli({ service }) {
|
|
|
|
const config = service.widget;
|
|
|
|
|
2022-09-04 21:58:42 +03:00
|
|
|
const { data: statsData, error: statsError } = useSWR(formatApiUrl(config, "get_activity"));
|
2022-09-03 15:36:59 +03:00
|
|
|
|
|
|
|
if (statsError) {
|
|
|
|
return <Widget error="Tautulli API Error" />;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!statsData) {
|
|
|
|
return (
|
|
|
|
<Widget>
|
|
|
|
<Block label="Playing" />
|
|
|
|
<Block label="Transcoding" />
|
|
|
|
<Block label="Bitrate" />
|
|
|
|
</Widget>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-09-07 16:53:24 +03:00
|
|
|
const { data } = statsData.response;
|
2022-09-03 15:36:59 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Widget>
|
|
|
|
<Block label="Playing" value={data.stream_count} />
|
|
|
|
<Block label="Transcoding" value={data.stream_count_transcode} />
|
|
|
|
{/* We divide by 1000 here because thats how Tautulli reports it on its own dashboard */}
|
|
|
|
<Block label="Bitrate" value={`${Math.round((data.total_bandwidth / 1000) * 100) / 100} Mbps`} />
|
|
|
|
</Widget>
|
|
|
|
);
|
|
|
|
}
|