Add resize reset
This commit is contained in:
@@ -14,21 +14,36 @@
|
|||||||
let width = $state(0);
|
let width = $state(0);
|
||||||
let height = $state(0);
|
let height = $state(0);
|
||||||
|
|
||||||
const resize = () => {
|
let debounce: number | null = $state(null);
|
||||||
width = image?.getBoundingClientRect().width ?? 0;
|
|
||||||
height = image?.getBoundingClientRect().height ?? 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
onMount(() => {
|
const connect = () => {
|
||||||
ws = new WebSocket("/ws");
|
ws = new WebSocket("/ws");
|
||||||
|
|
||||||
ws.onmessage = (event) => {
|
ws.onmessage = (event) => {
|
||||||
const data = JSON.parse(event.data);
|
const data = JSON.parse(event.data);
|
||||||
for (const tracker of data) {
|
for (const tracker of data) {
|
||||||
tracker.x *= width
|
tracker.x *= width;
|
||||||
tracker.y *= height
|
tracker.y *= height;
|
||||||
}
|
}
|
||||||
trackers = data;
|
trackers = data;
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const resize = () => {
|
||||||
|
width = image?.getBoundingClientRect().width ?? 0;
|
||||||
|
height = image?.getBoundingClientRect().height ?? 0;
|
||||||
|
|
||||||
|
if (debounce) {
|
||||||
|
clearTimeout(debounce);
|
||||||
|
}
|
||||||
|
|
||||||
|
debounce = setTimeout(() => {
|
||||||
|
connect();
|
||||||
|
}, 200);
|
||||||
|
};
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
connect();
|
||||||
|
|
||||||
width = image?.getBoundingClientRect().width ?? 0;
|
width = image?.getBoundingClientRect().width ?? 0;
|
||||||
height = image?.getBoundingClientRect().height ?? 0;
|
height = image?.getBoundingClientRect().height ?? 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user