| 
									
										
										
										
											2020-12-19 17:26:36 +00:00
										 |  |  | <!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> | 
					
						
							| 
									
										
										
										
											2022-08-09 19:14:37 +00:00
										 |  |  |   <div id="canv"></div> | 
					
						
							| 
									
										
										
										
											2020-12-19 17:26:36 +00:00
										 |  |  |   <script> | 
					
						
							| 
									
										
										
										
											2022-03-24 11:17:10 +00:00
										 |  |  |     var ws; | 
					
						
							|  |  |  |     try { | 
					
						
							|  |  |  |       ws = top.window.ws; | 
					
						
							|  |  |  |     } catch (e) {} | 
					
						
							| 
									
										
										
										
											2021-07-08 00:01:17 +00:00
										 |  |  |     if (ws && ws.readyState === WebSocket.OPEN) { | 
					
						
							| 
									
										
										
										
											2022-08-09 19:14:37 +00:00
										 |  |  |       //console.info("Peek uses top WS"); | 
					
						
							| 
									
										
										
										
											2021-07-08 00:01:17 +00:00
										 |  |  |       ws.send("{'lv':true}"); | 
					
						
							|  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2022-02-01 11:02:04 +00:00
										 |  |  |       console.info("Peek WS opening"); | 
					
						
							| 
									
										
										
										
											2022-03-07 17:26:53 +00:00
										 |  |  |       ws = new WebSocket((window.location.protocol == "https:"?"wss":"ws")+"://"+document.location.host+"/ws"); | 
					
						
							| 
									
										
										
										
											2021-07-08 00:01:17 +00:00
										 |  |  |       ws.onopen = function () { | 
					
						
							| 
									
										
										
										
											2022-08-09 19:14:37 +00:00
										 |  |  |         //console.info("Peek WS open"); | 
					
						
							| 
									
										
										
										
											2021-07-08 00:01:17 +00:00
										 |  |  |         ws.send("{'lv':true}"); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-12-19 17:26:36 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-02-01 11:02:04 +00:00
										 |  |  |     ws.binaryType = "arraybuffer"; | 
					
						
							| 
									
										
										
										
											2022-08-09 19:14:37 +00:00
										 |  |  |     ws.addEventListener('message', (e) => { | 
					
						
							|  |  |  |       try { | 
					
						
							|  |  |  |         if (toString.call(e.data) === '[object ArrayBuffer]') { | 
					
						
							|  |  |  |           let leds = new Uint8Array(event.data); | 
					
						
							|  |  |  |           if (leds[0] != 76) return; //'L' | 
					
						
							|  |  |  |           let str = "linear-gradient(90deg,"; | 
					
						
							|  |  |  |           let len = leds.length; | 
					
						
							|  |  |  |           let start = leds[1]==2 ? 4 : 2; // 1 = 1D, 2 = 1D/2D (leds[2]=w, leds[3]=h) | 
					
						
							|  |  |  |           for (i = start; i < len; i+=3) { | 
					
						
							|  |  |  |             str += `rgb(${leds[i]},${leds[i+1]},${leds[i+2]})`; | 
					
						
							|  |  |  |             if (i < len -3) str += "," | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |           str += ")"; | 
					
						
							|  |  |  |           document.getElementById("canv").style.background = str; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } catch (err) { | 
					
						
							|  |  |  |         console.error("Peek WS error:",err); | 
					
						
							|  |  |  |       }  | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-12-19 17:26:36 +00:00
										 |  |  |   </script> | 
					
						
							|  |  |  | </body> | 
					
						
							|  |  |  | </html> |