diff --git a/apps/ex_nvr_web/assets/js/app.js b/apps/ex_nvr_web/assets/js/app.js index 1e4a7b51..d6246614 100644 --- a/apps/ex_nvr_web/assets/js/app.js +++ b/apps/ex_nvr_web/assets/js/app.js @@ -116,6 +116,8 @@ function initDarkMode() { startStreaming = (src, poster_url) => { var video = document.getElementById("live-video") + var infoBox = document.getElementById("stream-info"); + if (video != null && Hls.isSupported()) { if (window.hls) { window.hls.destroy() @@ -130,6 +132,31 @@ startStreaming = (src, poster_url) => { }) window.hls.loadSource(src) window.hls.attachMedia(video) + + window.hls.on(Hls.Events.LEVEL_LOADED, (event, data) => { + const { level, stats } = data; + const levelInfo = window.hls.levels[level]; + + infoBox.innerHTML = ` +

Bandwith Estimate: ${convertBitrate(window.hls.bandwidthEstimate)}

+

Bitrate: ${convertBitrate(levelInfo.bitrate)}

+

Avg.Bitrate: ${convertBitrate(levelInfo.averageBitrate)}

+

Resolution: ${levelInfo.width}x${levelInfo.height}

+

Codecs: ${levelInfo.attrs.CODECS}

+ `; + infoBox.innerHTML = infoHtml; + }); + } +} + +function convertBitrate(bitRate) { + const mbpsFactor = 1000 * 1000 + + let bitRateMbps = (bitRate / mbpsFactor) + if (bitRateMbps < 1) { + return `${(bitRateMbps * 1000).toFixed(2)} Kbps` + } else { + return `${bitRateMbps.toFixed(2)} Mbps` } } diff --git a/apps/ex_nvr_web/lib/ex_nvr_web/live/dashboard_live.ex b/apps/ex_nvr_web/lib/ex_nvr_web/live/dashboard_live.ex index 859ca757..663c1a0e 100644 --- a/apps/ex_nvr_web/lib/ex_nvr_web/live/dashboard_live.ex +++ b/apps/ex_nvr_web/lib/ex_nvr_web/live/dashboard_live.ex @@ -94,6 +94,18 @@ defmodule ExNVRWeb.DashboardLive do > <.icon name="hero-camera" /> + +