webtonative 1.0.74 → 1.0.75-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +10 -0
- package/.prettierrc.json +7 -0
- package/README.md +31 -2
- package/build/ATTConsent/index.d.ts +17 -0
- package/build/ATTConsent/index.d.ts.map +1 -0
- package/build/ATTConsent/index.js +54 -0
- package/build/ATTConsent/index.js.map +1 -0
- package/build/ATTConsent/types.d.ts +15 -0
- package/build/ATTConsent/types.d.ts.map +1 -0
- package/build/ATTConsent/types.js +3 -0
- package/build/ATTConsent/types.js.map +1 -0
- package/build/AdMob/index.d.ts +31 -0
- package/build/AdMob/index.d.ts.map +1 -0
- package/build/AdMob/index.js +102 -0
- package/build/AdMob/index.js.map +1 -0
- package/build/AdMob/types.d.ts +25 -0
- package/build/AdMob/types.d.ts.map +1 -0
- package/build/AdMob/types.js +4 -0
- package/build/AdMob/types.js.map +1 -0
- package/build/AppReview/index.d.ts +7 -0
- package/build/AppReview/index.d.ts.map +1 -0
- package/build/AppReview/index.js +22 -0
- package/build/AppReview/index.js.map +1 -0
- package/build/AppReview/types.d.ts +8 -0
- package/build/AppReview/types.d.ts.map +1 -0
- package/build/AppReview/types.js +4 -0
- package/build/AppReview/types.js.map +1 -0
- package/build/AppsFlyer/index.d.ts +15 -0
- package/build/AppsFlyer/index.d.ts.map +1 -0
- package/build/AppsFlyer/index.js +43 -0
- package/build/AppsFlyer/index.js.map +1 -0
- package/build/AppsFlyer/types.d.ts +10 -0
- package/build/AppsFlyer/types.d.ts.map +1 -0
- package/build/AppsFlyer/types.js +3 -0
- package/build/AppsFlyer/types.js.map +1 -0
- package/build/BackgroundLocation/index.d.ts +12 -0
- package/build/BackgroundLocation/index.d.ts.map +1 -0
- package/build/BackgroundLocation/index.js +65 -0
- package/build/BackgroundLocation/index.js.map +1 -0
- package/build/BackgroundLocation/types.d.ts +32 -0
- package/build/BackgroundLocation/types.d.ts.map +1 -0
- package/build/BackgroundLocation/types.js +3 -0
- package/build/BackgroundLocation/types.js.map +1 -0
- package/build/Beacon/index.d.ts +7 -0
- package/build/Beacon/index.d.ts.map +1 -0
- package/build/Beacon/index.js +30 -0
- package/build/Beacon/index.js.map +1 -0
- package/build/Beacon/types.d.ts +19 -0
- package/build/Beacon/types.d.ts.map +1 -0
- package/build/Beacon/types.js +3 -0
- package/build/Beacon/types.js.map +1 -0
- package/build/Biometric/index.d.ts +27 -0
- package/build/Biometric/index.d.ts.map +1 -0
- package/build/Biometric/index.js +125 -0
- package/build/Biometric/index.js.map +1 -0
- package/build/Biometric/types.d.ts +24 -0
- package/build/Biometric/types.d.ts.map +1 -0
- package/build/Biometric/types.js +3 -0
- package/build/Biometric/types.js.map +1 -0
- package/build/Bluetooth/index.d.ts +17 -0
- package/build/Bluetooth/index.d.ts.map +1 -0
- package/build/Bluetooth/index.js +67 -0
- package/build/Bluetooth/index.js.map +1 -0
- package/build/Bluetooth/types.d.ts +34 -0
- package/build/Bluetooth/types.d.ts.map +1 -0
- package/build/Bluetooth/types.js +3 -0
- package/build/Bluetooth/types.js.map +1 -0
- package/build/BottomNavigation/index.d.ts +11 -0
- package/build/BottomNavigation/index.d.ts.map +1 -0
- package/build/BottomNavigation/index.js +41 -0
- package/build/BottomNavigation/index.js.map +1 -0
- package/build/BottomNavigation/types.d.ts +9 -0
- package/build/BottomNavigation/types.d.ts.map +1 -0
- package/build/BottomNavigation/types.js +3 -0
- package/build/BottomNavigation/types.js.map +1 -0
- package/build/Clipboard/index.d.ts +12 -0
- package/build/Clipboard/index.d.ts.map +1 -0
- package/build/Clipboard/index.js +45 -0
- package/build/Clipboard/index.js.map +1 -0
- package/build/Clipboard/types.d.ts +20 -0
- package/build/Clipboard/types.d.ts.map +1 -0
- package/build/Clipboard/types.js +4 -0
- package/build/Clipboard/types.js.map +1 -0
- package/build/Facebook/events.d.ts +13 -0
- package/build/Facebook/events.d.ts.map +1 -0
- package/build/Facebook/events.js +44 -0
- package/build/Facebook/events.js.map +1 -0
- package/build/Facebook/index.d.ts +3 -0
- package/build/Facebook/index.d.ts.map +1 -0
- package/build/Facebook/index.js +29 -0
- package/build/Facebook/index.js.map +1 -0
- package/build/Facebook/types.d.ts +22 -0
- package/build/Facebook/types.d.ts.map +1 -0
- package/build/Facebook/types.js +3 -0
- package/build/Facebook/types.js.map +1 -0
- package/build/Firebase/Analytics/index.d.ts +32 -0
- package/build/Firebase/Analytics/index.d.ts.map +1 -0
- package/build/Firebase/Analytics/index.js +110 -0
- package/build/Firebase/Analytics/index.js.map +1 -0
- package/build/Firebase/Messaging/index.d.ts +17 -0
- package/build/Firebase/Messaging/index.d.ts.map +1 -0
- package/build/Firebase/Messaging/index.js +64 -0
- package/build/Firebase/Messaging/index.js.map +1 -0
- package/build/Firebase/index.d.ts +4 -0
- package/build/Firebase/index.d.ts.map +1 -0
- package/build/Firebase/index.js +31 -0
- package/build/Firebase/index.js.map +1 -0
- package/build/Firebase/types.d.ts +58 -0
- package/build/Firebase/types.d.ts.map +1 -0
- package/build/Firebase/types.js +4 -0
- package/build/Firebase/types.js.map +1 -0
- package/build/FirebaseAnalytics/index.d.ts +3 -0
- package/build/FirebaseAnalytics/index.d.ts.map +1 -0
- package/build/FirebaseAnalytics/index.js +29 -0
- package/build/FirebaseAnalytics/index.js.map +1 -0
- package/build/Haptics/index.d.ts +7 -0
- package/build/Haptics/index.d.ts.map +1 -0
- package/build/Haptics/index.js +21 -0
- package/build/Haptics/index.js.map +1 -0
- package/build/Haptics/types.d.ts +8 -0
- package/build/Haptics/types.d.ts.map +1 -0
- package/build/Haptics/types.js +3 -0
- package/build/Haptics/types.js.map +1 -0
- package/build/InAppPurchase/index.d.ts +23 -0
- package/build/InAppPurchase/index.d.ts.map +1 -0
- package/build/InAppPurchase/index.js +81 -0
- package/build/InAppPurchase/index.js.map +1 -0
- package/build/InAppPurchase/types.d.ts +30 -0
- package/build/InAppPurchase/types.d.ts.map +1 -0
- package/build/InAppPurchase/types.js +3 -0
- package/build/InAppPurchase/types.js.map +1 -0
- package/build/InAppUpdate/index.d.ts +12 -0
- package/build/InAppUpdate/index.d.ts.map +1 -0
- package/build/InAppUpdate/index.js +39 -0
- package/build/InAppUpdate/index.js.map +1 -0
- package/build/InAppUpdate/types.d.ts +15 -0
- package/build/InAppUpdate/types.d.ts.map +1 -0
- package/build/InAppUpdate/types.js +3 -0
- package/build/InAppUpdate/types.js.map +1 -0
- package/build/MediaPlayer/index.d.ts +17 -0
- package/build/MediaPlayer/index.d.ts.map +1 -0
- package/build/MediaPlayer/index.js +56 -0
- package/build/MediaPlayer/index.js.map +1 -0
- package/build/MediaPlayer/types.d.ts +14 -0
- package/build/MediaPlayer/types.d.ts.map +1 -0
- package/build/MediaPlayer/types.js +3 -0
- package/build/MediaPlayer/types.js.map +1 -0
- package/build/NativeContacts/index.d.ts +12 -0
- package/build/NativeContacts/index.d.ts.map +1 -0
- package/build/NativeContacts/index.js +51 -0
- package/build/NativeContacts/index.js.map +1 -0
- package/build/NativeContacts/types.d.ts +14 -0
- package/build/NativeContacts/types.d.ts.map +1 -0
- package/build/NativeContacts/types.js +3 -0
- package/build/NativeContacts/types.js.map +1 -0
- package/build/Notification/index.d.ts +11 -0
- package/build/Notification/index.d.ts.map +1 -0
- package/build/Notification/index.js +42 -0
- package/build/Notification/index.js.map +1 -0
- package/build/Notification/types.d.ts +14 -0
- package/build/Notification/types.d.ts.map +1 -0
- package/build/Notification/types.js +3 -0
- package/build/Notification/types.js.map +1 -0
- package/build/OneSignal/index.d.ts +4 -0
- package/build/OneSignal/index.d.ts.map +1 -0
- package/build/OneSignal/index.js +59 -0
- package/build/OneSignal/index.js.map +1 -0
- package/build/OneSignal/types.d.ts +11 -0
- package/build/OneSignal/types.d.ts.map +1 -0
- package/build/OneSignal/types.js +4 -0
- package/build/OneSignal/types.js.map +1 -0
- package/build/Printing/index.d.ts +7 -0
- package/build/Printing/index.d.ts.map +1 -0
- package/build/Printing/index.js +20 -0
- package/build/Printing/index.js.map +1 -0
- package/build/Printing/types.d.ts +9 -0
- package/build/Printing/types.d.ts.map +1 -0
- package/build/Printing/types.js +3 -0
- package/build/Printing/types.js.map +1 -0
- package/build/README.md +33 -0
- package/build/Screen/index.d.ts +9 -0
- package/build/Screen/index.d.ts.map +1 -0
- package/build/Screen/index.js +35 -0
- package/build/Screen/index.js.map +1 -0
- package/build/Screen/types.d.ts +6 -0
- package/build/Screen/types.d.ts.map +1 -0
- package/build/Screen/types.js +4 -0
- package/build/Screen/types.js.map +1 -0
- package/build/Siri/index.d.ts +7 -0
- package/build/Siri/index.d.ts.map +1 -0
- package/build/Siri/index.js +26 -0
- package/build/Siri/index.js.map +1 -0
- package/build/Siri/types.d.ts +14 -0
- package/build/Siri/types.d.ts.map +1 -0
- package/build/Siri/types.js +3 -0
- package/build/Siri/types.js.map +1 -0
- package/build/SocialLogin/apple.d.ts +12 -0
- package/build/SocialLogin/apple.d.ts.map +1 -0
- package/build/SocialLogin/apple.js +32 -0
- package/build/SocialLogin/apple.js.map +1 -0
- package/build/SocialLogin/facebook.d.ts +22 -0
- package/build/SocialLogin/facebook.d.ts.map +1 -0
- package/build/SocialLogin/facebook.js +61 -0
- package/build/SocialLogin/facebook.js.map +1 -0
- package/build/SocialLogin/google.d.ts +22 -0
- package/build/SocialLogin/google.d.ts.map +1 -0
- package/build/SocialLogin/google.js +61 -0
- package/build/SocialLogin/google.js.map +1 -0
- package/build/SocialLogin/index.d.ts +17 -0
- package/build/SocialLogin/index.d.ts.map +1 -0
- package/build/SocialLogin/index.js +23 -0
- package/build/SocialLogin/index.js.map +1 -0
- package/build/SocialLogin/types.d.ts +39 -0
- package/build/SocialLogin/types.d.ts.map +1 -0
- package/build/SocialLogin/types.js +3 -0
- package/build/SocialLogin/types.js.map +1 -0
- package/build/Stripe/index.d.ts +3 -0
- package/build/Stripe/index.d.ts.map +1 -0
- package/build/Stripe/index.js +49 -0
- package/build/Stripe/index.js.map +1 -0
- package/build/Stripe/types.d.ts +32 -0
- package/build/Stripe/types.d.ts.map +1 -0
- package/build/Stripe/types.js +3 -0
- package/build/Stripe/types.js.map +1 -0
- package/build/VoiceSearch/index.d.ts +13 -0
- package/build/VoiceSearch/index.d.ts.map +1 -0
- package/build/VoiceSearch/index.js +34 -0
- package/build/VoiceSearch/index.js.map +1 -0
- package/build/VoiceSearch/types.d.ts +10 -0
- package/build/VoiceSearch/types.d.ts.map +1 -0
- package/build/VoiceSearch/types.js +3 -0
- package/build/VoiceSearch/types.js.map +1 -0
- package/build/barcode/barcode-scan.d.ts +16 -0
- package/build/barcode/barcode-scan.d.ts.map +1 -0
- package/build/barcode/barcode-scan.js +40 -0
- package/build/barcode/barcode-scan.js.map +1 -0
- package/build/barcode/barcode-types.d.ts +18 -0
- package/build/barcode/barcode-types.d.ts.map +1 -0
- package/build/barcode/barcode-types.js +3 -0
- package/build/barcode/barcode-types.js.map +1 -0
- package/build/barcode/formats.d.ts +18 -0
- package/build/barcode/formats.d.ts.map +1 -0
- package/build/barcode/formats.js +23 -0
- package/build/barcode/formats.js.map +1 -0
- package/build/barcode/index.d.ts +5 -0
- package/build/barcode/index.d.ts.map +1 -0
- package/build/barcode/index.js +13 -0
- package/build/barcode/index.js.map +1 -0
- package/build/barcode/types.d.ts +17 -0
- package/build/barcode/types.d.ts.map +1 -0
- package/build/barcode/types.js +22 -0
- package/build/barcode/types.js.map +1 -0
- package/build/index.d.ts +15 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +110 -0
- package/build/index.js.map +1 -0
- package/build/package.json +155 -0
- package/build/types/index.d.ts +49 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/index.js +4 -0
- package/build/types/index.js.map +1 -0
- package/build/utills.d.ts +12 -0
- package/build/utills.d.ts.map +1 -0
- package/build/utills.js +111 -0
- package/build/utills.js.map +1 -0
- package/build/webtonative.min.js +1 -0
- package/buildScript.ts +35 -0
- package/client.ts +106 -0
- package/index.d.ts +65 -0
- package/package.json +36 -31
- package/src/ATTConsent/index.ts +51 -0
- package/src/ATTConsent/types.ts +17 -0
- package/src/AdMob/index.ts +113 -0
- package/src/AdMob/types.ts +37 -0
- package/src/AppReview/index.ts +19 -0
- package/src/AppReview/types.ts +12 -0
- package/src/AppsFlyer/index.ts +46 -0
- package/src/AppsFlyer/types.ts +10 -0
- package/src/BackgroundLocation/index.ts +78 -0
- package/src/BackgroundLocation/types.ts +34 -0
- package/src/Beacon/index.ts +28 -0
- package/src/Beacon/types.ts +22 -0
- package/src/Biometric/index.ts +126 -0
- package/src/Biometric/types.ts +27 -0
- package/src/Bluetooth/index.ts +71 -0
- package/src/Bluetooth/types.ts +40 -0
- package/src/BottomNavigation/index.ts +39 -0
- package/src/BottomNavigation/types.ts +9 -0
- package/src/Clipboard/index.ts +48 -0
- package/src/Clipboard/types.ts +30 -0
- package/src/Facebook/events.ts +45 -0
- package/src/Facebook/index.ts +3 -0
- package/src/Facebook/types.ts +24 -0
- package/src/Firebase/Analytics/index.ts +127 -0
- package/src/Firebase/Messaging/index.ts +73 -0
- package/src/Firebase/index.ts +4 -0
- package/src/Firebase/types.ts +74 -0
- package/src/FirebaseAnalytics/index.ts +3 -0
- package/src/Haptics/index.ts +17 -0
- package/src/Haptics/types.ts +8 -0
- package/src/InAppPurchase/index.ts +92 -0
- package/src/InAppPurchase/types.ts +35 -0
- package/src/InAppUpdate/index.ts +40 -0
- package/src/InAppUpdate/types.ts +17 -0
- package/src/MediaPlayer/index.ts +56 -0
- package/src/MediaPlayer/types.ts +15 -0
- package/src/NativeContacts/index.ts +50 -0
- package/src/NativeContacts/types.ts +16 -0
- package/src/Notification/index.ts +41 -0
- package/src/Notification/types.ts +16 -0
- package/src/OneSignal/index.ts +54 -0
- package/src/OneSignal/types.ts +15 -0
- package/src/Printing/index.ts +17 -0
- package/src/Printing/types.ts +9 -0
- package/src/Screen/index.ts +34 -0
- package/src/Screen/types.ts +8 -0
- package/src/Siri/index.ts +23 -0
- package/src/Siri/types.ts +14 -0
- package/src/SocialLogin/apple.ts +31 -0
- package/src/SocialLogin/facebook.ts +64 -0
- package/src/SocialLogin/google.ts +64 -0
- package/src/SocialLogin/index.ts +20 -0
- package/src/SocialLogin/types.ts +52 -0
- package/src/Stripe/index.ts +54 -0
- package/src/Stripe/types.ts +37 -0
- package/src/VoiceSearch/index.ts +37 -0
- package/src/VoiceSearch/types.ts +12 -0
- package/src/barcode/barcode-scan.ts +59 -0
- package/src/barcode/barcode-types.ts +22 -0
- package/src/barcode/formats.ts +19 -0
- package/src/barcode/index.ts +5 -0
- package/src/barcode/types.ts +18 -0
- package/src/index.ts +105 -0
- package/src/types/index.ts +71 -0
- package/src/utills.ts +110 -0
- package/tsconfig.json +27 -0
- package/webpack.config.js +57 -0
- package/ATTConsent/index.js +0 -1
- package/AdMob/index.js +0 -1
- package/AppReview/index.js +0 -1
- package/AppsFlyer/index.js +0 -4
- package/BackgroundLocation/index.js +0 -4
- package/Beacon/index.js +0 -1
- package/Biometric/index.js +0 -1
- package/Bluetooth/index.js +0 -1
- package/BottomNavigation/index.js +0 -4
- package/Clipboard/index.js +0 -4
- package/Facebook/events.js +0 -4
- package/Facebook/index.js +0 -1
- package/Firebase/Analytics/index.js +0 -4
- package/Firebase/Messaging/index.js +0 -4
- package/Firebase/index.js +0 -1
- package/FirebaseAnalytics/index.js +0 -1
- package/Haptics/index.js +0 -1
- package/InAppPurchase/index.js +0 -1
- package/InAppUpdate/index.js +0 -1
- package/MediaPlayer/index.js +0 -7
- package/NativeContacts/index.js +0 -6
- package/Notification/index.js +0 -5
- package/OneSignal/index.js +0 -1
- package/Printing/index.js +0 -1
- package/Screen/index.js +0 -4
- package/Siri/index.js +0 -1
- package/SocialLogin/apple.js +0 -1
- package/SocialLogin/facebook.js +0 -9
- package/SocialLogin/google.js +0 -9
- package/SocialLogin/index.js +0 -1
- package/Stripe/index.js +0 -1
- package/VoiceSearch/index.js +0 -1
- package/barcode/barcode-scan.js +0 -1
- package/barcode/formats.js +0 -1
- package/barcode/index.js +0 -1
- package/barcode/types.js +0 -1
- package/index.js +0 -4
- package/utills.js +0 -1
- package/webtonative.min.js +0 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { platform, registerCb, webToNative, webToNativeIos } from "../utills";
|
|
2
|
+
import { SocialLoginOptions, GoogleLoginResponse, GoogleLogoutResponse, GoogleIosMessage } from "./types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This function handles native Google login
|
|
6
|
+
* @param options - Options for Google login
|
|
7
|
+
* @example wtn.socialLogin.google.login({
|
|
8
|
+
* callback:(data)=>{
|
|
9
|
+
* console.log(data);
|
|
10
|
+
* }
|
|
11
|
+
* });
|
|
12
|
+
*/
|
|
13
|
+
export const login = (options: SocialLoginOptions): void => {
|
|
14
|
+
if (["ANDROID_APP", "IOS_APP"].includes(platform)) {
|
|
15
|
+
const { callback, scope } = options;
|
|
16
|
+
|
|
17
|
+
registerCb((response: GoogleLoginResponse) => {
|
|
18
|
+
const { type } = response;
|
|
19
|
+
if (type === "googleLoginToken") {
|
|
20
|
+
callback && callback(response);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
platform === "ANDROID_APP" && webToNative.signInWithGoogle();
|
|
25
|
+
|
|
26
|
+
if (platform === "IOS_APP" && webToNativeIos) {
|
|
27
|
+
webToNativeIos.postMessage({
|
|
28
|
+
action: "googleSignIn",
|
|
29
|
+
scope,
|
|
30
|
+
} as GoogleIosMessage);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* This function handles native Google logout
|
|
37
|
+
* @param options - Options for Google logout
|
|
38
|
+
* @example wtn.socialLogin.google.logout({
|
|
39
|
+
* callback:(data)=>{
|
|
40
|
+
* console.log(data);
|
|
41
|
+
* }
|
|
42
|
+
* });
|
|
43
|
+
*/
|
|
44
|
+
export const logout = (options: SocialLoginOptions): void => {
|
|
45
|
+
if (["ANDROID_APP", "IOS_APP"].includes(platform)) {
|
|
46
|
+
const { callback, scope } = options;
|
|
47
|
+
|
|
48
|
+
registerCb((response: GoogleLogoutResponse) => {
|
|
49
|
+
const { type } = response;
|
|
50
|
+
if (type === "googleLogOut") {
|
|
51
|
+
callback && callback(response);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
platform === "ANDROID_APP" && webToNative.signOutWithGoogle();
|
|
56
|
+
|
|
57
|
+
if (platform === "IOS_APP" && webToNativeIos) {
|
|
58
|
+
webToNativeIos.postMessage({
|
|
59
|
+
action: "googleSignOut",
|
|
60
|
+
scope,
|
|
61
|
+
} as GoogleIosMessage);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { login as loginFacebook, logout as logoutFacebook } from "./facebook";
|
|
2
|
+
import { login as loginApple } from "./apple";
|
|
3
|
+
import { login as loginGoogle, logout as logoutGoogle } from "./google";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Social login module for Facebook, Google, and Apple authentication
|
|
7
|
+
*/
|
|
8
|
+
export const socialLogin = {
|
|
9
|
+
facebook: {
|
|
10
|
+
login: loginFacebook,
|
|
11
|
+
logout: logoutFacebook,
|
|
12
|
+
},
|
|
13
|
+
google: {
|
|
14
|
+
login: loginGoogle,
|
|
15
|
+
logout: logoutGoogle,
|
|
16
|
+
},
|
|
17
|
+
apple: {
|
|
18
|
+
login: loginApple,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Common types for social login
|
|
2
|
+
export interface SocialLoginResponse {
|
|
3
|
+
type: string;
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface SocialLoginCallback {
|
|
8
|
+
(response: SocialLoginResponse): void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface SocialLoginOptions {
|
|
12
|
+
callback?: SocialLoginCallback;
|
|
13
|
+
scope?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Facebook types
|
|
17
|
+
export interface FacebookLoginResponse extends SocialLoginResponse {
|
|
18
|
+
type: 'fbLoginToken';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface FacebookLogoutResponse extends SocialLoginResponse {
|
|
22
|
+
type: 'fbLogOut';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface FacebookIosMessage {
|
|
26
|
+
action: 'fbSignIn' | 'fbSignOut';
|
|
27
|
+
scope?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Google types
|
|
31
|
+
export interface GoogleLoginResponse extends SocialLoginResponse {
|
|
32
|
+
type: 'googleLoginToken';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface GoogleLogoutResponse extends SocialLoginResponse {
|
|
36
|
+
type: 'googleLogOut';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface GoogleIosMessage {
|
|
40
|
+
action: 'googleSignIn' | 'googleSignOut';
|
|
41
|
+
scope?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Apple types
|
|
45
|
+
export interface AppleLoginResponse extends SocialLoginResponse {
|
|
46
|
+
type: 'appleLoginToken';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface AppleIosMessage {
|
|
50
|
+
action: 'appleSignIn';
|
|
51
|
+
scope?: string;
|
|
52
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { platform, webToNative, webToNativeIos, registerCb } from "../utills";
|
|
2
|
+
import { StripeOptions, StripePaymentData, StripeIosMessage } from "./types";
|
|
3
|
+
|
|
4
|
+
export const makeTapToPay = (options: StripeOptions): void => {
|
|
5
|
+
if (["ANDROID_APP", "IOS_APP"].includes(platform)) {
|
|
6
|
+
const {
|
|
7
|
+
callback,
|
|
8
|
+
apiUrl = null,
|
|
9
|
+
amount,
|
|
10
|
+
currency,
|
|
11
|
+
isSimulated = false,
|
|
12
|
+
captureMethod = "automatic",
|
|
13
|
+
connectionToken,
|
|
14
|
+
stripeLocationId,
|
|
15
|
+
clientSecret = null
|
|
16
|
+
} = options;
|
|
17
|
+
|
|
18
|
+
registerCb((response) => {
|
|
19
|
+
const { type } = response;
|
|
20
|
+
if (type === "makeTapToPayStripePayment") {
|
|
21
|
+
callback && callback(response);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
let paymentData: StripePaymentData = {
|
|
26
|
+
secretToken: connectionToken,
|
|
27
|
+
amount,
|
|
28
|
+
currency,
|
|
29
|
+
isSimulated,
|
|
30
|
+
captureMethod,
|
|
31
|
+
locationId: stripeLocationId
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
if (apiUrl) {
|
|
35
|
+
paymentData.apiUrl = apiUrl;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (clientSecret) {
|
|
39
|
+
paymentData.client_secret = clientSecret;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (platform === "ANDROID_APP") {
|
|
43
|
+
webToNative.makeTapToPayStripePayment(JSON.stringify(paymentData));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (platform === "IOS_APP" && webToNativeIos) {
|
|
47
|
+
const iosMessage: StripeIosMessage = {
|
|
48
|
+
"action": "makeTapToPayStripePayment",
|
|
49
|
+
...paymentData
|
|
50
|
+
};
|
|
51
|
+
webToNativeIos.postMessage(iosMessage);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { BaseCallback, BaseResponse } from "../types";
|
|
2
|
+
|
|
3
|
+
export interface StripeResponse extends BaseResponse {
|
|
4
|
+
type: "makeTapToPayStripePayment";
|
|
5
|
+
// Additional response properties can be added here based on actual response structure
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface StripeCallback extends BaseCallback {
|
|
9
|
+
(response: StripeResponse): void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface StripePaymentData {
|
|
13
|
+
secretToken: string;
|
|
14
|
+
amount: number;
|
|
15
|
+
currency: string;
|
|
16
|
+
isSimulated: boolean;
|
|
17
|
+
captureMethod: string;
|
|
18
|
+
locationId: string;
|
|
19
|
+
apiUrl?: string;
|
|
20
|
+
client_secret?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface StripeOptions {
|
|
24
|
+
callback?: StripeCallback;
|
|
25
|
+
apiUrl?: string;
|
|
26
|
+
amount: number;
|
|
27
|
+
currency: string;
|
|
28
|
+
isSimulated?: boolean;
|
|
29
|
+
captureMethod?: string;
|
|
30
|
+
connectionToken: string;
|
|
31
|
+
stripeLocationId: string;
|
|
32
|
+
clientSecret?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface StripeIosMessage extends StripePaymentData {
|
|
36
|
+
action: string;
|
|
37
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { webToNative, isNativeApp, registerCb } from "../utills";
|
|
2
|
+
import { VoiceSearchOptions, VoiceSearchCallback, VoiceSearchResponse } from "./types";
|
|
3
|
+
|
|
4
|
+
let voiceSearchCb: VoiceSearchCallback | null = null;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* This function opens native voice search
|
|
8
|
+
* @param options Configuration options for voice search
|
|
9
|
+
* @example wtn.openVoiceSearch({
|
|
10
|
+
* onVoiceSearch:(value)=>{
|
|
11
|
+
* console.log(value);
|
|
12
|
+
* }
|
|
13
|
+
* });
|
|
14
|
+
*/
|
|
15
|
+
const openVoiceSearch = (options: VoiceSearchOptions = {}): any => {
|
|
16
|
+
const { onVoiceSearch } = options;
|
|
17
|
+
|
|
18
|
+
registerCb((response) => {
|
|
19
|
+
const { type, results } = response as VoiceSearchResponse;
|
|
20
|
+
if (type === "VOICE_SEARCH_RESULT") {
|
|
21
|
+
voiceSearchCb && voiceSearchCb(results);
|
|
22
|
+
voiceSearchCb = null;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
if (isNativeApp) {
|
|
27
|
+
webToNative.openVoiceSearch();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (typeof onVoiceSearch === "function") {
|
|
31
|
+
voiceSearchCb = onVoiceSearch;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return this;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export default openVoiceSearch;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseResponse } from "../types";
|
|
2
|
+
|
|
3
|
+
export interface VoiceSearchResponse extends BaseResponse {
|
|
4
|
+
type: "VOICE_SEARCH_RESULT";
|
|
5
|
+
results: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type VoiceSearchCallback = (results: string) => void;
|
|
9
|
+
|
|
10
|
+
export interface VoiceSearchOptions {
|
|
11
|
+
onVoiceSearch?: VoiceSearchCallback;
|
|
12
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isNativeApp,
|
|
3
|
+
platform,
|
|
4
|
+
webToNative,
|
|
5
|
+
registerCb,
|
|
6
|
+
webToNativeIos,
|
|
7
|
+
} from "../utills";
|
|
8
|
+
import Format from "./formats";
|
|
9
|
+
|
|
10
|
+
// Define interfaces for barcode scanner
|
|
11
|
+
interface BarcodeScanOptions {
|
|
12
|
+
onBarcodeSearch?: (value: string) => void;
|
|
13
|
+
format?: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface BarcodeScanResponse {
|
|
17
|
+
type: string;
|
|
18
|
+
value: string;
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* This function opens native barcode scanner from Android/Ios app.
|
|
24
|
+
* @param {object} options
|
|
25
|
+
* @example wtn.onScanner({
|
|
26
|
+
* onBarcodeSearch:(value)=>{
|
|
27
|
+
* console.log(value);
|
|
28
|
+
* }
|
|
29
|
+
* });
|
|
30
|
+
*/
|
|
31
|
+
const BarcodeScan = (options: BarcodeScanOptions): void => {
|
|
32
|
+
if (["ANDROID_APP", "IOS_APP"].includes(platform)) {
|
|
33
|
+
const { onBarcodeSearch, format } = options;
|
|
34
|
+
|
|
35
|
+
registerCb((response: BarcodeScanResponse) => {
|
|
36
|
+
const { type, value } = response;
|
|
37
|
+
if (type === "BARCODE_SCAN") {
|
|
38
|
+
onBarcodeSearch && onBarcodeSearch(value);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
if (platform === "ANDROID_APP" && webToNative.startScanner) {
|
|
43
|
+
webToNative.startScanner(
|
|
44
|
+
JSON.stringify({
|
|
45
|
+
formats: format ? [format] : [],
|
|
46
|
+
})
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (platform === "IOS_APP" && webToNativeIos) {
|
|
51
|
+
webToNativeIos.postMessage({
|
|
52
|
+
action: "barcodeScan",
|
|
53
|
+
barcodeFormat: format ? String(format) : String(Format.ALL_FORMATS),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export default BarcodeScan;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BaseResponse } from "../types";
|
|
2
|
+
|
|
3
|
+
export interface BarcodeScanResponse extends BaseResponse {
|
|
4
|
+
type: "BARCODE_SCAN";
|
|
5
|
+
value: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type BarcodeScanCallback = (value: string) => void;
|
|
9
|
+
|
|
10
|
+
export interface BarcodeScanOptions {
|
|
11
|
+
onBarcodeSearch?: BarcodeScanCallback;
|
|
12
|
+
format?: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface BarcodeScanAndroidParams {
|
|
16
|
+
formats: number[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface BarcodeScanIosMessage {
|
|
20
|
+
action: string;
|
|
21
|
+
barcodeFormat: string;
|
|
22
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Barcode formats
|
|
2
|
+
export enum BarcodeFormat {
|
|
3
|
+
ALL_FORMATS = 0,
|
|
4
|
+
CODE_128 = 1,
|
|
5
|
+
CODE_39 = 2,
|
|
6
|
+
CODE_93 = 4,
|
|
7
|
+
CODABAR = 8,
|
|
8
|
+
DATA_MATRIX = 16,
|
|
9
|
+
EAN_13 = 32,
|
|
10
|
+
EAN_8 = 64,
|
|
11
|
+
ITF = 128,
|
|
12
|
+
QR_CODE = 256,
|
|
13
|
+
UPC_A = 512,
|
|
14
|
+
UPC_E = 1024,
|
|
15
|
+
PDF417 = 2048,
|
|
16
|
+
AZTEC = 4096
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default BarcodeFormat;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Barcode types
|
|
2
|
+
export enum BarcodeType {
|
|
3
|
+
QR_CODE = 'QR_CODE',
|
|
4
|
+
DATA_MATRIX = 'DATA_MATRIX',
|
|
5
|
+
UPC_E = 'UPC_E',
|
|
6
|
+
UPC_A = 'UPC_A',
|
|
7
|
+
EAN_8 = 'EAN_8',
|
|
8
|
+
EAN_13 = 'EAN_13',
|
|
9
|
+
CODE_128 = 'CODE_128',
|
|
10
|
+
CODE_39 = 'CODE_39',
|
|
11
|
+
CODE_93 = 'CODE_93',
|
|
12
|
+
CODABAR = 'CODABAR',
|
|
13
|
+
ITF = 'ITF',
|
|
14
|
+
AZTEC = 'AZTEC',
|
|
15
|
+
PDF_417 = 'PDF_417'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default BarcodeType;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Repository for webtonative javascript sdk. Build your android/ios app from https://webtonative.com.
|
|
3
|
+
* This is in beta phase.
|
|
4
|
+
* @example npm install webtonative
|
|
5
|
+
* import webtonative from "webtonative";
|
|
6
|
+
* const wtn = webtonative();
|
|
7
|
+
*/
|
|
8
|
+
import { isNativeApp, webToNative, platform, webToNativeIos, registerCb } from "./utills";
|
|
9
|
+
import { StatusBarOptions, DownloadBlobFileOptions, CustomFileDownloadOptions } from "./types";
|
|
10
|
+
|
|
11
|
+
export const isAndroidApp: boolean = platform === "ANDROID_APP";
|
|
12
|
+
export const isIosApp: boolean = platform === "IOS_APP";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* This function hides splash screen
|
|
16
|
+
* @example wtn.hideSplashScreen()
|
|
17
|
+
*/
|
|
18
|
+
export const hideSplashScreen = (): void => {
|
|
19
|
+
isNativeApp && webToNative.hideSplashScreen && webToNative.hideSplashScreen();
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const statusBar = (options: StatusBarOptions): void => {
|
|
23
|
+
if (isNativeApp) {
|
|
24
|
+
if (isAndroidApp) {
|
|
25
|
+
webToNative.statusBar && webToNative.statusBar(JSON.stringify(options));
|
|
26
|
+
} else if (isIosApp) {
|
|
27
|
+
webToNativeIos && webToNativeIos.postMessage({
|
|
28
|
+
action: "statusBar",
|
|
29
|
+
color: options.color,
|
|
30
|
+
style: options.style,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const downloadFile = (downloadUrl: string): void => {
|
|
37
|
+
if (isNativeApp) {
|
|
38
|
+
if (isAndroidApp) {
|
|
39
|
+
// Android implementation
|
|
40
|
+
} else if (isIosApp) {
|
|
41
|
+
webToNativeIos && webToNativeIos.postMessage({
|
|
42
|
+
action: "downloadFile",
|
|
43
|
+
downloadUrl,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const downloadBlobFile = ({fileName, downloadUrl}: DownloadBlobFileOptions): void => {
|
|
50
|
+
if (["IOS_APP"].includes(platform)) {
|
|
51
|
+
isIosApp && webToNativeIos && webToNativeIos.postMessage({
|
|
52
|
+
action: "downloadBlobFile",
|
|
53
|
+
fileName,
|
|
54
|
+
url: downloadUrl,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const customFileDownload = ({downloadUrl, fileName, isBlob, mimeType, cookies, userAgent, openFileAfterDownload}: CustomFileDownloadOptions): void => {
|
|
60
|
+
if (["ANDROID_APP"].includes(platform)) {
|
|
61
|
+
platform === "ANDROID_APP" && webToNative.downloadFile && webToNative.downloadFile(JSON.stringify({
|
|
62
|
+
url: downloadUrl,
|
|
63
|
+
fileName,
|
|
64
|
+
isBlob,
|
|
65
|
+
mimeType,
|
|
66
|
+
cookies,
|
|
67
|
+
userAgent,
|
|
68
|
+
openFileAfterDownload
|
|
69
|
+
}))
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export const deviceInfo = (): Promise<any> => {
|
|
74
|
+
return new Promise((resolve, reject) => {
|
|
75
|
+
registerCb(
|
|
76
|
+
(results) => {
|
|
77
|
+
if (results) {
|
|
78
|
+
resolve(results);
|
|
79
|
+
} else {
|
|
80
|
+
reject({
|
|
81
|
+
err: "Error getting device info",
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
key: "deviceInfo",
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
if (platform === "ANDROID_APP") {
|
|
90
|
+
webToNative.getDeviceInfo && webToNative.getDeviceInfo();
|
|
91
|
+
} else if (platform === "IOS_APP") {
|
|
92
|
+
webToNativeIos && webToNativeIos.postMessage({
|
|
93
|
+
action: "deviceInfo",
|
|
94
|
+
});
|
|
95
|
+
} else {
|
|
96
|
+
reject("This function will work in Native App Powered By WebToNative");
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export const showInAppReview = (): void => {
|
|
102
|
+
isNativeApp && webToNative.showInAppReview && webToNative.showInAppReview();
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// Export all other functions from the original file
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// Define common types used throughout the package
|
|
2
|
+
|
|
3
|
+
// Platform types
|
|
4
|
+
export type Platform = 'ANDROID_APP' | 'IOS_APP' | 'WEBSITE';
|
|
5
|
+
|
|
6
|
+
// Base response interface for all native responses
|
|
7
|
+
export interface BaseResponse {
|
|
8
|
+
type: string;
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Base callback interface for all native callbacks
|
|
13
|
+
export interface BaseCallback {
|
|
14
|
+
(response: BaseResponse): void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Callback function types
|
|
18
|
+
export type CallbackFunction = (response: any) => void;
|
|
19
|
+
|
|
20
|
+
// Register callback options
|
|
21
|
+
export interface RegisterCallbackOptions {
|
|
22
|
+
key?: string;
|
|
23
|
+
ignoreDelete?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Status bar options
|
|
27
|
+
export interface StatusBarOptions {
|
|
28
|
+
color?: string;
|
|
29
|
+
style?: 'light' | 'dark';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Download file options
|
|
33
|
+
export interface DownloadBlobFileOptions {
|
|
34
|
+
fileName: string;
|
|
35
|
+
downloadUrl: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Custom file download options
|
|
39
|
+
export interface CustomFileDownloadOptions {
|
|
40
|
+
downloadUrl: string;
|
|
41
|
+
fileName: string;
|
|
42
|
+
isBlob?: boolean;
|
|
43
|
+
mimeType?: string;
|
|
44
|
+
cookies?: string;
|
|
45
|
+
userAgent?: string;
|
|
46
|
+
openFileAfterDownload?: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Device info response
|
|
50
|
+
export interface DeviceInfoResponse {
|
|
51
|
+
[key: string]: any;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Native interface
|
|
55
|
+
export interface WebToNativeInterface {
|
|
56
|
+
getAndroidVersion?: () => string;
|
|
57
|
+
hideSplashScreen?: () => void;
|
|
58
|
+
statusBar?: (options: string) => void;
|
|
59
|
+
downloadFile?: (options: string) => void;
|
|
60
|
+
getDeviceInfo?: () => void;
|
|
61
|
+
showInAppReview?: () => void;
|
|
62
|
+
startScanner?: (options: string) => void;
|
|
63
|
+
androidCBHook?: (results: string) => void;
|
|
64
|
+
androidAdMobCBHook?: (results: string) => void;
|
|
65
|
+
[key: string]: any;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// iOS interface
|
|
69
|
+
export interface WebToNativeIosInterface {
|
|
70
|
+
postMessage: (message: any) => void;
|
|
71
|
+
}
|
package/src/utills.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Platform, WebToNativeInterface, WebToNativeIosInterface, CallbackFunction, RegisterCallbackOptions } from './types';
|
|
2
|
+
|
|
3
|
+
const isClient: boolean = typeof window !== "undefined";
|
|
4
|
+
const webToNative: WebToNativeInterface = (isClient && (window as any).WebToNativeInterface) || {};
|
|
5
|
+
const webToNativeIos: WebToNativeIosInterface | false =
|
|
6
|
+
isClient &&
|
|
7
|
+
(window as any).webkit &&
|
|
8
|
+
(window as any).webkit.messageHandlers &&
|
|
9
|
+
(window as any).webkit.messageHandlers.webToNativeInterface;
|
|
10
|
+
const platform: Platform = webToNative.getAndroidVersion
|
|
11
|
+
? "ANDROID_APP"
|
|
12
|
+
: webToNativeIos
|
|
13
|
+
? "IOS_APP"
|
|
14
|
+
: "WEBSITE";
|
|
15
|
+
const isNativeApp: boolean = isClient && platform !== "WEBSITE";
|
|
16
|
+
const cbObj: Record<string | number, { cb: CallbackFunction; ignoreDelete?: boolean }> = {};
|
|
17
|
+
let counter: number = 1;
|
|
18
|
+
let abMobCb: CallbackFunction | null = null;
|
|
19
|
+
if (isNativeApp) {
|
|
20
|
+
webToNative.androidCBHook = (results: string) => {
|
|
21
|
+
var response: any = results;
|
|
22
|
+
try {
|
|
23
|
+
response = JSON.parse(results);
|
|
24
|
+
} catch (e) {
|
|
25
|
+
console.log(e);
|
|
26
|
+
}
|
|
27
|
+
const { type } = response;
|
|
28
|
+
for (var key in cbObj) {
|
|
29
|
+
const { cb, ignoreDelete = false } = cbObj[key];
|
|
30
|
+
if (response && response.reqType) {
|
|
31
|
+
if (key == response["reqType"]) {
|
|
32
|
+
cb(response);
|
|
33
|
+
if (!ignoreDelete) {
|
|
34
|
+
delete cbObj[key];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
} else {
|
|
38
|
+
cb(response);
|
|
39
|
+
if (!ignoreDelete) {
|
|
40
|
+
delete cbObj[key];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
(window as any).iOSAdMobCBHook = webToNative.androidAdMobCBHook = (results: string) => {
|
|
46
|
+
const responseObj = JSON.parse(results);
|
|
47
|
+
abMobCb && abMobCb(responseObj);
|
|
48
|
+
};
|
|
49
|
+
(window as any).iosCBHook = (results: string) => {
|
|
50
|
+
var response: any = results;
|
|
51
|
+
try {
|
|
52
|
+
response = JSON.parse(results);
|
|
53
|
+
} catch (e) {
|
|
54
|
+
console.log(e);
|
|
55
|
+
}
|
|
56
|
+
for (var key in cbObj) {
|
|
57
|
+
const { cb, ignoreDelete = false } = cbObj[key];
|
|
58
|
+
if (response && response.reqType) {
|
|
59
|
+
if (key == response["reqType"]) {
|
|
60
|
+
cb(response);
|
|
61
|
+
if (!ignoreDelete) {
|
|
62
|
+
delete cbObj[key];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
cb(response);
|
|
67
|
+
if (!ignoreDelete) {
|
|
68
|
+
delete cbObj[key];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const registerCb = (cb: CallbackFunction, obj?: RegisterCallbackOptions) => {
|
|
76
|
+
if (typeof cb === "function") {
|
|
77
|
+
if (obj && obj.key) {
|
|
78
|
+
cbObj[obj["key"]] = { cb, ignoreDelete: obj.ignoreDelete ? true : false };
|
|
79
|
+
} else {
|
|
80
|
+
cbObj[counter] = { cb, ignoreDelete: obj && obj.ignoreDelete ? true : false };
|
|
81
|
+
counter += 1;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const registerForAbMobCb = (cb: CallbackFunction) => {
|
|
86
|
+
if (typeof cb === "function") {
|
|
87
|
+
abMobCb = cb;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const deRegisterForAbMobCb = () => {
|
|
91
|
+
if (abMobCb) {
|
|
92
|
+
abMobCb = null;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const deRegisterCbByKey = (key: string | number) => {
|
|
97
|
+
delete cbObj[key];
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export {
|
|
101
|
+
webToNative,
|
|
102
|
+
isClient,
|
|
103
|
+
webToNativeIos,
|
|
104
|
+
platform,
|
|
105
|
+
isNativeApp,
|
|
106
|
+
registerCb,
|
|
107
|
+
registerForAbMobCb,
|
|
108
|
+
deRegisterForAbMobCb,
|
|
109
|
+
deRegisterCbByKey,
|
|
110
|
+
};
|