feat(media-streaming,pubsub): expand helper swarm and chunk scheduler APIs
Hyper-P2P Module Tests / unit-all (push) Failing after 1h20m44s

- helper-swarm-coordinator: autoAssign, rebalance, resetUtilization
- chunk-scheduler-media: enqueueBatch, dropBelowPriority, clear
- qos-topic: queueDepths, clearQueues
- Update routing-advanced category README highlights

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Raven Scott
2026-05-21 02:21:32 -04:00
co-authored by Cursor
parent 1811e9d969
commit 26ca05031a
3 changed files with 50 additions and 0 deletions
@@ -84,6 +84,23 @@ class HyperP2PChunkSchedulerMedia extends EventEmitter {
return this._queue.length return this._queue.length
} }
enqueueBatch (chunks) {
if (!Array.isArray(chunks)) throw new Error('chunks must be an array')
return chunks.map((c) => this.enqueue(c.chunk || c, c.priority))
}
dropBelowPriority (minPriority) {
const before = this._queue.length
this._queue = this._queue.filter((e) => e.priority >= minPriority)
return before - this._queue.length
}
clear () {
const n = this._queue.length
this._queue = []
return n
}
getStats () { getStats () {
return mediaStats(this._stats, PROTOCOL, { pending: this._queue.length }) return mediaStats(this._stats, PROTOCOL, { pending: this._queue.length })
} }
@@ -73,6 +73,26 @@ class HyperP2PHelperSwarmCoordinator extends EventEmitter {
return Math.min(1, h.usedBps / h.capacityBps) return Math.min(1, h.usedBps / h.capacityBps)
} }
autoAssign (viewerId, count = 3) {
const available = this.availableHelpers()
.sort((a, b) => (a.usedBps / (a.capacityBps || 1)) - (b.usedBps / (b.capacityBps || 1)))
const helpers = available.slice(0, Math.max(0, count | 0)).map((h) => h.peerId)
return this.assignViewer(viewerId, helpers)
}
resetUtilization () {
let n = 0
for (const h of this._helpers.values()) {
h.usedBps = 0
n++
}
return n
}
rebalance (viewerId) {
return this.autoAssign(viewerId)
}
_gossip (payload) { _gossip (payload) {
if (this._peerMsgs) gossipSend(this, payload) if (this._peerMsgs) gossipSend(this, payload)
} }
@@ -75,6 +75,19 @@ class HyperP2PQosTopic extends EventEmitter {
hasHandler (channel) { return this._handlers.has(channel) } hasHandler (channel) { return this._handlers.has(channel) }
queueDepths () {
return this._queues.map((q, qos) => ({ qos, depth: q.length }))
}
clearQueues () {
let n = 0
for (const q of this._queues) {
n += q.length
q.length = 0
}
return n
}
_onGossip (data) { _onGossip (data) {
if (!data || data.type !== 'qos-publish') return if (!data || data.type !== 'qos-publish') return
this._stats.gossipIn++ this._stats.gossipIn++