Skip to content

Commit

Permalink
Merge pull request #2670 from entrylabs/issue/8013
Browse files Browse the repository at this point in the history
이슈 8013 처리
  • Loading branch information
leunge authored Mar 13, 2024
2 parents 2eecb19 + f1c9517 commit b69246f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/util/mediaPipeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,10 @@ class MediaPipeUtils {
return;
}

const id = Entry.generateHash();
if (sprite) {
const returnMessage = ({ data }: MessageEvent) => {
if (data.action === 'sprite_return') {
if (data.action === 'sprite_return' && data.id === id) {
this.motionWorker.removeEventListener('message', returnMessage);
resolve(data.result);
}
Expand Down Expand Up @@ -484,6 +485,8 @@ class MediaPipeUtils {
maxY,
},
imageBitmap,
flipState: this.flipState,
id,
});

if (!sprite) {
Expand Down
10 changes: 6 additions & 4 deletions src/util/workers/newmotion.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ type ImageRange = {
};

type TMessageData = {
action: String;
id: string;
action: string;
width?: number;
height?: number;
range?: ImageRange;
Expand Down Expand Up @@ -99,6 +100,7 @@ function calcMotion(data: TMessageData) {
motionCanvas.width,
motionCanvas.height
).data;
const id = data.id;
const sprite = data.sprite;
const flipState = data.flipState;
let { minX, maxX, minY, maxY } = data.range;
Expand All @@ -109,7 +111,7 @@ function calcMotion(data: TMessageData) {
maxX = motionCanvas.width / 2 + x + (width * scaleX) / 2;
minY = motionCanvas.height / 2 - y - (height * scaleY) / 2;
maxY = motionCanvas.height / 2 - y + (height * scaleY) / 2;
if (isFlipState(flipState, 'horizontal')) {
if (!isFlipState(flipState, 'horizontal')) {
const tempMinX = minX;
minX = motionCanvas.width - maxX;
maxX = motionCanvas.width - tempMinX;
Expand Down Expand Up @@ -220,9 +222,9 @@ function calcMotion(data: TMessageData) {
},
};
if (sprite) {
ctx.postMessage({ action: 'sprite_return', result });
ctx.postMessage({ id, action: 'sprite_return', result });
} else {
ctx.postMessage({ action: 'next_detect_motion', result });
ctx.postMessage({ id, action: 'next_detect_motion', result });
}
} catch (e) {
console.error(e);
Expand Down
1 change: 1 addition & 0 deletions types/entry.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export declare interface IEntry extends EntryOptions {
expansionBlocks: any;
aiUtilizeBlocks: any;
hardwareLiteBlocks: any;
generateHash: () => string;
}

declare type IHardwareType = 'serial' | 'bluetooth' | 'hid' | 'ble';
Expand Down

0 comments on commit b69246f

Please sign in to comment.