Skip to content

Commit

Permalink
chore: 유틸 함수 폴더 통일
Browse files Browse the repository at this point in the history
  • Loading branch information
alstn2468 committed Dec 14, 2024
1 parent b6ad757 commit 82e70ca
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
1 change: 0 additions & 1 deletion packages/bridge/src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './navigateBack';
export * from './navigateToShowDetail';
export * from './requestToken';
export * from './utils';
2 changes: 1 addition & 1 deletion packages/bridge/src/commands/sendCommand.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BRIDGE } from '../constants';
import { Command, PostMessageFn, ResponseListener, WebviewCommand } from '../types';
import { messageListeners, subscribe, unsubscribe } from './messageListeners';
import { getTimeStamp, getUuid, hasAndroidPostMessage, hasWebkitPostMessage } from './utils';
import { getTimeStamp, getUuid, hasAndroidPostMessage, hasWebkitPostMessage } from '../utils';

const getPostMessageFn = (): PostMessageFn | null => {
if (hasAndroidPostMessage()) {
Expand Down
19 changes: 0 additions & 19 deletions packages/bridge/src/commands/utils.ts

This file was deleted.

19 changes: 19 additions & 0 deletions packages/bridge/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { OS_REGEX, WEBVIEW_REGEX } from './constants';
import { v4 as uuidv4 } from 'uuid';

export const getUserAgent = () => window.navigator.userAgent;

Expand All @@ -19,3 +20,21 @@ export const checkIsIOS = (userAgent: string) => {
if (!checkIsWebView(userAgent)) return false;
return getWebViewOS(userAgent) === 'IOS';
};

export const getTimeStamp = () => new Date().valueOf().toString();

export const getUuid = () => uuidv4();

export const hasAndroidPostMessage = () =>
!!(typeof window !== 'undefined' && window.boolti && window.boolti.postMessage);

export const hasWebkitPostMessage = () =>
!!(
typeof window !== 'undefined' &&
window.webkit &&
window.webkit.messageHandlers &&
window.webkit.messageHandlers.boolti &&
window.webkit.messageHandlers.boolti.postMessage
);

export const isWebViewBridgeAvailable = () => hasAndroidPostMessage() || hasWebkitPostMessage();

0 comments on commit 82e70ca

Please sign in to comment.