p2p-media-loader-shaka
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -1,11 +0,11 @@ | ||
var x = Object.defineProperty; | ||
var R = (s, e, t) => e in s ? x(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t; | ||
var u = (s, e, t) => R(s, typeof e != "symbol" ? e + "" : e, t); | ||
import { debug as q, CoreRequestError as T, Core as C } from "p2p-media-loader-core"; | ||
class L { | ||
var R = Object.defineProperty; | ||
var L = (o, e, t) => e in o ? R(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t; | ||
var g = (o, e, t) => L(o, typeof e != "symbol" ? e + "" : e, t); | ||
import { debug as T, CoreRequestError as C, Core as H } from "p2p-media-loader-core"; | ||
class w { | ||
constructor(e, t) { | ||
u(this, "debug", q("p2pml-shaka:manifest-parser")); | ||
u(this, "isHls"); | ||
u(this, "segmentManager"); | ||
u(this, "player"); | ||
g(this, "debug", T("p2pml-shaka:manifest-parser")); | ||
g(this, "isHls"); | ||
g(this, "segmentManager"); | ||
g(this, "player"); | ||
this.originalManifestParser = t, this.isHls = this.originalManifestParser instanceof e.hls.HlsParser; | ||
@@ -28,6 +28,3 @@ } | ||
this.setP2PMediaLoaderData(r); | ||
const n = await this.originalManifestParser.start( | ||
e, | ||
t | ||
); | ||
const n = await this.originalManifestParser.start(e, t); | ||
return r && (this.isHls && this.hookHlsStreamMediaSequenceTimeMaps(n.variants), this.processStreams(n.variants)), n; | ||
@@ -42,6 +39,3 @@ } | ||
onExpirationUpdated(e, t) { | ||
return this.originalManifestParser.onExpirationUpdated( | ||
e, | ||
t | ||
); | ||
return this.originalManifestParser.onExpirationUpdated(e, t); | ||
} | ||
@@ -51,7 +45,7 @@ processStreams(e) { | ||
if (!t) return; | ||
const r = /* @__PURE__ */ new Set(), n = (c, d, a) => (this.hookSegmentIndex(c), t.setStream(c, d, a), r.add(c.id), !0); | ||
let i = 0, o = 0; | ||
for (const c of e) { | ||
const { video: d, audio: a } = c; | ||
d && !r.has(d.id) && n(d, "main", i++), a && !r.has(a.id) && n(a, d ? "secondary" : "main", o++); | ||
const r = /* @__PURE__ */ new Set(), n = (a, h, i) => (this.hookSegmentIndex(a), t.setStream(a, h, i), r.add(a.id), !0); | ||
let s = 0, d = 0; | ||
for (const a of e) { | ||
const { video: h, audio: i } = a; | ||
h && !r.has(h.id) && n(h, "main", s++), i && !r.has(i.id) && n(i, h ? "secondary" : "main", d++); | ||
} | ||
@@ -62,72 +56,59 @@ } | ||
if (!t) return; | ||
const r = (i, o = !1) => { | ||
let c = null, d, a; | ||
const l = i.get, h = (m) => { | ||
var v, P; | ||
const g = l.call(i, m); | ||
if (g === c || !((v = this.player) != null && v.isLive()) && e.isSegmentIndexAlreadyRead) | ||
return g; | ||
c = g, i.get = l; | ||
const r = (s, d = !1) => { | ||
let a, h, i = null; | ||
const c = s.get, l = (u) => { | ||
var M, P; | ||
const m = c.call(s, u); | ||
if (m === i || !((M = this.player) != null && M.isLive()) && e.isSegmentIndexAlreadyRead) return m; | ||
i = m, s.get = c; | ||
try { | ||
const f = [...i], I = f[0], E = f[f.length - 1]; | ||
if (I === d && E === a) | ||
return g; | ||
d = I, a = E, t.updateStreamSegments(e, f), e.isSegmentIndexAlreadyRead = !0, this.debug(`Stream ${e.id} is updated`); | ||
const p = [...s], k = p[0], E = p[p.length - 1]; | ||
if (k === a && E === h) return m; | ||
a = k, h = E, t.updateStreamSegments(e, p), e.isSegmentIndexAlreadyRead = !0, this.debug(`Stream ${e.id} is updated`); | ||
} catch { | ||
} finally { | ||
(!e.isSegmentIndexAlreadyRead || (P = this.player) != null && P.isLive() || !o) && (i.get = h); | ||
e.isSegmentIndexAlreadyRead && !((P = this.player) != null && P.isLive()) && d || (s.get = l); | ||
} | ||
return g; | ||
return m; | ||
}; | ||
i.get = h; | ||
s.get = l; | ||
}; | ||
if (e.segmentIndex) { | ||
r(e.segmentIndex); | ||
return; | ||
} | ||
if (e.segmentIndex) return void r(e.segmentIndex); | ||
const n = e.createSegmentIndex; | ||
e.createSegmentIndex = async () => { | ||
const i = await n.call(e); | ||
return e.segmentIndex && r(e.segmentIndex, !0), i; | ||
const s = await n.call(e); | ||
return e.segmentIndex && r(e.segmentIndex, !0), s; | ||
}; | ||
} | ||
hookHlsStreamMediaSequenceTimeMaps(e) { | ||
var d; | ||
const t = w( | ||
this.originalManifestParser | ||
); | ||
var h; | ||
const t = I(this.originalManifestParser); | ||
let r, n; | ||
const i = ["video", "audio", "text", "image"]; | ||
for (const a of t) | ||
i.every((l) => a.has(l)) && (r = a.get("video"), n = a.get("audio")); | ||
const s = ["video", "audio", "text", "image"]; | ||
for (const i of t) s.every((c) => i.has(c)) && (r = i.get("video"), n = i.get("audio")); | ||
if (r && n) { | ||
for (const a of e) { | ||
const { video: l, audio: h } = a; | ||
l && r && (l.mediaSequenceTimeMap = r), h && n && (h.mediaSequenceTimeMap = r); | ||
for (const i of e) { | ||
const { video: c, audio: l } = i; | ||
c && r && (c.mediaSequenceTimeMap = r), l && n && (l.mediaSequenceTimeMap = r); | ||
} | ||
return; | ||
} | ||
const o = t.find((a) => { | ||
var h; | ||
const l = a.values().next().value; | ||
return ( | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access | ||
typeof l == "object" && ((h = l == null ? void 0 : l.streams) == null ? void 0 : h.createSegmentIndex) | ||
); | ||
const d = t.find((i) => { | ||
var l; | ||
const c = i.values().next().value; | ||
return typeof c == "object" && ((l = c == null ? void 0 : c.streams) == null ? void 0 : l.createSegmentIndex); | ||
}); | ||
if (!o) return; | ||
const c = [...o.values()]; | ||
for (const a of c) { | ||
if ((d = a == null ? void 0 : a.stream) != null && d.mediaSequenceTimeMap) continue; | ||
const l = w( | ||
a | ||
).find((h) => { | ||
const [m, g] = h.entries().next().value ?? []; | ||
return typeof m == "number" && typeof g == "number"; | ||
if (!d) return; | ||
const a = [...d.values()]; | ||
for (const i of a) { | ||
if ((h = i == null ? void 0 : i.stream) != null && h.mediaSequenceTimeMap) continue; | ||
const c = I(i).find((l) => { | ||
const [u, m] = l.entries().next().value ?? []; | ||
return typeof u == "number" && typeof m == "number"; | ||
}); | ||
l && (a.stream.mediaSequenceTimeMap = l); | ||
c && (i.stream.mediaSequenceTimeMap = c); | ||
} | ||
} | ||
} | ||
class H extends L { | ||
class q extends w { | ||
constructor(e) { | ||
@@ -137,3 +118,3 @@ super(e, new e.hls.HlsParser()); | ||
} | ||
class B extends L { | ||
class U extends w { | ||
constructor(e) { | ||
@@ -143,66 +124,34 @@ super(e, new e.dash.DashParser()); | ||
} | ||
function w(s) { | ||
return Object.values(s).filter( | ||
(e) => e instanceof Map | ||
); | ||
function I(o) { | ||
return Object.values(o).filter((e) => e instanceof Map); | ||
} | ||
function S({ | ||
segmentReference: s, | ||
externalId: e, | ||
runtimeId: t | ||
}) { | ||
const { byteRange: r, url: n, startTime: i, endTime: o } = b(s); | ||
return { | ||
runtimeId: t ?? M(n, r), | ||
externalId: e, | ||
byteRange: r, | ||
url: n, | ||
startTime: i, | ||
endTime: o | ||
}; | ||
function y({ segmentReference: o, externalId: e, runtimeId: t }) { | ||
const { byteRange: r, url: n, startTime: s, endTime: d } = b(o); | ||
return { runtimeId: t ?? v(n, r), externalId: e, byteRange: r, url: n, startTime: s, endTime: d }; | ||
} | ||
function k(s) { | ||
const { url: e, byteRange: t } = b(s); | ||
return M(e, t); | ||
function x(o) { | ||
const { url: e, byteRange: t } = b(o); | ||
return v(e, t); | ||
} | ||
function M(s, e) { | ||
if (!e) return s; | ||
const t = typeof e == "string" ? D(e) : e; | ||
return t ? `${s}|${t.start}-${t.end}` : s; | ||
function v(o, e) { | ||
if (!e) return o; | ||
const t = typeof e == "string" ? function(r) { | ||
if (!r || !r.includes("bytes=")) return; | ||
const n = r.split("=")[1].split("-").map((a) => parseInt(a)), [s, d] = n; | ||
return { start: s, end: d }; | ||
}(e) : e; | ||
return t ? `${o}|${t.start}-${t.end}` : o; | ||
} | ||
function D(s) { | ||
if (!s || !s.includes("bytes=")) return; | ||
const e = s.split("=")[1].split("-").map((n) => parseInt(n)), [t, r] = e; | ||
return { start: t, end: r }; | ||
function b(o) { | ||
const e = o.getUris(), t = e[1] ?? e[0], r = o.getStartByte(), n = o.getEndByte() ?? void 0; | ||
return { byteRange: n !== void 0 ? { start: r, end: n } : void 0, url: t, startTime: o.getStartTime(), endTime: o.getEndTime() }; | ||
} | ||
function b(s) { | ||
const e = s.getUris(), t = e[1] ?? e[0], r = s.getStartByte(), n = s.getEndByte() ?? void 0, i = s.getStartTime(), o = s.getEndTime(); | ||
return { | ||
byteRange: n !== void 0 ? { start: r, end: n } : void 0, | ||
url: t, | ||
startTime: i, | ||
endTime: o | ||
}; | ||
} | ||
function N(s) { | ||
const { shakaStream: e } = s, t = e.mediaSequenceTimeMap; | ||
if (!t) return; | ||
const r = t.keys().next().value; | ||
if (r !== void 0) | ||
return r + t.size - 1; | ||
} | ||
const F = 0.5; | ||
class U { | ||
class N { | ||
constructor(e, t) { | ||
u(this, "core"); | ||
u(this, "streamInfo"); | ||
g(this, "core"); | ||
g(this, "streamInfo"); | ||
this.core = t, this.streamInfo = e; | ||
} | ||
setStream(e, t, r = -1) { | ||
this.core.addStreamIfNoneExists({ | ||
runtimeId: e.id.toString(), | ||
type: t, | ||
index: r, | ||
shakaStream: e | ||
}), e.segmentIndex && this.updateStreamSegments(e); | ||
this.core.addStreamIfNoneExists({ runtimeId: e.id.toString(), type: t, index: r, shakaStream: e }), e.segmentIndex && this.updateStreamSegments(e); | ||
} | ||
@@ -213,8 +162,7 @@ updateStreamSegments(e, t) { | ||
const { segmentIndex: n } = r.shakaStream; | ||
if (!t && n) | ||
try { | ||
t = [...n]; | ||
} catch { | ||
return; | ||
} | ||
if (!t && n) try { | ||
t = [...n]; | ||
} catch { | ||
return; | ||
} | ||
t && (this.streamInfo.protocol === "hls" ? this.processHlsSegmentReferences(r, t) : this.processDashSegmentReferences(r, t)); | ||
@@ -224,72 +172,52 @@ } | ||
const r = new Set(e.segments.keys()), n = []; | ||
for (const i of t) { | ||
const o = Math.trunc( | ||
i.getStartTime() / F | ||
), c = k(i); | ||
if (!e.segments.has(c)) { | ||
const d = S({ | ||
segmentReference: i, | ||
externalId: o, | ||
runtimeId: c | ||
}); | ||
n.push(d); | ||
for (const s of t) { | ||
const d = Math.trunc(s.getStartTime() / 0.5), a = x(s); | ||
if (!e.segments.has(a)) { | ||
const h = y({ segmentReference: s, externalId: d, runtimeId: a }); | ||
n.push(h); | ||
} | ||
r.delete(c); | ||
r.delete(a); | ||
} | ||
!n.length && !r.size || this.core.updateStream( | ||
e.runtimeId, | ||
n, | ||
r.values() | ||
); | ||
(n.length || r.size) && this.core.updateStream(e.runtimeId, n, r.values()); | ||
} | ||
processHlsSegmentReferences(e, t) { | ||
const { segments: r } = e, n = N(e), i = []; | ||
const { segments: r } = e, n = function(i) { | ||
const { shakaStream: c } = i, l = c.mediaSequenceTimeMap; | ||
if (!l) return; | ||
const u = l.keys().next().value; | ||
return u !== void 0 ? u + l.size - 1 : void 0; | ||
}(e), s = []; | ||
if (r.size === 0) { | ||
const a = n === void 0 ? 0 : n - t.length + 1; | ||
for (const [l, h] of t.entries()) { | ||
const m = S({ | ||
segmentReference: h, | ||
externalId: a + l | ||
}); | ||
i.push(m); | ||
const i = n === void 0 ? 0 : n - t.length + 1; | ||
for (const [c, l] of t.entries()) { | ||
const u = y({ segmentReference: l, externalId: i + c }); | ||
s.push(u); | ||
} | ||
this.core.updateStream(e.runtimeId, i); | ||
return; | ||
return void this.core.updateStream(e.runtimeId, s); | ||
} | ||
if (!n) return; | ||
let o = n; | ||
for (const a of O(t)) { | ||
const l = k(a); | ||
if (r.has(l)) break; | ||
const h = S({ | ||
runtimeId: l, | ||
segmentReference: a, | ||
externalId: o | ||
}); | ||
i.push(h), o--; | ||
let d = n; | ||
for (const i of function* (c) { | ||
for (let l = c.length - 1; l >= 0; l--) yield c[l]; | ||
}(t)) { | ||
const c = x(i); | ||
if (r.has(c)) break; | ||
const l = y({ runtimeId: c, segmentReference: i, externalId: d }); | ||
s.push(l), d--; | ||
} | ||
i.reverse(); | ||
const c = [], d = i.length; | ||
for (const a of A(r, d)) | ||
c.push(a.runtimeId); | ||
!i.length && !c.length || this.core.updateStream( | ||
e.runtimeId, | ||
i, | ||
c | ||
); | ||
s.reverse(); | ||
const a = [], h = s.length; | ||
for (const i of function* (c, l) { | ||
let u = 0; | ||
for (const m of c.values()) { | ||
if (u >= l) break; | ||
yield m, u++; | ||
} | ||
}(r, h)) a.push(i.runtimeId); | ||
(s.length || a.length) && this.core.updateStream(e.runtimeId, s, a); | ||
} | ||
} | ||
function* O(s) { | ||
for (let e = s.length - 1; e >= 0; e--) yield s[e]; | ||
} | ||
function* A(s, e) { | ||
let t = 0; | ||
for (const r of s.values()) { | ||
if (t >= e) break; | ||
yield r, t++; | ||
} | ||
} | ||
class V { | ||
class B { | ||
constructor(e, t, r) { | ||
u(this, "loadArgs"); | ||
g(this, "loadArgs"); | ||
this.shaka = e, this.core = t, this.streamInfo = r; | ||
@@ -302,7 +230,6 @@ } | ||
this.loadArgs = e; | ||
const { RequestType: t } = this.shaka.net.NetworkingEngine, [r, n, i] = e; | ||
if (i === t.SEGMENT) | ||
return this.loadSegment(r, n.headers.Range); | ||
const o = this.defaultLoad(); | ||
return i === t.MANIFEST && this.handleManifestLoading(o.promise), o; | ||
const { RequestType: t } = this.shaka.net.NetworkingEngine, [r, n, s] = e; | ||
if (s === t.SEGMENT) return this.loadSegment(r, n.headers.Range); | ||
const d = this.defaultLoad(); | ||
return s === t.MANIFEST && this.handleManifestLoading(d.promise), d; | ||
} | ||
@@ -316,40 +243,22 @@ async handleManifestLoading(e) { | ||
loadSegment(e, t) { | ||
const r = M( | ||
e, | ||
t | ||
), n = this.core.isSegmentLoadable(r); | ||
if (!this.core.hasSegment(r) || n === !1) | ||
return this.defaultLoad(); | ||
const i = async () => { | ||
const { request: o, callbacks: c } = $(); | ||
this.core.loadSegment(r, c); | ||
const r = v(e, t), n = this.core.isSegmentLoadable(r); | ||
return !this.core.hasSegment(r) || n === !1 ? this.defaultLoad() : new this.shaka.util.AbortableOperation((async () => { | ||
const { request: s, callbacks: d } = function() { | ||
let a, h; | ||
return { request: new Promise((c, l) => { | ||
a = c, h = l; | ||
}), callbacks: { onSuccess: a, onError: h } }; | ||
}(); | ||
this.core.loadSegment(r, d); | ||
try { | ||
const { data: d, bandwidth: a } = await o; | ||
return { | ||
data: d, | ||
headers: {}, | ||
uri: e, | ||
originalUri: e, | ||
timeMs: G( | ||
a, | ||
d.byteLength | ||
) | ||
}; | ||
} catch (d) { | ||
if (d instanceof T) { | ||
const { Error: a } = this.shaka.util; | ||
if (d.type === "aborted") | ||
throw new a( | ||
a.Severity.RECOVERABLE, | ||
a.Category.NETWORK, | ||
this.shaka.util.Error.Code.OPERATION_ABORTED | ||
); | ||
const { data: a, bandwidth: h } = await s; | ||
return { data: a, headers: {}, uri: e, originalUri: e, timeMs: A(h, a.byteLength) }; | ||
} catch (a) { | ||
if (a instanceof C) { | ||
const { Error: h } = this.shaka.util; | ||
if (a.type === "aborted") throw new h(h.Severity.RECOVERABLE, h.Category.NETWORK, this.shaka.util.Error.Code.OPERATION_ABORTED); | ||
} | ||
throw d; | ||
throw a; | ||
} | ||
}; | ||
return new this.shaka.util.AbortableOperation( | ||
i(), | ||
() => Promise.resolve(this.core.abortSegmentLoading(r)) | ||
); | ||
})(), () => Promise.resolve(this.core.abortSegmentLoading(r))); | ||
} | ||
@@ -360,57 +269,28 @@ setManifestResponseUrl(e) { | ||
} | ||
function G(s, e) { | ||
const t = e * 8; | ||
return Math.round(t / s) * 1e3; | ||
function A(o, e) { | ||
const t = 8 * e; | ||
return 1e3 * Math.round(t / o); | ||
} | ||
function $() { | ||
let s, e; | ||
return { | ||
request: new Promise((r, n) => { | ||
s = r, e = n; | ||
}), | ||
callbacks: { | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
onSuccess: s, | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
onError: e | ||
} | ||
}; | ||
} | ||
const j = 25; | ||
class p { | ||
/** | ||
* Constructs an instance of ShakaP2PEngine. | ||
* | ||
* @param config Optional configuration for customizing the P2P engine's behavior. | ||
* @param shaka The Shaka Player library instance. | ||
*/ | ||
class f { | ||
constructor(e, t = window.shaka) { | ||
u(this, "player"); | ||
u(this, "shaka"); | ||
u(this, "streamInfo", {}); | ||
u(this, "core"); | ||
u(this, "segmentManager"); | ||
u(this, "requestFilter"); | ||
u(this, "updatePlayerEventHandlers", (e) => { | ||
g(this, "player"); | ||
g(this, "shaka"); | ||
g(this, "streamInfo", {}); | ||
g(this, "core"); | ||
g(this, "segmentManager"); | ||
g(this, "requestFilter"); | ||
g(this, "updatePlayerEventHandlers", (e) => { | ||
const { player: t } = this; | ||
if (!t) return; | ||
const r = t.getNetworkingEngine(); | ||
if (r) | ||
if (e === "register") { | ||
const i = { | ||
player: t, | ||
shaka: this.shaka, | ||
core: this.core, | ||
streamInfo: this.streamInfo, | ||
segmentManager: this.segmentManager | ||
}; | ||
this.requestFilter = (o, c) => { | ||
c.p2pml = i; | ||
}, r.p2pml = i, r.registerRequestFilter(this.requestFilter); | ||
} else | ||
r.p2pml = void 0, this.requestFilter && r.unregisterRequestFilter(this.requestFilter); | ||
if (r) if (e === "register") { | ||
const s = { player: t, shaka: this.shaka, core: this.core, streamInfo: this.streamInfo, segmentManager: this.segmentManager }; | ||
this.requestFilter = (d, a) => { | ||
a.p2pml = s; | ||
}, r.p2pml = s, r.registerRequestFilter(this.requestFilter); | ||
} else r.p2pml = void 0, this.requestFilter && r.unregisterRequestFilter(this.requestFilter); | ||
const n = e === "register" ? "addEventListener" : "removeEventListener"; | ||
t[n]("loaded", this.handlePlayerLoaded), t[n]("loading", this.destroyCurrentStreamContext), t[n]("unloading", this.handlePlayerUnloading), t[n]("adaptation", this.onVariantChanged), t[n]("variantchanged", this.onVariantChanged); | ||
}); | ||
u(this, "onVariantChanged", () => { | ||
g(this, "onVariantChanged", () => { | ||
if (!this.player) return; | ||
@@ -420,12 +300,12 @@ const e = this.player.getVariantTracks().find((t) => t.active); | ||
}); | ||
u(this, "handlePlayerLoaded", () => { | ||
g(this, "handlePlayerLoaded", () => { | ||
this.player && (this.core.setIsLive(this.player.isLive()), this.updateMediaElementEventHandlers("register")); | ||
}); | ||
u(this, "handlePlayerUnloading", () => { | ||
g(this, "handlePlayerUnloading", () => { | ||
this.destroyCurrentStreamContext(), this.updateMediaElementEventHandlers("unregister"); | ||
}); | ||
u(this, "destroyCurrentStreamContext", () => { | ||
g(this, "destroyCurrentStreamContext", () => { | ||
this.streamInfo.protocol = void 0, this.streamInfo.manifestResponseUrl = void 0, this.core.destroy(); | ||
}); | ||
u(this, "updateMediaElementEventHandlers", (e) => { | ||
g(this, "updateMediaElementEventHandlers", (e) => { | ||
var n; | ||
@@ -437,85 +317,23 @@ const t = (n = this.player) == null ? void 0 : n.getMediaElement(); | ||
}); | ||
u(this, "handlePlaybackUpdate", (e) => { | ||
g(this, "handlePlaybackUpdate", (e) => { | ||
const t = e.target; | ||
this.core.updatePlayback(t.currentTime, t.playbackRate); | ||
}); | ||
y(t), this.shaka = t, this.core = new C(e == null ? void 0 : e.core), this.segmentManager = new U(this.streamInfo, this.core); | ||
S(t), this.shaka = t, this.core = new H(e == null ? void 0 : e.core), this.segmentManager = new N(this.streamInfo, this.core); | ||
} | ||
/** | ||
* Configures and initializes the Shaka Player instance with predefined settings for optimal P2P performance. | ||
* | ||
* @param player The Shaka Player instance to configure. | ||
*/ | ||
bindShakaPlayer(e) { | ||
this.player !== e && (this.player && this.destroy(), this.player = e, this.player.configure("manifest.defaultPresentationDelay", j), this.player.configure( | ||
"manifest.dash.ignoreSuggestedPresentationDelay", | ||
!0 | ||
), this.player.configure("streaming.useNativeHlsOnSafari", !1), this.updatePlayerEventHandlers("register")); | ||
this.player !== e && (this.player && this.destroy(), this.player = e, this.player.configure("manifest.defaultPresentationDelay", 25), this.player.configure("manifest.dash.ignoreSuggestedPresentationDelay", !0), this.player.configure("streaming.useNativeHlsOnSafari", !1), this.updatePlayerEventHandlers("register")); | ||
} | ||
/** | ||
* Applies dynamic configuration updates to the P2P engine. | ||
* | ||
* @param dynamicConfig Configuration changes to apply. | ||
* | ||
* @example | ||
* // Assuming `shakaP2PEngine` is an instance of ShakaP2PEngine | ||
* | ||
* const newDynamicConfig = { | ||
* core: { | ||
* // Increase the number of cached segments to 1000 | ||
* cachedSegmentsCount: 1000, | ||
* // 50 minutes of segments will be downloaded further through HTTP connections if P2P fails | ||
* httpDownloadTimeWindow: 3000, | ||
* // 100 minutes of segments will be downloaded further through P2P connections | ||
* p2pDownloadTimeWindow: 6000, | ||
* }; | ||
* | ||
* shakaP2PEngine.applyDynamicConfig(newDynamicConfig); | ||
*/ | ||
applyDynamicConfig(e) { | ||
e.core && this.core.applyDynamicConfig(e.core); | ||
} | ||
/** | ||
* Retrieves the current configuration of the ShakaP2PEngine. | ||
* | ||
* @returns The configuration as a readonly object. | ||
*/ | ||
getConfig() { | ||
return { core: this.core.getConfig() }; | ||
} | ||
/** | ||
* Adds an event listener for the specified event. | ||
* @param eventName The name of the event to listen for. | ||
* @param listener The callback function to be invoked when the event is triggered. | ||
* | ||
* @example | ||
* // Listening for a segment being successfully loaded | ||
* shakaP2PEngine.addEventListener('onSegmentLoaded', (details) => { | ||
* console.log('Segment Loaded:', details); | ||
* }); | ||
* | ||
* @example | ||
* // Handling segment load errors | ||
* shakaP2PEngine.addEventListener('onSegmentError', (errorDetails) => { | ||
* console.error('Error loading segment:', errorDetails); | ||
* }); | ||
* | ||
* @example | ||
* // Tracking data downloaded from peers | ||
* shakaP2PEngine.addEventListener('onChunkDownloaded', (bytesLength, downloadSource, peerId) => { | ||
* console.log(`Downloaded ${bytesLength} bytes from ${downloadSource} ${peerId ? 'from peer ' + peerId : 'from server'}`); | ||
* }); | ||
*/ | ||
addEventListener(e, t) { | ||
this.core.addEventListener(e, t); | ||
} | ||
/** | ||
* Removes an event listener for the specified event. | ||
* @param eventName The name of the event. | ||
* @param listener The callback function that was previously added. | ||
*/ | ||
removeEventListener(e, t) { | ||
this.core.removeEventListener(e, t); | ||
} | ||
/** Clean up and release all resources. Unregister all event handlers. */ | ||
destroy() { | ||
@@ -525,7 +343,4 @@ this.destroyCurrentStreamContext(), this.updatePlayerEventHandlers("unregister"), this.updateMediaElementEventHandlers("unregister"), this.player = void 0; | ||
static registerManifestParsers(e) { | ||
const t = () => new H(e), r = () => new B(e), n = e.media.ManifestParser; | ||
n.registerParserByMime("application/dash+xml", r), n.registerParserByMime("application/x-mpegurl", t), n.registerParserByMime( | ||
"application/vnd.apple.mpegurl", | ||
t | ||
); | ||
const t = () => new q(e), r = e.media.ManifestParser; | ||
r.registerParserByMime("application/dash+xml", () => new U(e)), r.registerParserByMime("application/x-mpegurl", t), r.registerParserByMime("application/vnd.apple.mpegurl", t); | ||
} | ||
@@ -538,6 +353,4 @@ static unregisterManifestParsers(e) { | ||
const { NetworkingEngine: t } = e.net, r = (...n) => { | ||
const i = n[1], { p2pml: o } = i; | ||
return o ? new V(o.shaka, o.core, o.streamInfo).load(...n) : e.net.HttpFetchPlugin.parse( | ||
...n | ||
); | ||
const s = n[1], { p2pml: d } = s; | ||
return d ? new B(d.shaka, d.core, d.streamInfo).load(...n) : e.net.HttpFetchPlugin.parse(...n); | ||
}; | ||
@@ -550,29 +363,15 @@ t.registerScheme("http", r), t.registerScheme("https", r); | ||
} | ||
/** | ||
* Registers plugins related to P2P functionality into the Shaka Player. | ||
* Plugins must be registered before initializing the player to ensure proper integration. | ||
* | ||
* @param shaka - The Shaka Player library. Defaults to the global Shaka Player instance if not provided. | ||
*/ | ||
static registerPlugins(e = window.shaka) { | ||
y(e), p.registerManifestParsers(e), p.registerNetworkingEngineSchemes(e); | ||
S(e), f.registerManifestParsers(e), f.registerNetworkingEngineSchemes(e); | ||
} | ||
/** | ||
* Unregister plugins related to P2P functionality from the Shaka Player. | ||
* | ||
* @param shaka - The Shaka Player library. Defaults to the global Shaka Player instance if not provided. | ||
*/ | ||
static unregisterPlugins(e = window.shaka) { | ||
y(e), p.unregisterManifestParsers(e), p.unregisterNetworkingEngineSchemes(e); | ||
S(e), f.unregisterManifestParsers(e), f.unregisterNetworkingEngineSchemes(e); | ||
} | ||
} | ||
function y(s) { | ||
if (!s) | ||
throw new Error( | ||
"shaka namespace is not defined in global scope and not passed as an argument to Shaka P2P engine constructor" | ||
); | ||
function S(o) { | ||
if (!o) throw new Error("shaka namespace is not defined in global scope and not passed as an argument to Shaka P2P engine constructor"); | ||
} | ||
export { | ||
p as ShakaP2PEngine | ||
f as ShakaP2PEngine | ||
}; | ||
//# sourceMappingURL=p2p-media-loader-shaka.es.min.js.map |
{ | ||
"name": "p2p-media-loader-shaka", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "P2P Media Loader Shaka Player integration", | ||
@@ -39,5 +39,6 @@ "license": "Apache-2.0", | ||
"dependencies": { | ||
"p2p-media-loader-core": "1.0.0" | ||
"p2p-media-loader-core": "1.0.1" | ||
}, | ||
"devDependencies": { | ||
"@rollup/plugin-terser": "^0.4.4", | ||
"shaka-player": "^4.9.9" | ||
@@ -44,0 +45,0 @@ }, |
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
264009
2
3126
+ Addedp2p-media-loader-core@1.0.1(transitive)
- Removedp2p-media-loader-core@1.0.0(transitive)
Updatedp2p-media-loader-core@1.0.1