WLED/wled00/data/liveviewws.htm
2021-07-08 02:01:17 +02:00

64 lines
1.6 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1">
<meta charset="utf-8">
<meta name="theme-color" content="#222222">
<title>WLED Live Preview</title>
<style>
body {
margin: 0;
}
#canv {
background: black;
filter: brightness(175%);
width: 100%;
height: 100%;
position: absolute;
}
</style>
</head>
<body>
<div id="canv" />
<script>
function updatePreview(leds) {
var str = "linear-gradient(90deg,";
var len = leds.length;
for (i = 0; i < len; i++) {
var leddata = leds[i];
if (leddata.length > 6) leddata = leddata.substring(2);
str += "#" + leddata;
if (i < len -1) str += ","
}
str += ")";
document.getElementById("canv").style.background = str;
}
function getLiveJson(event) {
try {
var json = JSON.parse(event.data);
if (json && json.leds) {
requestAnimationFrame(function () {updatePreview(json.leds);});
}
}
catch (err) {
console.error("Live-Preview ws error:",err);
}
}
var ws = top.window.ws;
if (ws && ws.readyState === WebSocket.OPEN) {
console.info("Use top WS for peek");
ws.send("{'lv':true}");
} else {
console.info("Peek ws opening");
ws = new WebSocket("ws://"+document.location.host+"/ws");
ws.onopen = function () {
console.info("Peek WS opened");
ws.send("{'lv':true}");
}
}
ws.addEventListener('message',getLiveJson);
</script>
</body>
</html>