Compare commits

...

2 commits

Author SHA1 Message Date
Bit Borealis 800af05329
fix
Z
2023-10-04 08:58:31 +00:00
Bit Borealis e1c7737480
fix 2023-10-04 08:58:27 +00:00
3 changed files with 11 additions and 13 deletions

2
.vscode/launch.json vendored
View file

@ -13,7 +13,7 @@
"request": "launch",
"command": "nix run .#backend",
"name": "Backend",
"cwd": "${workspaceFolder}/../melodypond"
"cwd": "${workspaceFolder}"
},
{
"type": "chrome",

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>