kopia lustrzana https://github.com/Aircoookie/WLED
62 wiersze
1.6 KiB
HTML
62 wiersze
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>
|
|
console.info("Live-Preview websocket opening");
|
|
var socket = new WebSocket("ws://"+document.location.host+"/ws");
|
|
|
|
socket.onopen = function () {
|
|
console.info("Live-Preview websocket is opened");
|
|
socket.send("{'lv':true}");
|
|
}
|
|
|
|
socket.onclose = function () { console.info("Live-Preview websocket is closing"); }
|
|
|
|
socket.onerror = function (event) { console.error("Live-Preview websocket error:", event); }
|
|
|
|
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;
|
|
}
|
|
|
|
socket.onmessage = function (event) {
|
|
try {
|
|
var json = JSON.parse(event.data);
|
|
if (json && json.leds) {
|
|
requestAnimationFrame(function () {updatePreview(json.leds);});
|
|
}
|
|
}
|
|
catch (err) {
|
|
console.error("Live-Preview websocket error:",err);
|
|
}
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |