@jhh96/light-app-bridge 1.0.4 → 1.0.5

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.
@@ -37,7 +37,7 @@ export interface Envelope {
37
37
  export interface BridgeOptions {
38
38
  /** send 默认超时(ms),默认 3000 */
39
39
  timeout?: number;
40
- /** 握手超时(ms),默认 30000 */
40
+ /** 握手超时(ms),默认 30000。仅 plugin 角色生效;lightapp 端持续等待,不超时 */
41
41
  handshakeTimeout?: number;
42
42
  }
43
43
  /** send 单次调用选项 */
@@ -86,8 +86,8 @@ export default class LightAppBridge {
86
86
  private _onMessage;
87
87
  /**
88
88
  * 建立连接(握手)。构造时已自动调用,通常无需手动调;如需重新握手可再次调用。
89
- * - 插件:发起握手(解析目标 id → 发 hello → 每秒重试直到收到 ack)
90
- * - 轻应用:启动握手等待(被动等 hello;若插件始终未来则超时)
89
+ * - 插件:发起握手(解析目标 id → 发 hello → 每秒重试直到收到 ack 或超时)
90
+ * - 轻应用:被动等待 hello(持续监听,不超时——插件可能任意晚才发起连接)
91
91
  * 多次调用幂等,返回同一个连接 Promise。
92
92
  * @returns 对端 webContentsId
93
93
  */
@@ -237,8 +237,8 @@ export default class LightAppBridge {
237
237
  // —— 连接 / 握手 —— //
238
238
  /**
239
239
  * 建立连接(握手)。构造时已自动调用,通常无需手动调;如需重新握手可再次调用。
240
- * - 插件:发起握手(解析目标 id → 发 hello → 每秒重试直到收到 ack)
241
- * - 轻应用:启动握手等待(被动等 hello;若插件始终未来则超时)
240
+ * - 插件:发起握手(解析目标 id → 发 hello → 每秒重试直到收到 ack 或超时)
241
+ * - 轻应用:被动等待 hello(持续监听,不超时——插件可能任意晚才发起连接)
242
242
  * 多次调用幂等,返回同一个连接 Promise。
243
243
  * @returns 对端 webContentsId
244
244
  */
@@ -249,13 +249,16 @@ export default class LightAppBridge {
249
249
  this._connectStarted = true;
250
250
  // 等监听后端绑定完成后再握手,避免对端的 ack/hello 在监听绑定前到达而丢失
251
251
  const listenerReady = (_a = this._listenerReady) !== null && _a !== void 0 ? _a : Promise.resolve();
252
- // 握手超时保护
253
- this._handshakeTimer = setTimeout(() => {
254
- if (!this._connected) {
255
- this._connectDeferred.reject(new Error(`握手超时 (${this.handshakeTimeout}ms),对端未响应`));
256
- this._clearHelloTimer();
257
- }
258
- }, this.handshakeTimeout);
252
+ // 握手超时保护:仅插件(主动方)需要——它发了 hello 却收不到 ack 说明对端异常。
253
+ // 轻应用(被动方)持续等待,不超时:插件可能任意晚才发起连接。
254
+ if (this.role === 'plugin') {
255
+ this._handshakeTimer = setTimeout(() => {
256
+ if (!this._connected) {
257
+ this._connectDeferred.reject(new Error(`握手超时 (${this.handshakeTimeout}ms),对端未响应`));
258
+ this._clearHelloTimer();
259
+ }
260
+ }, this.handshakeTimeout);
261
+ }
259
262
  listenerReady
260
263
  .then(() => {
261
264
  if (this._connected)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jhh96/light-app-bridge",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "type": "module",
5
5
  "description": "招商随行(WorkLink)插件窗口(plugin)与轻应用窗口(lightapp)之间的双向通信 SDK",
6
6
  "main": "./dist/index.js",