feat(media-streaming): deepen peer selector and media chunker

Add bestPeer/weight tuning, chunk reassemble and stream listing for
manual media-streaming module expansion.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Raven Scott
2026-05-21 02:33:33 -04:00
co-authored by Cursor
parent bed98ff300
commit d285079522
3 changed files with 40 additions and 2 deletions
@@ -85,6 +85,27 @@ class HyperP2PMediaChunker extends EventEmitter {
return n
}
reassemble (streamId) {
const parts = this.listChunks(streamId)
if (!parts.length) return b4a.alloc(0)
const total = parts.reduce((s, c) => s + c.byteLength, 0)
const out = b4a.alloc(total)
let off = 0
for (const c of parts) {
out.set(c.data, off)
off += c.byteLength
}
return out
}
chunkCount (streamId) {
return this.listChunks(streamId).length
}
streamIds () {
return [...new Set([...this._chunks.values()].map((c) => c.streamId))]
}
getStats () {
return mediaStats(this._stats, PROTOCOL, { stored: this._chunks.size })
}
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "hyper-p2p-media-chunker",
"version": "0.0.0-scaffold",
"version": "0.3.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "hyper-p2p-media-chunker",
"version": "0.0.0-scaffold",
"version": "0.3.1",
"license": "Apache-2.0",
"dependencies": {
"b4a": "^1.6.7",
@@ -83,6 +83,23 @@ class HyperP2PPeerSelectorStreaming extends EventEmitter {
return this._peers.delete(assertPeerId(peerId))
}
bestPeer () {
const ranked = this.rankPeers()
return ranked.length ? ranked[0] : null
}
setWeights (weights = {}) {
if (weights.upload != null) this.weights.upload = weights.upload
if (weights.latency != null) this.weights.latency = weights.latency
if (weights.stability != null) this.weights.stability = weights.stability
if (weights.load != null) this.weights.load = weights.load
return { ...this.weights }
}
peerCount () {
return this._peers.size
}
getStats () {
return mediaStats(this._stats, PROTOCOL, { peers: this._peers.size })
}