From 28447b23124f26ca0a5439115e4601f18326fc93 Mon Sep 17 00:00:00 2001 From: Piotr Dobrowolski Date: Mon, 6 Nov 2023 22:35:13 +0100 Subject: [PATCH] minor cleanup --- frontend.html | 30 +++++++++++++----------------- server.go | 3 +-- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/frontend.html b/frontend.html index cdbbb03..acafd4c 100644 --- a/frontend.html +++ b/frontend.html @@ -1,10 +1,12 @@

+

@@ -42,7 +44,7 @@ async function startStream() { canvas.width = width; canvas.height = height; - const ws = new WebSocket("ws://127.0.0.1:8080/stream"); + const ws = new WebSocket(`${location.protocol === 'https:' ? 'wss' : 'ws'}://${location.host}/stream`); ws.onmessage = (ev) => { console.info('onmessage', ev); @@ -66,25 +68,19 @@ async function startStream() { }; function render() { - //skip = (skip + 1) % 3; - if (skip === 0) { - ctx.drawImage(video, 0, 0, canvas.width, canvas.height); - ctx.filter = 'contrast(300%)'; - const pixel = ctx.getImageData(0, 0, canvas.width, canvas.height); + ctx.drawImage(video, 0, 0, canvas.width, canvas.height); + ctx.filter = 'contrast(300%)'; + const pixel = ctx.getImageData(0, 0, canvas.width, canvas.height); - for (var i = 0; i < width * height; i++) { - fb[offset+3*i] = pixel.data[4*i]; - fb[offset+3*i+1] = pixel.data[4*i+1]; - fb[offset+3*i+2] = pixel.data[4*i+2]; - } - - if (ws.readyState === 1) { - ws.send(fb); - } + for (var i = 0; i < width * height; i++) { + fb[offset+3*i] = pixel.data[4*i]; + fb[offset+3*i+1] = pixel.data[4*i+1]; + fb[offset+3*i+2] = pixel.data[4*i+2]; } - // setTimeout(render, 1000/30.0); - // requestAnimationFrame(render); + if (ws.readyState === 1) { + ws.send(fb); + } } //render(); diff --git a/server.go b/server.go index 8a08449..e12375e 100644 --- a/server.go +++ b/server.go @@ -2,7 +2,6 @@ package main import ( "flag" - "html/template" "log" "net" "net/http" @@ -41,7 +40,7 @@ func stream(w http.ResponseWriter, r *http.Request) { } func home(w http.ResponseWriter, r *http.Request) { - homeTemplate.Execute(w, "ws://"+r.Host+"/echo") + http.ServeFile(w, r, "frontend.html") } func main() {