-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add app bridge to send message (#43)
- Loading branch information
1 parent
1382fdf
commit 9dff610
Showing
2 changed files
with
36 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
declare global { | ||
interface Window { | ||
BRIDGE: { | ||
sendMessage: (message: string) => void; | ||
}; | ||
webkit: { | ||
messageHandlers: { | ||
weski: { | ||
showToast: (message: string) => void; | ||
}; | ||
}; | ||
}; | ||
} | ||
} | ||
|
||
const postAppMessage = (message: string) => { | ||
const userAgent = navigator.userAgent; | ||
const android = userAgent.match(/Android/i); | ||
const iphone = userAgent.match(/iPhone/i); | ||
|
||
if (android !== null) { | ||
console.log("Android"); | ||
return window.BRIDGE.sendMessage(message); | ||
|
||
} else if (iphone !== null) { | ||
console.log("iOS"); | ||
return window.webkit.messageHandlers.weski.showToast(message); | ||
|
||
} else { | ||
return window.opener.postMessage(message); | ||
} | ||
} | ||
|
||
export default postAppMessage; |