@jhh96/light-app-bridge 1.3.2 → 1.4.0
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/lightAppBridge.d.ts +14 -0
- package/dist/lightAppBridge.js +12 -4
- package/package.json +1 -1
package/dist/lightAppBridge.d.ts
CHANGED
|
@@ -99,6 +99,14 @@ export interface BridgeOptions {
|
|
|
99
99
|
export interface SendOptions {
|
|
100
100
|
/** 本次超时(ms),不传用实例默认值 */
|
|
101
101
|
timeout?: number;
|
|
102
|
+
/**
|
|
103
|
+
* 定向发送的目标 webContentsId(round 钉扎投递)。
|
|
104
|
+
* 不传(或 null/undefined)= 发往当前绑定对端(dynamic 模式即当前激活窗口);
|
|
105
|
+
* 显式传历史对端 id = 向该窗口定向发送,绝不漂移到当前 peer——
|
|
106
|
+
* 用于"指令必须送达提问时刻的轻应用"语义。目标窗口已关闭时
|
|
107
|
+
* invoke 抛错快速失败(或按 timeout 超时),不会静默改投其他窗口。
|
|
108
|
+
*/
|
|
109
|
+
to?: number | null;
|
|
102
110
|
}
|
|
103
111
|
/**
|
|
104
112
|
* 请求消息处理器。返回值(含 Promise 解析值)会作为回复发回发送方。
|
|
@@ -251,6 +259,12 @@ export default class LightAppBridge {
|
|
|
251
259
|
private _handleDisconnect;
|
|
252
260
|
/** 监听对端失联(ping 与 hello 兜底探测均无响应时触发一次) */
|
|
253
261
|
onDisconnect(cb: (peerId: number | null) => void): this;
|
|
262
|
+
/**
|
|
263
|
+
* 当前绑定对端 webContentsId(未连接/失联时为 null)。
|
|
264
|
+
* 调用方在业务时点(如用户提问)快照此值,之后经 send({to}) 定向发送,
|
|
265
|
+
* 即可保证指令送达该时点所在的轻应用窗口(round 钉扎)。
|
|
266
|
+
*/
|
|
267
|
+
get peerId(): number | null;
|
|
254
268
|
/**
|
|
255
269
|
* 等待连接建立(握手完成)。构造时已自动发起握手,直接 await 即可。
|
|
256
270
|
* @returns 对端 webContentsId
|
package/dist/lightAppBridge.js
CHANGED
|
@@ -759,6 +759,14 @@ export default class LightAppBridge {
|
|
|
759
759
|
this._disconnectCbs.push(cb);
|
|
760
760
|
return this;
|
|
761
761
|
}
|
|
762
|
+
/**
|
|
763
|
+
* 当前绑定对端 webContentsId(未连接/失联时为 null)。
|
|
764
|
+
* 调用方在业务时点(如用户提问)快照此值,之后经 send({to}) 定向发送,
|
|
765
|
+
* 即可保证指令送达该时点所在的轻应用窗口(round 钉扎)。
|
|
766
|
+
*/
|
|
767
|
+
get peerId() {
|
|
768
|
+
return this._peer;
|
|
769
|
+
}
|
|
762
770
|
/**
|
|
763
771
|
* 等待连接建立(握手完成)。构造时已自动发起握手,直接 await 即可。
|
|
764
772
|
* @returns 对端 webContentsId
|
|
@@ -832,12 +840,12 @@ export default class LightAppBridge {
|
|
|
832
840
|
return Promise.reject(new Error('实例已销毁'));
|
|
833
841
|
const timeout = options.timeout != null ? options.timeout : this.timeout;
|
|
834
842
|
return this.ready().then(() => {
|
|
835
|
-
//
|
|
836
|
-
// dynamic 模式迁移重绑后,后续 send 立即发往新对端。
|
|
837
|
-
const targetId = this._peer;
|
|
843
|
+
// 发送目标:显式 to(round 钉扎)优先;否则取当前 _peer(而非 ready()
|
|
844
|
+
// resolve 的快照)——dynamic 模式迁移重绑后,后续 send 立即发往新对端。
|
|
845
|
+
const targetId = options.to != null ? options.to : this._peer;
|
|
838
846
|
const id = genId();
|
|
839
847
|
const envelope = this._envelope('req', data, id);
|
|
840
|
-
this._log('send→ id=' + id + ' 目标=' + targetId + ' data=' + debugPayload(data));
|
|
848
|
+
this._log('send→ id=' + id + ' 目标=' + targetId + (options.to != null ? '(钉扎)' : '') + ' data=' + debugPayload(data));
|
|
841
849
|
return new Promise((resolve, reject) => {
|
|
842
850
|
const timer = setTimeout(() => {
|
|
843
851
|
if (this._pending.has(id)) {
|