feat(media-streaming,pubsub): expand helper swarm and chunk scheduler APIs
Hyper-P2P Module Tests / unit-all (push) Failing after 1h20m44s
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:
@@ -84,6 +84,23 @@ class HyperP2PChunkSchedulerMedia extends EventEmitter {
|
||||
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 () {
|
||||
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)
|
||||
}
|
||||
|
||||
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) {
|
||||
if (this._peerMsgs) gossipSend(this, payload)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user