Z
This commit is contained in:
Bit Borealis 2023-10-04 08:58:31 +00:00
parent e1c7737480
commit 800af05329
Signed by: theotheroracle
GPG key ID: 2D816A2DCA6E5649
2 changed files with 10 additions and 12 deletions

View file

@ -1,3 +1,4 @@
//@ts-ignore
import { Update, UpdateRequest } from "/proto/mmelodies.proto";
// Pre-init protobuf request buffer
@ -6,12 +7,10 @@ const request = UpdateRequest.encode(message).finish();
const dest = document.querySelector("audio#stream");
const canvas = document.getElementById("scope");
const canvasCtx = canvas.getContext("2d");
const canvas = document.getElementById("scope") as HTMLCanvasElement;
const canvasCtx = canvas.getContext("2d") as CanvasRenderingContext2D;
const send = document.querySelector("#send");
let socket = undefined;
let socket: WebSocket | null = null;
function draw(samples: Float32Array) {
canvasCtx.fillStyle = "rgb(200, 200, 200)";
@ -55,7 +54,10 @@ function connect_ws() {
ws.binaryType = "arraybuffer";
ws.addEventListener("open", (event) => {
socket.send(request);
if (socket) {
socket.send(request);
}
});
ws.addEventListener("error", (event) => {
@ -63,6 +65,7 @@ function connect_ws() {
});
ws.addEventListener("close", () => {
socket = null;
setTimeout(() => {
socket = connect_ws();
}, 2500);
@ -70,7 +73,6 @@ function connect_ws() {
// Listen for messages
ws.addEventListener("message", (event) => {
send.hidden = true;
const message = Update.decode(new Uint8Array(event.data));
const samples = new Float32Array(message.scopeSamples);
@ -82,7 +84,4 @@ function connect_ws() {
return ws;
}
send.addEventListener("click", function (event) {
socket = connect_ws();
send.disabled = true;
});
socket = connect_ws();

View file

@ -8,7 +8,6 @@
</head>
<body>
<h1>Andisco display</h1>
<input type="button" id="send" value="Start">
<div id="waveform"></div>
<canvas id="scope" height=256 width=400></canvas>
</body>