crh-jssdk 1.0.23 → 1.0.25
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/business/utils/bridge.js +18 -10
- package/package.json +1 -1
|
@@ -7,11 +7,10 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.JYClientTHS = exports.jyBridge = exports.globalBridge = exports.Bridge = exports.JYBridge = void 0;
|
|
10
|
-
//
|
|
11
|
-
// 确保 native WebViewJavascriptBridge 在注入完成并调用 _callWVJBCallbacks 时,WVJBCallbacks 始终存在
|
|
12
|
-
// 避免 "TypeError: undefined is not an object (evaluating 'callbacks.length')" 错误
|
|
10
|
+
// 在脚本加载时立即初始化全局标记
|
|
13
11
|
if (typeof window !== 'undefined') {
|
|
14
12
|
window.WVJBCallbacks = window.WVJBCallbacks || [];
|
|
13
|
+
window._WVJBInitialized = false;
|
|
15
14
|
}
|
|
16
15
|
/**
|
|
17
16
|
* ClientTHS全局桥接对象
|
|
@@ -274,16 +273,25 @@ var Bridge = /** @class */ (function () {
|
|
|
274
273
|
_this.bridge = bridge;
|
|
275
274
|
// 确保bridge.init存在且是函数,且未初始化过
|
|
276
275
|
// 在iOS环境下,App原生可能已经调用过bridge.init(),再次调用会报错"init called twice"
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
276
|
+
// 使用全局标记 window._WVJBInitialized 检测App原生的初始化
|
|
277
|
+
if (bridge && typeof bridge.init === 'function') {
|
|
278
|
+
// 双保险:在调用init前再次检查全局标记,避免并发或多次进入时重复调用
|
|
279
|
+
if (!window._WVJBInitialized && !_this._bridgeInitCalled) {
|
|
280
|
+
window._WVJBInitialized = true;
|
|
281
|
+
bridge.init(function () {
|
|
282
|
+
console.log('Bridge初始化完成');
|
|
283
|
+
_this._bridgeInitCalled = true;
|
|
284
|
+
resolve();
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
console.log('Bridge.init已调用过(全局标记或实例标记),跳过');
|
|
280
289
|
resolve();
|
|
281
|
-
}
|
|
282
|
-
_this._bridgeInitCalled = true;
|
|
290
|
+
}
|
|
283
291
|
}
|
|
284
292
|
else {
|
|
285
|
-
// 如果
|
|
286
|
-
console.log('Bridge
|
|
293
|
+
// 如果init不存在,直接resolve
|
|
294
|
+
console.log('Bridge.init不存在,跳过');
|
|
287
295
|
resolve();
|
|
288
296
|
}
|
|
289
297
|
});
|