@microbt/environment 1.2.13 → 1.2.14
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/global.d.ts +4 -0
- package/dist/esm/hybrid.js +64 -23
- package/package.json +1 -1
package/dist/esm/global.d.ts
CHANGED
package/dist/esm/hybrid.js
CHANGED
|
@@ -1,43 +1,84 @@
|
|
|
1
1
|
// src/hybrid.ts
|
|
2
|
+
import { arms } from "./arms";
|
|
2
3
|
import Logger from "./logger";
|
|
3
4
|
import { iOSWebview } from "./platform";
|
|
4
5
|
var queue = [];
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
var isFlushMessageQueueAvailable = () => {
|
|
7
|
+
var _a, _b, _c;
|
|
8
|
+
if (!iOSWebview) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
const postMessage = (_c = (_b = (_a = window.webkit) == null ? void 0 : _a.messageHandlers) == null ? void 0 : _b.iOS_Native_FlushMessageQueue) == null ? void 0 : _c.postMessage;
|
|
12
|
+
return typeof postMessage === "function";
|
|
13
|
+
};
|
|
14
|
+
var hasReportedMissingHandler = false;
|
|
15
|
+
var reportMissingHandlerOnce = () => {
|
|
16
|
+
if (hasReportedMissingHandler) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
hasReportedMissingHandler = true;
|
|
20
|
+
Logger.warn("iOS_Native_FlushMessageQueue unavailable, bridge call rejected");
|
|
21
|
+
arms.sum("BRIDGE_FLUSH_QUEUE_MISSING");
|
|
22
|
+
};
|
|
23
|
+
var buildErrorResponse = (code, method, params, message, stack) => JSON.stringify({
|
|
24
|
+
success: false,
|
|
25
|
+
error: {
|
|
26
|
+
code,
|
|
27
|
+
message,
|
|
28
|
+
method,
|
|
29
|
+
params,
|
|
30
|
+
stack,
|
|
31
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
32
|
+
}
|
|
12
33
|
});
|
|
13
|
-
|
|
34
|
+
var invokeBridge = (method, params, callback) => {
|
|
14
35
|
var _a;
|
|
15
|
-
if (method === "log") {
|
|
16
|
-
Logger.debug("bridgeCall", method, params);
|
|
17
|
-
} else {
|
|
18
|
-
Logger.info("bridgeCall", method, params);
|
|
19
|
-
}
|
|
20
36
|
try {
|
|
21
37
|
if (((_a = window.SuperAcme) == null ? void 0 : _a.call) && typeof window.SuperAcme.call === "function") {
|
|
38
|
+
if (!isFlushMessageQueueAvailable()) {
|
|
39
|
+
reportMissingHandlerOnce();
|
|
40
|
+
callback(
|
|
41
|
+
buildErrorResponse(
|
|
42
|
+
"BRIDGE_FLUSH_QUEUE_MISSING",
|
|
43
|
+
method,
|
|
44
|
+
params,
|
|
45
|
+
"iOS_Native_FlushMessageQueue is unavailable"
|
|
46
|
+
)
|
|
47
|
+
);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
22
50
|
window.SuperAcme.call(method, params, callback);
|
|
23
51
|
} else {
|
|
24
52
|
queue.push({ method, params, callback });
|
|
25
53
|
}
|
|
26
54
|
} catch (error) {
|
|
27
55
|
Logger.error("bridgeCall failed:", error);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
code: "BRIDGE_CALL_ERROR",
|
|
32
|
-
message: error instanceof Error ? error.message : String(error),
|
|
56
|
+
callback(
|
|
57
|
+
buildErrorResponse(
|
|
58
|
+
"BRIDGE_CALL_ERROR",
|
|
33
59
|
method,
|
|
34
60
|
params,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
61
|
+
error instanceof Error ? error.message : String(error),
|
|
62
|
+
error instanceof Error ? error.stack : void 0
|
|
63
|
+
)
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
document.addEventListener("WebViewJavascriptBridgeReady", () => {
|
|
68
|
+
queue.forEach(({ method, params, callback }) => {
|
|
69
|
+
if (window.SuperAcme && typeof window.SuperAcme.call === "function") {
|
|
70
|
+
invokeBridge(method, params, callback);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
queue.length = 0;
|
|
74
|
+
});
|
|
75
|
+
function bridgeCall(method, params, callback) {
|
|
76
|
+
if (method === "log") {
|
|
77
|
+
Logger.debug("bridgeCall", method, params);
|
|
78
|
+
} else {
|
|
79
|
+
Logger.info("bridgeCall", method, params);
|
|
40
80
|
}
|
|
81
|
+
invokeBridge(method, params, callback);
|
|
41
82
|
}
|
|
42
83
|
function bridgeBootstrap() {
|
|
43
84
|
function bootstrap(callback) {
|