made basic message passing setup

This commit is contained in:
2024-08-02 16:34:35 +05:30
parent 6db2941102
commit 25d68c3479
13 changed files with 598 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
import { MessageType } from "./mainThread";
const handleConnection = (msg: MessageEvent<any>) => {
const { data } = msg;
if (!(data instanceof Array)) return;
if (!data.length) return;
switch (data[0]) {
case MessageType.attachCanvas:
const canvas = data[1];
const ctxWorker = canvas.getContext("2d");
ctxWorker.clearRect(0, 0, canvas.width, canvas.height);
ctxWorker.font = "24px Verdana";
ctxWorker.textAlign = "center";
ctxWorker.fillText("Hello World", canvas.width / 2, canvas.height / 2);
break;
}
console.log(...data);
}
export { handleConnection };