Skip to content

Commit 9dff610

Browse files
authored
feat: add app bridge to send message (#43)
1 parent 1382fdf commit 9dff610

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

src/features/slop/ui/slop-camera.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import React, { useEffect, useRef } from 'react';
22
import { createPortal } from 'react-dom';
3-
import { toast } from 'sonner';
43
import type { Position, Webcam } from '@/entities/slop/model/model';
54
import ArrowRightIcon from '@/shared/icons/arrow-right';
6-
import NeutralFace from '@/shared/icons/neutral-face';
75
import { cn } from '@/shared/lib';
6+
import postAppMessage from '@/shared/lib/postAppMessage';
87
import CameraButton from '@/shared/ui/cam-button';
98
import { Tooltip } from '@/shared/ui/tooltip';
109
import useSlopStore from '../hooks/useSlopStore';
@@ -45,11 +44,7 @@ const SlopCamera = ({
4544
setOpenCamera();
4645

4746
if (!src) {
48-
toast(
49-
<>
50-
<NeutralFace /> 선택한 웹캠은 아직 준비중 이에요
51-
</>
52-
);
47+
postAppMessage('선택한 웹캠은 아직 준비중 이에요');
5348
}
5449
};
5550

src/shared/lib/postAppMessage.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
declare global {
2+
interface Window {
3+
BRIDGE: {
4+
sendMessage: (message: string) => void;
5+
};
6+
webkit: {
7+
messageHandlers: {
8+
weski: {
9+
showToast: (message: string) => void;
10+
};
11+
};
12+
};
13+
}
14+
}
15+
16+
const postAppMessage = (message: string) => {
17+
const userAgent = navigator.userAgent;
18+
const android = userAgent.match(/Android/i);
19+
const iphone = userAgent.match(/iPhone/i);
20+
21+
if (android !== null) {
22+
console.log("Android");
23+
return window.BRIDGE.sendMessage(message);
24+
25+
} else if (iphone !== null) {
26+
console.log("iOS");
27+
return window.webkit.messageHandlers.weski.showToast(message);
28+
29+
} else {
30+
return window.opener.postMessage(message);
31+
}
32+
}
33+
34+
export default postAppMessage;

0 commit comments

Comments
 (0)