icecast-metadata-js
Advanced tools
Comparing version 0.6.1 to 0.6.2
{ | ||
"name": "icecast-metadata-js", | ||
"version": "0.6.1", | ||
"version": "0.6.2", | ||
"description": "Library for Web Browsers and NodeJS that reads, parses, and synchronizes Icecast stream metadata", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -140,3 +140,3 @@ /* Copyright 2020-2021 Ethan Halsall | ||
while (this._remainingData) { | ||
yield* this._sendStream(yield* super._getNextValue()); | ||
this._addStream(yield* super._getNextValue()); | ||
} | ||
@@ -143,0 +143,0 @@ } |
@@ -33,2 +33,4 @@ /* Copyright 2020-2021 Ethan Halsall | ||
this._buffer = new Uint8Array(0); | ||
this._streamBuffer = []; | ||
this._streamBufferLength = 0; | ||
this._stats = new Stats(); | ||
@@ -51,13 +53,24 @@ | ||
while (true) { | ||
yield* this._sendStream(yield* this._getNextValue()); | ||
this._addStream(yield* this._getNextValue()); | ||
yield* this._sendStream(); | ||
} | ||
} | ||
static _concatBuffers(buf1, buf2) { | ||
const result = new Uint8Array(buf1.length + buf2.length); | ||
result.set(buf1); | ||
result.set(buf2, buf1.length); | ||
return result; | ||
static _concatBuffers(...buffers) { | ||
const length = buffers.reduce((acc, buf) => acc + buf.length, 0); | ||
return this._concatBuffersKnownLength(buffers, length); | ||
} | ||
static _concatBuffersKnownLength(buffers, length) { | ||
const buffer = new Uint8Array(length); | ||
buffers.reduce((offset, buf) => { | ||
buffer.set(buf, offset); | ||
return offset + buf.length; | ||
}, 0); | ||
return buffer; | ||
} | ||
*iterator(chunk) { | ||
@@ -114,12 +127,28 @@ for ( | ||
*_sendStream(stream) { | ||
this._stats.addStreamBytes(stream.length); | ||
_addStream(stream) { | ||
this._streamBuffer.push(stream); | ||
this._streamBufferLength += stream.length; | ||
} | ||
const streamPayload = { stream, stats: this._stats.stats }; | ||
*_sendStream() { | ||
if (this._streamBuffer.length) { | ||
const stream = MetadataParser._concatBuffersKnownLength( | ||
this._streamBuffer, | ||
this._streamBufferLength | ||
); | ||
this._streamBuffer = []; | ||
this._streamBufferLength = 0; | ||
this._onStreamPromise = this._onStream(streamPayload); | ||
yield streamPayload; | ||
this._stats.addStreamBytes(stream.length); | ||
const streamPayload = { stream, stats: this._stats.stats }; | ||
this._onStreamPromise = this._onStream(streamPayload); | ||
yield streamPayload; | ||
} | ||
} | ||
*_sendMetadata(metadata) { | ||
yield* this._sendStream(); | ||
const metadataPayload = { | ||
@@ -164,2 +193,4 @@ metadata, | ||
*_readData() { | ||
yield* this._sendStream(); | ||
let data; | ||
@@ -166,0 +197,0 @@ |
@@ -95,3 +95,3 @@ /* Copyright 2020-2021 Ethan Halsall | ||
if (syncBytes.length) yield* this._sendStream(Uint8Array.from(syncBytes)); | ||
if (syncBytes.length) this._addStream(Uint8Array.from(syncBytes)); | ||
@@ -148,3 +148,3 @@ if (syncBytes.length > 65307) { | ||
yield* this._sendStream(value); | ||
this._addStream(value); | ||
return value; | ||
@@ -151,0 +151,0 @@ } |
62338
972