Skip to content

Commit

Permalink
Added liveviewws-page for liveview via websockets
Browse files Browse the repository at this point in the history
  • Loading branch information
GrumpyMeow committed Dec 19, 2020
1 parent 8545013 commit c4d8ef5
Show file tree
Hide file tree
Showing 5 changed files with 1,503 additions and 1,422 deletions.
8 changes: 8 additions & 0 deletions tools/cdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,14 @@ const char PAGE_dmxmap[] PROGMEM = R"=====()=====";
method: "plaintext",
filter: "html-minify",
},
{
file: "liveviewws.htm",
name: "PAGE_liveviewws",
prepend: "=====(",
append: ")=====",
method: "plaintext",
filter: "html-minify",
},
{
file: "404.htm",
name: "PAGE_404",
Expand Down
62 changes: 62 additions & 0 deletions wled00/data/liveviewws.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!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>
11 changes: 11 additions & 0 deletions wled00/html_other.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ update();var tmout=null;function update(){if(document.hidden)return clearTimeout
</script></body></html>)=====";
// Autogenerated from wled00/data/liveviewws.htm, do not edit!!
const char PAGE_liveviewws[] PROGMEM = R"=====(<!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:#000;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");function updatePreview(e){var o="linear-gradient(90deg,",n=e.length;for(i=0;i<n;i++){var t=e[i];t.length>6&&(t=t.substring(2)),o+="#"+t,i<n-1&&(o+=",")}o+=")",document.getElementById("canv").style.background=o}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(e){console.error("Live-Preview websocket error:",e)},socket.onmessage=function(e){try{var o=JSON.parse(e.data);o&&o.leds&&requestAnimationFrame((function(){updatePreview(o.leds)}))}catch(e){console.error("Live-Preview websocket error:",e)}}
</script></body></html>)=====";


// Autogenerated from wled00/data/404.htm, do not edit!!
const char PAGE_404[] PROGMEM = R"=====(<!DOCTYPE html><html><head><meta charset="utf-8"><meta
content="width=device-width" name="viewport"><meta name="theme-color"
Expand Down
Loading

0 comments on commit c4d8ef5

Please sign in to comment.