feat: multi-listener bridge + subscribe/unsubscribe in index page

This commit is contained in:
2026-09-01 19:01:20 +08:00
parent 3146f01d77
commit e577181300
2 changed files with 16 additions and 6 deletions
+10 -5
View File
@@ -1,12 +1,12 @@
// DSHWatch bridge: @system.interconnect wrapper (real shell glue).
// Sends/receives JSON envelopes to the DSHWatch phone APP over the Xiaomi
// Vela interconnect BLE channel. Protocol per DSHWatch_Server/docs/PROTOCOL.md.
// DSHWatch bridge: @system.interconnect wrapper.
// Sends/receives JSON envelopes to the DSHWatch phone APP over the Vela BLE channel.
// Protocol per DSHWatch_Server/docs/PROTOCOL.md.
import interconnect from '@system.interconnect'
let conn = null
let seq = 0
let listeners = []
const listeners = new Set()
let currentStatus = '未连接'
function getConn() {
@@ -48,8 +48,13 @@ function emit(type, payload) {
}
}
export function subscribe(callbacks) {
listeners.add(callbacks)
return () => listeners.delete(callbacks)
}
export function init(callbacks) {
listeners = [callbacks]
subscribe(callbacks)
refreshConn()
}