crh-jssdk 1.0.26 → 1.0.27

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.
@@ -228,7 +228,7 @@ var JYBridge = /** @class */ (function () {
228
228
  * 等待Bridge准备就绪
229
229
  */
230
230
  JYBridge.prototype.waitForReady = function (timeout) {
231
- if (timeout === void 0) { timeout = 5000; }
231
+ if (timeout === void 0) { timeout = 300; }
232
232
  if (this.bridge) {
233
233
  return Promise.resolve();
234
234
  }
@@ -363,7 +363,7 @@ var Bridge = /** @class */ (function () {
363
363
  return new Promise(function (resolve, reject) {
364
364
  try {
365
365
  // 如果Bridge已初始化,直接使用;否则等待初始化完成
366
- var useBridge = function (bridge) {
366
+ var useBridge_1 = function (bridge) {
367
367
  if (!bridge || typeof bridge.callHandler !== 'function') {
368
368
  reject(new Error('Bridge未正确初始化或callHandler方法不存在'));
369
369
  return;
@@ -379,33 +379,35 @@ var Bridge = /** @class */ (function () {
379
379
  };
380
380
  if (_this.bridge) {
381
381
  // Bridge已初始化,直接使用
382
- useBridge(_this.bridge);
382
+ useBridge_1(_this.bridge);
383
383
  }
384
384
  else {
385
385
  // Bridge未初始化,等待初始化完成
386
- // this.waitForReady(5000)
387
- // .then(() => {
388
- // if (this.bridge) {
389
- // useBridge(this.bridge);
390
- // } else {
391
- // // 如果等待后仍然没有bridge,尝试重新连接(可能是动态加载的情况)
392
- // this.connectWebViewJavascriptBridge((bridge: any) => {
393
- // this.bridge = bridge;
394
- // useBridge(bridge);
395
- // });
396
- // }
397
- // })
398
- // .catch((error) => {
399
- // // 如果等待超时,尝试直接连接(可能是Bridge已经存在但未初始化)
400
- // this.connectWebViewJavascriptBridge((bridge: any) => {
401
- // if (bridge) {
402
- // this.bridge = bridge;
403
- // useBridge(bridge);
404
- // } else {
405
- // reject(new Error(`Bridge初始化失败: ${error.message}`));
406
- // }
407
- // });
408
- // });
386
+ _this.waitForReady(300)
387
+ .then(function () {
388
+ if (_this.bridge) {
389
+ useBridge_1(_this.bridge);
390
+ }
391
+ else {
392
+ // 如果等待后仍然没有bridge,尝试重新连接(可能是动态加载的情况)
393
+ _this.connectWebViewJavascriptBridge(function (bridge) {
394
+ _this.bridge = bridge;
395
+ useBridge_1(bridge);
396
+ });
397
+ }
398
+ })
399
+ .catch(function (error) {
400
+ // 如果等待超时,尝试直接连接(可能是Bridge已经存在但未初始化)
401
+ _this.connectWebViewJavascriptBridge(function (bridge) {
402
+ if (bridge) {
403
+ _this.bridge = bridge;
404
+ useBridge_1(bridge);
405
+ }
406
+ else {
407
+ reject(new Error("Bridge\u521D\u59CB\u5316\u5931\u8D25: ".concat(error.message)));
408
+ }
409
+ });
410
+ });
409
411
  }
410
412
  }
411
413
  catch (e) {
@@ -415,7 +417,7 @@ var Bridge = /** @class */ (function () {
415
417
  }
416
418
  // 不需要回调,只需要执行
417
419
  try {
418
- var useBridge = function (bridge) {
420
+ var useBridge_2 = function (bridge) {
419
421
  if (bridge && typeof bridge.callHandler === 'function') {
420
422
  bridge.callHandler(name, params, function () {
421
423
  // dosomething
@@ -423,27 +425,28 @@ var Bridge = /** @class */ (function () {
423
425
  }
424
426
  };
425
427
  if (this.bridge) {
426
- useBridge(this.bridge);
428
+ useBridge_2(this.bridge);
427
429
  }
428
430
  else {
429
431
  // 等待初始化或直接连接
430
- // this.waitForReady(3000)
431
- // .then(() => {
432
- // if (this.bridge) {
433
- // useBridge(this.bridge);
434
- // } else {
435
- // this.connectWebViewJavascriptBridge((bridge: any) => {
436
- // this.bridge = bridge;
437
- // useBridge(bridge);
438
- // });
439
- // }
440
- // })
441
- // .catch(() => {
442
- // this.connectWebViewJavascriptBridge((bridge: any) => {
443
- // this.bridge = bridge;
444
- // useBridge(bridge);
445
- // });
446
- // });
432
+ this.waitForReady(300)
433
+ .then(function () {
434
+ if (_this.bridge) {
435
+ useBridge_2(_this.bridge);
436
+ }
437
+ else {
438
+ _this.connectWebViewJavascriptBridge(function (bridge) {
439
+ _this.bridge = bridge;
440
+ useBridge_2(bridge);
441
+ });
442
+ }
443
+ })
444
+ .catch(function () {
445
+ _this.connectWebViewJavascriptBridge(function (bridge) {
446
+ _this.bridge = bridge;
447
+ useBridge_2(bridge);
448
+ });
449
+ });
447
450
  }
448
451
  }
449
452
  catch (e) {
@@ -457,10 +460,11 @@ var Bridge = /** @class */ (function () {
457
460
  * @param callback 回调函数,第二个参数responseCallback用于向App发送响应
458
461
  */
459
462
  Bridge.prototype.registerHandler = function (name, callback) {
463
+ var _this = this;
460
464
  if (name === void 0) { name = ''; }
461
465
  if (callback === void 0) { callback = function () { }; }
462
466
  try {
463
- var useBridge = function (bridge) {
467
+ var useBridge_3 = function (bridge) {
464
468
  if (bridge && typeof bridge.registerHandler === 'function') {
465
469
  bridge.registerHandler(name, function (data, responseCallback) {
466
470
  callback(data, responseCallback);
@@ -468,27 +472,28 @@ var Bridge = /** @class */ (function () {
468
472
  }
469
473
  };
470
474
  if (this.bridge) {
471
- useBridge(this.bridge);
475
+ useBridge_3(this.bridge);
472
476
  }
473
477
  else {
474
478
  // 等待初始化或直接连接
475
- // this.waitForReady(3000)
476
- // .then(() => {
477
- // if (this.bridge) {
478
- // useBridge(this.bridge);
479
- // } else {
480
- // this.connectWebViewJavascriptBridge((bridge: any) => {
481
- // this.bridge = bridge;
482
- // useBridge(bridge);
483
- // });
484
- // }
485
- // })
486
- // .catch(() => {
487
- // this.connectWebViewJavascriptBridge((bridge: any) => {
488
- // this.bridge = bridge;
489
- // useBridge(bridge);
490
- // });
491
- // });
479
+ this.waitForReady(300)
480
+ .then(function () {
481
+ if (_this.bridge) {
482
+ useBridge_3(_this.bridge);
483
+ }
484
+ else {
485
+ _this.connectWebViewJavascriptBridge(function (bridge) {
486
+ _this.bridge = bridge;
487
+ useBridge_3(bridge);
488
+ });
489
+ }
490
+ })
491
+ .catch(function () {
492
+ _this.connectWebViewJavascriptBridge(function (bridge) {
493
+ _this.bridge = bridge;
494
+ useBridge_3(bridge);
495
+ });
496
+ });
492
497
  }
493
498
  }
494
499
  catch (e) {
@@ -506,7 +511,7 @@ var Bridge = /** @class */ (function () {
506
511
  * @param timeout 超时时间(毫秒),默认5000ms
507
512
  */
508
513
  Bridge.prototype.waitForReady = function (timeout) {
509
- if (timeout === void 0) { timeout = 5000; }
514
+ if (timeout === void 0) { timeout = 300; }
510
515
  // 如果Bridge已经初始化,直接返回成功
511
516
  if (this.bridge) {
512
517
  return Promise.resolve();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crh-jssdk",
3
- "version": "1.0.26",
3
+ "version": "1.0.27",
4
4
  "description": "crh-jssdk",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {