p2p-media-loader-hlsjs
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -53,7 +53,6 @@ var __defProp = Object.defineProperty; | ||
load(context, config, callbacks) { | ||
var _a; | ||
this.context = context; | ||
this.config = config; | ||
__privateSet(this, _callbacks, callbacks); | ||
const stats = this.stats; | ||
const { stats } = this; | ||
const { rangeStart: start, rangeEnd: end } = context; | ||
@@ -68,6 +67,6 @@ const byteRange = getByteRange( | ||
); | ||
if (!__privateGet(this, _core).hasSegment(__privateGet(this, _segmentId)) || isSegmentDownloadableByP2PCore === false) { | ||
if (!__privateGet(this, _core).hasSegment(__privateGet(this, _segmentId)) || !isSegmentDownloadableByP2PCore) { | ||
__privateSet(this, _defaultLoader, __privateGet(this, _createDefaultLoader).call(this)); | ||
__privateGet(this, _defaultLoader).stats = this.stats; | ||
(_a = __privateGet(this, _defaultLoader)) == null ? void 0 : _a.load(context, config, callbacks); | ||
__privateGet(this, _defaultLoader).load(context, config, callbacks); | ||
return; | ||
@@ -83,3 +82,4 @@ } | ||
); | ||
stats.total = stats.loaded = loadedBytes; | ||
stats.total = loadedBytes; | ||
stats.loaded = loadedBytes; | ||
if (callbacks.onProgress) { | ||
@@ -201,3 +201,2 @@ callbacks.onProgress( | ||
updatePlaylist(data) { | ||
if (!data.details) return; | ||
const { | ||
@@ -475,3 +474,3 @@ details: { url, fragments, live } | ||
createFragmentLoaderClass() { | ||
const core = this.core; | ||
const { core } = this; | ||
const engine = this; | ||
@@ -478,0 +477,0 @@ return class FragmentLoader extends FragmentLoaderBase { |
@@ -6,4 +6,4 @@ var j = Object.defineProperty; | ||
var q = (n, t, e) => t in n ? j(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e; | ||
var r = (n, t, e) => q(n, typeof t != "symbol" ? t + "" : t, e), A = (n, t, e) => t.has(n) || R("Cannot " + e); | ||
var i = (n, t, e) => (A(n, t, "read from private field"), e ? e.call(n) : t.get(n)), l = (n, t, e) => t.has(n) ? R("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(n) : t.set(n, e), u = (n, t, e, s) => (A(n, t, "write to private field"), s ? s.call(n, e) : t.set(n, e), e), x = (n, t, e) => (A(n, t, "access private method"), e); | ||
var r = (n, t, e) => q(n, typeof t != "symbol" ? t + "" : t, e), D = (n, t, e) => t.has(n) || R("Cannot " + e); | ||
var i = (n, t, e) => (D(n, t, "read from private field"), e ? e.call(n) : t.get(n)), l = (n, t, e) => t.has(n) ? R("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(n) : t.set(n, e), u = (n, t, e, s) => (D(n, t, "write to private field"), s ? s.call(n, e) : t.set(n, e), e), x = (n, t, e) => (D(n, t, "access private method"), e); | ||
import { CoreRequestError as T, debug as N, Core as z } from "p2p-media-loader-core"; | ||
@@ -16,3 +16,3 @@ function F(n, t) { | ||
} | ||
var H, C, g, v, f, p, b, G, U; | ||
var H, M, g, y, p, m, b, G, A; | ||
class B { | ||
@@ -25,25 +25,24 @@ constructor(t, e) { | ||
l(this, H); | ||
l(this, C); | ||
l(this, M); | ||
l(this, g); | ||
l(this, v); | ||
l(this, f); | ||
l(this, y); | ||
l(this, p); | ||
u(this, v, e), u(this, C, () => new t.loader(t)), this.stats = { aborted: !1, chunkCount: 0, loading: { start: 0, first: 0, end: 0 }, buffering: { start: 0, first: 0, end: 0 }, parsing: { start: 0, end: 0 }, total: 1, loaded: 1, bwEstimate: 0, retry: 0 }; | ||
l(this, m); | ||
u(this, y, e), u(this, M, () => new t.loader(t)), this.stats = { aborted: !1, chunkCount: 0, loading: { start: 0, first: 0, end: 0 }, buffering: { start: 0, first: 0, end: 0 }, parsing: { start: 0, end: 0 }, total: 1, loaded: 1, bwEstimate: 0, retry: 0 }; | ||
} | ||
load(t, e, s) { | ||
var L; | ||
this.context = t, this.config = e, u(this, H, s); | ||
const o = this.stats, { rangeStart: h, rangeEnd: a } = t, y = J(h, a !== void 0 ? a - 1 : void 0); | ||
u(this, p, F(t.url, y)); | ||
const c = i(this, v).isSegmentLoadable(i(this, p)); | ||
if (!i(this, v).hasSegment(i(this, p)) || c === !1) return u(this, g, i(this, C).call(this)), i(this, g).stats = this.stats, void ((L = i(this, g)) == null ? void 0 : L.load(t, e, s)); | ||
i(this, v).loadSegment(i(this, p), { onSuccess: (d) => { | ||
u(this, f, d); | ||
const E = i(this, f).data.byteLength; | ||
o.loading = function(I, w, S) { | ||
const P = 8e3 * w / I, M = S - P; | ||
return { start: M - 10, first: M, end: S }; | ||
}(i(this, f).bandwidth, E, performance.now()), o.total = o.loaded = E, s.onProgress && s.onProgress(this.stats, t, i(this, f).data, void 0), s.onSuccess({ data: i(this, f).data, url: t.url }, this.stats, t, void 0); | ||
}, onError: (d) => { | ||
d instanceof T && d.type === "aborted" && this.stats.aborted || x(this, b, G).call(this, d); | ||
const { stats: o } = this, { rangeStart: d, rangeEnd: a } = t, E = J(d, a !== void 0 ? a - 1 : void 0); | ||
u(this, m, F(t.url, E)); | ||
const h = i(this, y).isSegmentLoadable(i(this, m)); | ||
if (!i(this, y).hasSegment(i(this, m)) || !h) return u(this, g, i(this, M).call(this)), i(this, g).stats = this.stats, void i(this, g).load(t, e, s); | ||
i(this, y).loadSegment(i(this, m), { onSuccess: (f) => { | ||
u(this, p, f); | ||
const c = i(this, p).data.byteLength; | ||
o.loading = function(L, C, I) { | ||
const w = 8e3 * C / L, S = I - w; | ||
return { start: S - 10, first: S, end: I }; | ||
}(i(this, p).bandwidth, c, performance.now()), o.total = c, o.loaded = c, s.onProgress && s.onProgress(this.stats, t, i(this, p).data, void 0), s.onSuccess({ data: i(this, p).data, url: t.url }, this.stats, t, void 0); | ||
}, onError: (f) => { | ||
f instanceof T && f.type === "aborted" && this.stats.aborted || x(this, b, G).call(this, f); | ||
} }); | ||
@@ -53,34 +52,34 @@ } | ||
var t, e; | ||
i(this, g) ? i(this, g).abort() : (x(this, b, U).call(this), (e = (t = i(this, H)) == null ? void 0 : t.onAbort) == null || e.call(t, this.stats, this.context, {})); | ||
i(this, g) ? i(this, g).abort() : (x(this, b, A).call(this), (e = (t = i(this, H)) == null ? void 0 : t.onAbort) == null || e.call(t, this.stats, this.context, {})); | ||
} | ||
destroy() { | ||
i(this, g) ? i(this, g).destroy() : (this.stats.aborted || x(this, b, U).call(this), u(this, H, null), this.config = null); | ||
i(this, g) ? i(this, g).destroy() : (this.stats.aborted || x(this, b, A).call(this), u(this, H, null), this.config = null); | ||
} | ||
} | ||
H = new WeakMap(), C = new WeakMap(), g = new WeakMap(), v = new WeakMap(), f = new WeakMap(), p = new WeakMap(), b = new WeakSet(), G = function(t) { | ||
H = new WeakMap(), M = new WeakMap(), g = new WeakMap(), y = new WeakMap(), p = new WeakMap(), m = new WeakMap(), b = new WeakSet(), G = function(t) { | ||
var s; | ||
const e = { code: 0, text: "" }; | ||
(t instanceof T && t.type === "failed" || t instanceof Error) && (e.text = t.message), (s = i(this, H)) == null || s.onError(e, this.context, null, this.stats); | ||
}, U = function() { | ||
!i(this, f) && i(this, p) && (this.stats.aborted = !0, i(this, v).abortSegmentLoading(i(this, p))); | ||
}, A = function() { | ||
!i(this, p) && i(this, m) && (this.stats.aborted = !0, i(this, y).abortSegmentLoading(i(this, m))); | ||
}; | ||
var m; | ||
var v; | ||
class X { | ||
constructor(t) { | ||
l(this, m); | ||
l(this, v); | ||
r(this, "context"); | ||
r(this, "stats"); | ||
u(this, m, new t.loader(t)), this.stats = i(this, m).stats, this.context = i(this, m).context; | ||
u(this, v, new t.loader(t)), this.stats = i(this, v).stats, this.context = i(this, v).context; | ||
} | ||
load(t, e, s) { | ||
i(this, m).load(t, e, s); | ||
i(this, v).load(t, e, s); | ||
} | ||
abort() { | ||
i(this, m).abort(); | ||
i(this, v).abort(); | ||
} | ||
destroy() { | ||
i(this, m).destroy(); | ||
i(this, v).destroy(); | ||
} | ||
} | ||
m = new WeakMap(); | ||
v = new WeakMap(); | ||
class K { | ||
@@ -93,8 +92,8 @@ constructor(t) { | ||
const { levels: e, audioTracks: s } = t; | ||
for (const [o, h] of e.entries()) { | ||
const { url: a } = h; | ||
for (const [o, d] of e.entries()) { | ||
const { url: a } = d; | ||
this.core.addStreamIfNoneExists({ runtimeId: Array.isArray(a) ? a[0] : a, type: "main", index: o }); | ||
} | ||
for (const [o, h] of s.entries()) { | ||
const { url: a } = h; | ||
for (const [o, d] of s.entries()) { | ||
const { url: a } = d; | ||
this.core.addStreamIfNoneExists({ runtimeId: Array.isArray(a) ? a[0] : a, type: "secondary", index: o }); | ||
@@ -104,12 +103,11 @@ } | ||
updatePlaylist(t) { | ||
if (!t.details) return; | ||
const { details: { url: e, fragments: s, live: o } } = t, h = this.core.getStream(e); | ||
if (!h) return; | ||
const a = new Set(h.segments.keys()), y = []; | ||
s.forEach((c, L) => { | ||
const { url: d, byteRange: E, sn: I, start: w, end: S } = c; | ||
if (I === "initSegment") return; | ||
const [P, M] = E, k = J(P, M !== void 0 ? M - 1 : void 0), D = F(d, k); | ||
a.delete(D), h.segments.has(D) || y.push({ runtimeId: D, url: d, externalId: o ? I : L, byteRange: k, startTime: w, endTime: S }); | ||
}), (y.length || a.size) && this.core.updateStream(e, y, a.values()); | ||
const { details: { url: e, fragments: s, live: o } } = t, d = this.core.getStream(e); | ||
if (!d) return; | ||
const a = new Set(d.segments.keys()), E = []; | ||
s.forEach((h, f) => { | ||
const { url: c, byteRange: L, sn: C, start: I, end: w } = h; | ||
if (C === "initSegment") return; | ||
const [S, P] = L, U = J(S, P !== void 0 ? P - 1 : void 0), k = F(c, U); | ||
a.delete(k), d.segments.has(k) || E.push({ runtimeId: k, url: c, externalId: o ? C : f, byteRange: U, startTime: I, endTime: w }); | ||
}), (E.length || a.size) && this.core.updateStream(e, E, a.values()); | ||
} | ||
@@ -161,7 +159,7 @@ } | ||
constructor(...a) { | ||
var E; | ||
const y = a[0], { p2p: c, ...L } = y ?? {}, d = new $(c); | ||
super({ ...L, ...d.getConfigForHlsJs() }); | ||
var L; | ||
const E = a[0], { p2p: h, ...f } = E ?? {}, c = new $(h); | ||
super({ ...f, ...c.getConfigForHlsJs() }); | ||
l(this, s); | ||
d.bindHls(this), u(this, s, d), (E = c == null ? void 0 : c.onHlsJsCreated) == null || E.call(c, this); | ||
c.bindHls(this), u(this, s, c), (L = h == null ? void 0 : h.onHlsJsCreated) == null || L.call(h, this); | ||
} | ||
@@ -204,3 +202,3 @@ get p2pEngine() { | ||
createFragmentLoaderClass() { | ||
const t = this.core, e = this; | ||
const { core: t } = this, e = this; | ||
return class extends B { | ||
@@ -207,0 +205,0 @@ constructor(s) { |
@@ -140,5 +140,5 @@ import type Hls from "hls.js"; | ||
*/ | ||
getConfigForHlsJs<F = unknown, P = unknown>(): { | ||
fLoader: F; | ||
pLoader: P; | ||
getConfigForHlsJs(): { | ||
fLoader: unknown; | ||
pLoader: unknown; | ||
}; | ||
@@ -145,0 +145,0 @@ /** |
@@ -115,2 +115,3 @@ import { FragmentLoaderBase } from "./fragment-loader.js"; | ||
value: (event, data) => { | ||
// eslint-disable-next-line prefer-destructuring | ||
const networkDetails = data.networkDetails; | ||
@@ -310,3 +311,3 @@ if (networkDetails instanceof XMLHttpRequest) { | ||
createFragmentLoaderClass() { | ||
const core = this.core; | ||
const { core } = this; | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
@@ -313,0 +314,0 @@ const engine = this; |
@@ -63,3 +63,3 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
__classPrivateFieldSet(this, _FragmentLoaderBase_callbacks, callbacks, "f"); | ||
const stats = this.stats; | ||
const { stats } = this; | ||
const { rangeStart: start, rangeEnd: end } = context; | ||
@@ -70,6 +70,6 @@ const byteRange = Utils.getByteRange(start, end !== undefined ? end - 1 : undefined); | ||
if (!__classPrivateFieldGet(this, _FragmentLoaderBase_core, "f").hasSegment(__classPrivateFieldGet(this, _FragmentLoaderBase_segmentId, "f")) || | ||
isSegmentDownloadableByP2PCore === false) { | ||
!isSegmentDownloadableByP2PCore) { | ||
__classPrivateFieldSet(this, _FragmentLoaderBase_defaultLoader, __classPrivateFieldGet(this, _FragmentLoaderBase_createDefaultLoader, "f").call(this), "f"); | ||
__classPrivateFieldGet(this, _FragmentLoaderBase_defaultLoader, "f").stats = this.stats; | ||
__classPrivateFieldGet(this, _FragmentLoaderBase_defaultLoader, "f")?.load(context, config, callbacks); | ||
__classPrivateFieldGet(this, _FragmentLoaderBase_defaultLoader, "f").load(context, config, callbacks); | ||
return; | ||
@@ -81,3 +81,4 @@ } | ||
stats.loading = getLoadingStat(__classPrivateFieldGet(this, _FragmentLoaderBase_response, "f").bandwidth, loadedBytes, performance.now()); | ||
stats.total = stats.loaded = loadedBytes; | ||
stats.total = loadedBytes; | ||
stats.loaded = loadedBytes; | ||
if (callbacks.onProgress) { | ||
@@ -84,0 +85,0 @@ callbacks.onProgress(this.stats, context, __classPrivateFieldGet(this, _FragmentLoaderBase_response, "f").data, undefined); |
@@ -33,4 +33,2 @@ import * as Utils from "./utils.js"; | ||
updatePlaylist(data) { | ||
if (!data.details) | ||
return; | ||
const { details: { url, fragments, live }, } = data; | ||
@@ -37,0 +35,0 @@ const playlist = this.core.getStream(url); |
{ | ||
"name": "p2p-media-loader-hlsjs", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "P2P Media Loader hls.js integration", | ||
@@ -38,7 +38,7 @@ "license": "Apache-2.0", | ||
"dependencies": { | ||
"p2p-media-loader-core": "2.0.1" | ||
"p2p-media-loader-core": "2.1.0" | ||
}, | ||
"devDependencies": { | ||
"@rollup/plugin-terser": "^0.4.4", | ||
"hls.js": "^1.5.15" | ||
"hls.js": "^1.5.17" | ||
}, | ||
@@ -52,3 +52,3 @@ "scripts": { | ||
"prettier": "prettier --write .", | ||
"lint": "eslint . --ext .ts --report-unused-disable-directives --max-warnings 0", | ||
"lint": "eslint src --report-unused-disable-directives --max-warnings 0", | ||
"clean": "rimraf lib dist build p2p-media-loader-hlsjs-*.tgz", | ||
@@ -55,0 +55,0 @@ "clean-with-modules": "rimraf node_modules && pnpm clean", |
@@ -22,3 +22,3 @@ # P2P Media Loader | ||
- [API documentation](https://novage.github.io/p2p-media-loader/docs/v2.0/) | ||
- [API documentation](https://novage.github.io/p2p-media-loader/docs/v2.1.0/) | ||
- [P2P development, support & consulting](https://novage.com.ua/) | ||
@@ -25,0 +25,0 @@ - [Demo](http://novage.com.ua/p2p-media-loader/demo.html) |
@@ -21,7 +21,9 @@ import { | ||
constructor(...args: any[]) { | ||
const config = args[0] as { | ||
p2p?: PartialHlsJsP2PEngineConfig & { | ||
onHlsJsCreated?: (hls: InstanceType<HlsJsConstructor>) => void; | ||
}; | ||
} & Record<string, unknown>; | ||
const config = args[0] as | ||
| ({ | ||
p2p?: PartialHlsJsP2PEngineConfig & { | ||
onHlsJsCreated?: (hls: InstanceType<HlsJsConstructor>) => void; | ||
}; | ||
} & Record<string, unknown>) | ||
| undefined; | ||
@@ -28,0 +30,0 @@ const { p2p, ...hlsJsConfig } = config ?? {}; |
@@ -8,4 +8,5 @@ import type Hls from "hls.js"; | ||
PlaylistLevelType, | ||
HlsConfig, | ||
Events, | ||
} from "hls.js"; | ||
import type { HlsConfig, Events } from "hls.js"; | ||
import { FragmentLoaderBase } from "./fragment-loader.js"; | ||
@@ -181,6 +182,6 @@ import { PlaylistLoaderBase } from "./playlist-loader.js"; | ||
*/ | ||
getConfigForHlsJs<F = unknown, P = unknown>(): { fLoader: F; pLoader: P } { | ||
getConfigForHlsJs(): { fLoader: unknown; pLoader: unknown } { | ||
return { | ||
fLoader: this.createFragmentLoaderClass() as F, | ||
pLoader: this.createPlaylistLoaderClass() as P, | ||
fLoader: this.createFragmentLoaderClass(), | ||
pLoader: this.createPlaylistLoaderClass(), | ||
}; | ||
@@ -291,2 +292,3 @@ } | ||
private handleManifestLoaded = (event: string, data: ManifestLoadedData) => { | ||
// eslint-disable-next-line prefer-destructuring | ||
const networkDetails: unknown = data.networkDetails; | ||
@@ -354,3 +356,3 @@ if (networkDetails instanceof XMLHttpRequest) { | ||
private createFragmentLoaderClass() { | ||
const core = this.core; | ||
const { core } = this; | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
@@ -357,0 +359,0 @@ const engine = this; |
@@ -52,3 +52,3 @@ import type { | ||
this.#callbacks = callbacks; | ||
const stats = this.stats; | ||
const { stats } = this; | ||
@@ -68,7 +68,7 @@ const { rangeStart: start, rangeEnd: end } = context; | ||
!this.#core.hasSegment(this.#segmentId) || | ||
isSegmentDownloadableByP2PCore === false | ||
!isSegmentDownloadableByP2PCore | ||
) { | ||
this.#defaultLoader = this.#createDefaultLoader(); | ||
this.#defaultLoader.stats = this.stats; | ||
this.#defaultLoader?.load(context, config, callbacks); | ||
this.#defaultLoader.load(context, config, callbacks); | ||
return; | ||
@@ -85,3 +85,4 @@ } | ||
); | ||
stats.total = stats.loaded = loadedBytes; | ||
stats.total = loadedBytes; | ||
stats.loaded = loadedBytes; | ||
@@ -88,0 +89,0 @@ if (callbacks.onProgress) { |
@@ -40,3 +40,2 @@ import * as Utils from "./utils.js"; | ||
updatePlaylist(data: LevelUpdatedData | AudioTrackLoadedData) { | ||
if (!data.details) return; | ||
const { | ||
@@ -43,0 +42,0 @@ details: { url, fragments, live }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2226
186872
+ Addedp2p-media-loader-core@2.1.0(transitive)
- Removedp2p-media-loader-core@2.0.1(transitive)
Updatedp2p-media-loader-core@2.1.0