@jhh96/light-app-bridge 1.3.2 → 1.4.1
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 +20 -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
|
@@ -104,6 +104,8 @@ function bindMessageBackend(cb) {
|
|
|
104
104
|
ev.off('native-call-js', handler);
|
|
105
105
|
else if (ev && typeof ev.removeListener === 'function')
|
|
106
106
|
ev.removeListener('native-call-js', handler);
|
|
107
|
+
else if (ev && typeof ev.remove === 'function')
|
|
108
|
+
ev.remove('native-call-js', handler); // waltz ≥1.1.7 API
|
|
107
109
|
});
|
|
108
110
|
}
|
|
109
111
|
// 2. 定义 handleMessageFromNative 路径:无 waltz 时。
|
|
@@ -152,6 +154,12 @@ function parseHandleMessageFromNative(raw) {
|
|
|
152
154
|
// handleMessageFromNative 入参带 responseId 包装
|
|
153
155
|
responseData = parsed && parsed.responseData != null ? parsed.responseData : parsed;
|
|
154
156
|
}
|
|
157
|
+
// waltz ≥1.1.7:event 总线(bl)派发载荷为 {id, data} 包装,responseData 在 .data 里
|
|
158
|
+
//(旧版 nativeCallWeb 直接派发裸 responseData)。裸数据有 .body 无 .data、包装有
|
|
159
|
+
// .data 无 .body,判据互斥,两种版本同一解析出口。
|
|
160
|
+
if (responseData && responseData.body == null && responseData.data != null) {
|
|
161
|
+
responseData = responseData.data;
|
|
162
|
+
}
|
|
155
163
|
if (!responseData || !responseData.body || responseData.body.eventName !== 'plugin-message') {
|
|
156
164
|
return null;
|
|
157
165
|
}
|
|
@@ -759,6 +767,14 @@ export default class LightAppBridge {
|
|
|
759
767
|
this._disconnectCbs.push(cb);
|
|
760
768
|
return this;
|
|
761
769
|
}
|
|
770
|
+
/**
|
|
771
|
+
* 当前绑定对端 webContentsId(未连接/失联时为 null)。
|
|
772
|
+
* 调用方在业务时点(如用户提问)快照此值,之后经 send({to}) 定向发送,
|
|
773
|
+
* 即可保证指令送达该时点所在的轻应用窗口(round 钉扎)。
|
|
774
|
+
*/
|
|
775
|
+
get peerId() {
|
|
776
|
+
return this._peer;
|
|
777
|
+
}
|
|
762
778
|
/**
|
|
763
779
|
* 等待连接建立(握手完成)。构造时已自动发起握手,直接 await 即可。
|
|
764
780
|
* @returns 对端 webContentsId
|
|
@@ -832,12 +848,12 @@ export default class LightAppBridge {
|
|
|
832
848
|
return Promise.reject(new Error('实例已销毁'));
|
|
833
849
|
const timeout = options.timeout != null ? options.timeout : this.timeout;
|
|
834
850
|
return this.ready().then(() => {
|
|
835
|
-
//
|
|
836
|
-
// dynamic 模式迁移重绑后,后续 send 立即发往新对端。
|
|
837
|
-
const targetId = this._peer;
|
|
851
|
+
// 发送目标:显式 to(round 钉扎)优先;否则取当前 _peer(而非 ready()
|
|
852
|
+
// resolve 的快照)——dynamic 模式迁移重绑后,后续 send 立即发往新对端。
|
|
853
|
+
const targetId = options.to != null ? options.to : this._peer;
|
|
838
854
|
const id = genId();
|
|
839
855
|
const envelope = this._envelope('req', data, id);
|
|
840
|
-
this._log('send→ id=' + id + ' 目标=' + targetId + ' data=' + debugPayload(data));
|
|
856
|
+
this._log('send→ id=' + id + ' 目标=' + targetId + (options.to != null ? '(钉扎)' : '') + ' data=' + debugPayload(data));
|
|
841
857
|
return new Promise((resolve, reject) => {
|
|
842
858
|
const timer = setTimeout(() => {
|
|
843
859
|
if (this._pending.has(id)) {
|