@microbt/environment 1.2.1 → 1.2.3
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/dist/esm/hybrid.d.ts +1 -1
- package/dist/esm/hybrid.js +52 -20
- package/package.json +1 -1
package/dist/esm/hybrid.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare function bridgeCall(method: string, params: Record<string, string>, callback: (resp: string) => void): void;
|
|
2
|
-
export declare function bridgeBootstrap(): void
|
|
2
|
+
export declare function bridgeBootstrap(): Promise<void>;
|
|
3
3
|
export declare function inSuperAcme(): boolean;
|
|
4
4
|
export declare function superAcmeVersion(): {
|
|
5
5
|
version: string;
|
package/dist/esm/hybrid.js
CHANGED
|
@@ -12,7 +12,11 @@ document.addEventListener("WebViewJavascriptBridgeReady", () => {
|
|
|
12
12
|
});
|
|
13
13
|
function bridgeCall(method, params, callback) {
|
|
14
14
|
var _a;
|
|
15
|
-
|
|
15
|
+
if (method === "log") {
|
|
16
|
+
Logger.debug("bridgeCall", method, params);
|
|
17
|
+
} else {
|
|
18
|
+
Logger.info("bridgeCall", method, params);
|
|
19
|
+
}
|
|
16
20
|
try {
|
|
17
21
|
if (((_a = window.SuperAcme) == null ? void 0 : _a.call) && typeof window.SuperAcme.call === "function") {
|
|
18
22
|
window.SuperAcme.call(method, params, callback);
|
|
@@ -36,27 +40,55 @@ function bridgeCall(method, params, callback) {
|
|
|
36
40
|
}
|
|
37
41
|
}
|
|
38
42
|
function bridgeBootstrap() {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
function bootstrap(callback) {
|
|
45
|
+
var _a, _b, _c;
|
|
46
|
+
if (!callback || typeof callback !== "function") {
|
|
47
|
+
const error = new Error("Invalid callback provided");
|
|
48
|
+
Logger.error("bootstrap:", error);
|
|
49
|
+
reject(error);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (window.SuperAcme && typeof window.SuperAcme.call === "function") {
|
|
53
|
+
Logger.debug("bootstrap: SuperAcme bridge is ready");
|
|
54
|
+
callback();
|
|
55
|
+
resolve();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (Array.isArray(window.WKWVJBCallbacks)) {
|
|
59
|
+
Logger.debug("bootstrap: Adding callback to existing WKWVJBCallbacks queue");
|
|
60
|
+
window.WKWVJBCallbacks.push(() => {
|
|
61
|
+
callback();
|
|
62
|
+
resolve();
|
|
63
|
+
});
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
Logger.debug("bootstrap: Initializing WKWVJBCallbacks");
|
|
67
|
+
window.WKWVJBCallbacks = [
|
|
68
|
+
() => {
|
|
69
|
+
callback();
|
|
70
|
+
resolve();
|
|
71
|
+
}
|
|
72
|
+
];
|
|
73
|
+
if (((_c = (_b = (_a = window.webkit) == null ? void 0 : _a.messageHandlers) == null ? void 0 : _b.iOS_Native_InjectJavascript) == null ? void 0 : _c.postMessage) && typeof window.webkit.messageHandlers.iOS_Native_InjectJavascript.postMessage === "function") {
|
|
74
|
+
window.webkit.messageHandlers.iOS_Native_InjectJavascript.postMessage(null);
|
|
75
|
+
} else {
|
|
76
|
+
const error = new Error("iOS bridge postMessage method not available or not a function");
|
|
77
|
+
Logger.warn(error.message);
|
|
78
|
+
reject(error);
|
|
79
|
+
}
|
|
50
80
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
81
|
+
if (iOSWebview) {
|
|
82
|
+
bootstrap(() => {
|
|
83
|
+
const ready = new CustomEvent("WebViewJavascriptBridgeReady", {
|
|
84
|
+
detail: { platform: "ios" }
|
|
85
|
+
});
|
|
86
|
+
document.dispatchEvent(ready);
|
|
56
87
|
});
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
88
|
+
} else {
|
|
89
|
+
reject(new Error("Not in iOS webview"));
|
|
90
|
+
}
|
|
91
|
+
});
|
|
60
92
|
}
|
|
61
93
|
function inSuperAcme() {
|
|
62
94
|
return navigator.userAgent.toLowerCase().includes("superacme");
|