minor cleanup

master
informatic 2023-11-06 22:35:13 +01:00
parent c95e86e214
commit 28447b2312
2 changed files with 14 additions and 19 deletions

View File

@ -1,10 +1,12 @@
<p>
<button onClick="openCamera()">Camera</button>
<button onClick="openScreensharing()">Screensharing</button>
<!--
<input type="number" id="x" />
<input type="number" id="y" />
<input type="number" id="width" />
<input type="number" id="height" />
-->
<button onClick="startStream()">Start stream</button>
</p>
@ -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();

View File

@ -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() {