diff --git a/web/matrix_widget.html b/web/matrix_widget.html index 277ec04..f1a7ec5 100644 --- a/web/matrix_widget.html +++ b/web/matrix_widget.html @@ -1,5 +1,14 @@ + mumble stats @@ -14,15 +23,52 @@ let loading = document.getElementById("loading"); let stats = document.getElementById("stats"); +let user_count = 0; +let user_list = []; + +function htmlUser(user) { + let output = ``; + + if (user.user_id != null) { + output += ` `; + } else { + output += ` `; + } + + if (user.comment != null) { + output += `${user.name}`; + } else { + output += user.name; + } + + return output + ``; +} + async function pingServer() { try { - let res = await fetch("https://api.alemi.dev/mumble/ping?host=<>") - let doc = await res.json() + let res = await fetch("https://api.alemi.dev/mumble/ping?host=<>"); + let doc = await res.json(); + if (doc.users != user_count) { + let tmp = await fetch("https://api.alemi.dev/mumble/users?host=<>"); + user_list = await tmp.json(); + user_count = user_list.length; + } + + let user_list_html = ""; + for (let user of user_list) { + user_list_html += htmlUser(user) + ' '; + } + stats.innerHTML = ` users ${doc.users}/${doc.max_users} net ${doc.bandwidth/1000}kbps ~ ${doc.latency}ms version ${doc.version} + + + + ${user_list_html} + `; } catch (e) { stats.innerHTML = `error reaching api: ${e}`; @@ -34,3 +80,5 @@ setInterval(pingServer, 1000 * 60); + +