import $ from 'jquery' // https://stackoverflow.com/a/18650828 function formatBytes(a,b){if(0==a)return"0 Bytes";var c=1024,d=b||2,e=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"],f=Math.floor(Math.log(a)/Math.log(c));return parseFloat((a/Math.pow(c,f)).toFixed(d))+" "+e[f]} function recursive_stats(table, subtable) { var key for (key in table) { var val = table[key] if (typeof(val) == "object") { recursive_stats(val, key) } else { if (key == "time") { var date = new Date(null); date.setSeconds(Math.floor(parseInt(val)/1000)); // specify value for SECONDS here val = date.toISOString().substr(11, 8); } else if (key.indexOf("bytes") != -1) { val = formatBytes(val, 3) } $("#stat_" + (subtable ? subtable + "_" : "") + key).text(val) } } } function dashboard () { $.get("/dashboard/data", function (res) { if (res.error) { window.location.href = "/" return } var fullURL = window.location.origin + "/watch/" + res.name $('#myStream').attr('src', fullURL) $('#stream_url').text(fullURL).attr("href", fullURL) console.log(res) $('#stream_live').text(res.live ? 'Yes' : 'No') }) $('#show_key').click(function () { $('#show_key').html(window.STREAM_KEY) }) setInterval(function () { $.get("/dashboard/stats", function (res) { if (res.error) return recursive_stats(res, "") }) }, 5000) } export default {start: dashboard}