feat(media,messaging,network): deepen streaming and transport APIs
Hyper-P2P Module Tests / unit-all (push) Failing after 1h16m23s
Hyper-P2P Module Tests / unit-all (push) Failing after 1h16m23s
Origin hybrid weighted select, latency path stats, live-edge listing; topic channel batch publish and retained clear; wakeup reschedule and cancelAll; electron bridge handler registry helpers. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -57,6 +57,21 @@ class HyperP2PLatencyOptimizer extends EventEmitter {
|
||||
return [...this._paths.keys()]
|
||||
}
|
||||
|
||||
clearPath (pathId) {
|
||||
return this._paths.delete(String(pathId))
|
||||
}
|
||||
|
||||
averageRtt () {
|
||||
const vals = [...this._paths.values()]
|
||||
if (!vals.length) return 0
|
||||
return vals.reduce((s, p) => s + p.rttMs, 0) / vals.length
|
||||
}
|
||||
|
||||
isWithinTarget (plan) {
|
||||
const glass = plan?.estimatedGlassMs ?? this.averageRtt() + 200
|
||||
return glass <= this.targetGlassMs
|
||||
}
|
||||
|
||||
getStats () {
|
||||
return mediaStats(this._stats, PROTOCOL, { paths: this._paths.size })
|
||||
}
|
||||
|
||||
@@ -61,6 +61,23 @@ class HyperP2PLiveEdgeManager extends EventEmitter {
|
||||
return this.setLiveEdge(streamId, e.seq + (delta | 0), Date.now())
|
||||
}
|
||||
|
||||
removeEdge (streamId) {
|
||||
return this._edges.delete(assertStreamId(streamId))
|
||||
}
|
||||
|
||||
listEdges () {
|
||||
return [...this._edges.values()]
|
||||
}
|
||||
|
||||
maxLagAcrossStreams (now = Date.now()) {
|
||||
let max = 0
|
||||
for (const sid of this._edges.keys()) {
|
||||
const lag = this.edgeLagMs(sid, now)
|
||||
if (lag != null && lag > max) max = lag
|
||||
}
|
||||
return max
|
||||
}
|
||||
|
||||
getStats () {
|
||||
return mediaStats(this._stats, PROTOCOL, { streams: this._edges.size })
|
||||
}
|
||||
|
||||
@@ -48,6 +48,33 @@ class HyperP2POriginHybridBridge extends EventEmitter {
|
||||
return [...(this._origins.get(assertStreamId(streamId)) || [])]
|
||||
}
|
||||
|
||||
removeOrigin (streamId, url) {
|
||||
const sid = assertStreamId(streamId)
|
||||
const list = this._origins.get(sid)
|
||||
if (!list) return false
|
||||
const idx = list.findIndex((o) => o.url === url)
|
||||
if (idx < 0) return false
|
||||
list.splice(idx, 1)
|
||||
if (!list.length) this._origins.delete(sid)
|
||||
return true
|
||||
}
|
||||
|
||||
listStreamIds () {
|
||||
return [...this._origins.keys()]
|
||||
}
|
||||
|
||||
weightedSelect (streamId) {
|
||||
const list = this._origins.get(assertStreamId(streamId))
|
||||
if (!list || !list.length) return null
|
||||
const total = list.reduce((s, o) => s + o.weight, 0)
|
||||
let r = Math.random() * total
|
||||
for (const o of list) {
|
||||
r -= o.weight
|
||||
if (r <= 0) return o
|
||||
}
|
||||
return list[0]
|
||||
}
|
||||
|
||||
totalBytes () {
|
||||
return this._stats.originBytes + this._stats.p2pBytes
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user