Skip to content

Commit f6ee06e

Browse files
committed
feat: 클라 -> 웹 영수증 OCR 결과 브릿지 구현
1 parent 82fa4f6 commit f6ee06e

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export enum WebBridgeMessageType {
2+
RECEIVE_SCAN_RESULT = "RECEIVE_SCAN_RESULT",
3+
}
4+
5+
export type WebBridgeMessage = ReceiveScanResultMessage;
6+
7+
export interface ReceiveScanResultMessage {
8+
type: WebBridgeMessageType.RECEIVE_SCAN_RESULT;
9+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { WebBridgeMessageType } from "@/components/provider/WebBridgeProvider/WebBridgeMessage.types";
2+
import type { WebBridgeMessage } from "@/components/provider/WebBridgeProvider/WebBridgeMessage.types";
3+
4+
declare global {
5+
interface Window {
6+
response: {
7+
receiveScanResult: (jsonData: string) => void;
8+
};
9+
}
10+
}
11+
12+
window.response = window.response || {};
13+
14+
const handlers = {
15+
[WebBridgeMessageType.RECEIVE_SCAN_RESULT]: (message: { payload: { json: string } }) => {
16+
if (
17+
typeof window !== "undefined" &&
18+
window.response &&
19+
typeof window.response.receiveScanResult === "function"
20+
) {
21+
window.response.receiveScanResult(message.payload.json);
22+
} else {
23+
console.warn("window.response.receiveScanResult is not available.");
24+
}
25+
},
26+
};
27+
28+
export function convertToWebBridge(message: WebBridgeMessage) {
29+
const handler = handlers[message.type];
30+
if (handler) {
31+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
32+
handler(message as any);
33+
} else {
34+
console.warn("Unhandled message type:", message.type);
35+
}
36+
}

0 commit comments

Comments
 (0)