hydra-rce/app.js

38 lines
861 B
JavaScript

import Hydra from "hydra-synth";
const h = new Hydra();
class App {
constructor() {
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", this.init);
} else {
this.init();
}
}
init() {
window.addEventListener("resize", (event) => {
setResolution(window.innerWidth, window.innerHeight);
});
this.ws = new WebSocket("ws://localhost:8765");
this.ws.addEventListener("error", console.error);
this.ws.addEventListener("message", ({data}) => {
this.onMessage(data);
});
}
onMessage(data) {
console.log(data);
try {
eval?.(`"use strict";(async () => {${data}})();`);
} catch (e) {
console.error(e);
}
}
}
const app = new App();