From 03aae4300630d17399863b180523e0c47cfd388b Mon Sep 17 00:00:00 2001 From: SrGooglo Date: Tue, 7 Mar 2023 02:09:24 +0000 Subject: [PATCH] added latency measurer --- .../app/constants/settings/about/index.jsx | 104 ++++++++++++++++-- 1 file changed, 92 insertions(+), 12 deletions(-) diff --git a/packages/app/constants/settings/about/index.jsx b/packages/app/constants/settings/about/index.jsx index a675dbf2..030630f3 100755 --- a/packages/app/constants/settings/about/index.jsx +++ b/packages/app/constants/settings/about/index.jsx @@ -34,6 +34,29 @@ const Footer = () => { } +const latencyToColor = (latency, type) => { + switch (type) { + case "http": { + if (latency < 100) { + return "green" + } + if (latency < 200) { + return "orange" + } + return "red" + } + case "ws": { + if (latency < 80) { + return "green" + } + if (latency < 120) { + return "orange" + } + return "red" + } + } +} + export default { id: "about", icon: "Info", @@ -46,6 +69,7 @@ export default { const [serverOrigin, setServerOrigin] = React.useState(null) const [serverHealth, setServerHealth] = React.useState(null) const [secureConnection, setSecureConnection] = React.useState(false) + const [connectionPing, setConnectionPing] = React.useState({}) const checkServerVersion = async () => { const serverManifest = await app.cores.api.customRequest() @@ -65,7 +89,7 @@ export default { } } - const featchServerHealth = async () => { + const fetchServerHealth = async () => { const response = await app.cores.api.customRequest({ method: "GET", url: "/server/health", @@ -78,10 +102,29 @@ export default { } } + const measurePing = async () => { + const result = await app.cores.api.measurePing() + + console.log(result) + + setConnectionPing(result) + } + React.useEffect(() => { checkServerVersion() checkServerOrigin() - featchServerHealth() + + fetchServerHealth() + measurePing() + + const measureInterval = setInterval(() => { + fetchServerHealth() + measurePing() + }, 3000) + + return () => { + clearInterval(measureInterval) + } }, []) return
@@ -114,18 +157,55 @@ export default {

Origin

- - : } +
- { - secureConnection ? " Secure connection" : "Insecure connection" - } - - + + + {connectionPing?.http}ms + +
+ +
+ + + {connectionPing?.ws}ms + +
+ + + : } + > + { + secureConnection ? " Secure connection" : "Insecure connection" + } + + +