@codenkay/video-nsgplayer-core 5.0.0 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/README.md +11 -8
- package/dist/index.cjs +134 -51
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +56 -5
- package/dist/index.d.ts +56 -5
- package/dist/index.js +131 -51
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 5.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Resume playback from `startPosition` after the media duration is known. A short opening buffer no longer pulls that seek back to the start.
|
|
8
|
+
- Keep a 30-second forward buffer, a 60-second ceiling, and a 20MB cap. Adaptive quality stays on the hls.js defaults.
|
|
9
|
+
- Refresh the playback token every 45 seconds by default (`DEFAULT_PLAYBACK_REFRESH_INTERVAL_MS`). The next request uses the new token. A proactive refresh does not restart the loader. Pass `playback.refreshIntervalMs: 0` to refresh only as the credential expires. A refresh after an authorization failure still restarts the loader.
|
|
10
|
+
|
|
11
|
+
## 5.1.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- Add `streaming.mediaProxyUrlBuilder` so playlists, segments, and encryption keys are loaded through a same-origin proxy. The playback API rejects the browser origin and does not send CORS headers.
|
|
16
|
+
- Leave URLs that are already on the page origin unchanged, so a rewritten playlist is not proxied twice.
|
|
17
|
+
- Recognize `/live/` and `/hls-web-live/` playlists for direct `sourceUrl` playback, including when the live address is nested in a proxy `url` parameter.
|
|
18
|
+
- Send same-origin encryption-key requests with the site cookie and without a bearer token. The playback credential stays in the query string.
|
|
19
|
+
|
|
3
20
|
## 5.0.0
|
|
4
21
|
|
|
5
22
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -19,13 +19,10 @@ const player = createVideoPlayer({
|
|
|
19
19
|
videoId: "12345",
|
|
20
20
|
mount: document.querySelector("video")!,
|
|
21
21
|
auth: {
|
|
22
|
-
getToken: async (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
body: JSON.stringify(ctx),
|
|
27
|
-
}).then((r) => r.json());
|
|
28
|
-
},
|
|
22
|
+
getToken: async () => ({
|
|
23
|
+
accessToken: "bff-managed",
|
|
24
|
+
expiresAt: Date.now() + 60 * 60 * 1000,
|
|
25
|
+
}),
|
|
29
26
|
},
|
|
30
27
|
playback: {
|
|
31
28
|
getSource: async ({ videoId }) =>
|
|
@@ -34,6 +31,12 @@ const player = createVideoPlayer({
|
|
|
34
31
|
fetch(`/api/videos/${videoId}/proxy-refresh`, { method: "POST" }).then((r) =>
|
|
35
32
|
r.json(),
|
|
36
33
|
),
|
|
34
|
+
// Default is 45_000. The loader keeps its buffer and uses the new token
|
|
35
|
+
// on the next request. Pass 0 to refresh only as the credential expires.
|
|
36
|
+
},
|
|
37
|
+
streaming: {
|
|
38
|
+
mediaProxyUrlBuilder: ({ url }) =>
|
|
39
|
+
`${location.origin}/api/media?url=${encodeURIComponent(url)}`,
|
|
37
40
|
},
|
|
38
41
|
});
|
|
39
42
|
|
|
@@ -41,7 +44,7 @@ player.on("ready", () => console.log("ready"));
|
|
|
41
44
|
await player.play();
|
|
42
45
|
```
|
|
43
46
|
|
|
44
|
-
See repository `docs/` for configuration, authentication, and security.
|
|
47
|
+
Core **5.2.0** keeps a 30-second forward buffer and refreshes the playback token every 45 seconds. That refresh does not restart the loader. `streaming.mediaProxyUrlBuilder` arrived in 5.1.0, which is already on npm. See repository `docs/` for configuration, authentication, and security.
|
|
45
48
|
|
|
46
49
|
## Samples
|
|
47
50
|
|
package/dist/index.cjs
CHANGED
|
@@ -34,6 +34,7 @@ __export(index_exports, {
|
|
|
34
34
|
AuthParamsStore: () => AuthParamsStore,
|
|
35
35
|
DEFAULT_CONTROLS: () => DEFAULT_CONTROLS,
|
|
36
36
|
DEFAULT_LIVE_EDGE_TOLERANCE_SECONDS: () => DEFAULT_LIVE_EDGE_TOLERANCE_SECONDS,
|
|
37
|
+
DEFAULT_PLAYBACK_REFRESH_INTERVAL_MS: () => DEFAULT_PLAYBACK_REFRESH_INTERVAL_MS,
|
|
37
38
|
DEFAULT_PLAYER_BEHAVIOR: () => DEFAULT_PLAYER_BEHAVIOR,
|
|
38
39
|
DEFAULT_PLAYER_CONFIG: () => DEFAULT_PLAYER_CONFIG,
|
|
39
40
|
DEFAULT_THEME: () => DEFAULT_THEME,
|
|
@@ -53,7 +54,9 @@ __export(index_exports, {
|
|
|
53
54
|
getLiveEdgeTime: () => getLiveEdgeTime,
|
|
54
55
|
isAtLiveEdge: () => isAtLiveEdge,
|
|
55
56
|
isEncryptionKeyUrl: () => isEncryptionKeyUrl,
|
|
57
|
+
isLivePlaylistUrl: () => isLivePlaylistUrl,
|
|
56
58
|
isPlainObject: () => isPlainObject,
|
|
59
|
+
isSameOriginHttpUrl: () => isSameOriginHttpUrl,
|
|
57
60
|
mergePlayerConfig: () => mergePlayerConfig,
|
|
58
61
|
redactObject: () => redactObject,
|
|
59
62
|
redactSensitive: () => redactSensitive,
|
|
@@ -213,7 +216,8 @@ var AuthManager = class {
|
|
|
213
216
|
|
|
214
217
|
// src/config/defaults.ts
|
|
215
218
|
var PLAYBACK_RATES = [0.5, 0.75, 1, 1.25, 1.5, 2];
|
|
216
|
-
var
|
|
219
|
+
var DEFAULT_PLAYBACK_REFRESH_INTERVAL_MS = 45e3;
|
|
220
|
+
var PACKAGE_VERSION = "5.2.0";
|
|
217
221
|
var DEFAULT_PLAYER_BEHAVIOR = {
|
|
218
222
|
autoplay: true,
|
|
219
223
|
startMuted: true,
|
|
@@ -285,7 +289,12 @@ var DEFAULT_PLAYER_CONFIG = {
|
|
|
285
289
|
enableWorker: true,
|
|
286
290
|
// VOD + AES-128: LL mode causes ABR thrash → bufferAppendError on MSE.
|
|
287
291
|
lowLatencyMode: false,
|
|
288
|
-
|
|
292
|
+
// Match a smooth encrypted VOD: 30s forward target, 60s ceiling,
|
|
293
|
+
// 20MB cap, and a short back buffer so MSE does not stall when full.
|
|
294
|
+
backBufferLength: 30,
|
|
295
|
+
maxBufferLength: 30,
|
|
296
|
+
maxMaxBufferLength: 60,
|
|
297
|
+
maxBufferSize: 20 * 1024 * 1024,
|
|
289
298
|
fatalRecoveryLimit: 3
|
|
290
299
|
}
|
|
291
300
|
},
|
|
@@ -309,6 +318,7 @@ var SKIP_DEEP_SCAN_KEYS = /* @__PURE__ */ new Set([
|
|
|
309
318
|
"getsource",
|
|
310
319
|
"refreshsource",
|
|
311
320
|
"keyproxyurlbuilder",
|
|
321
|
+
"mediaproxyurlbuilder",
|
|
312
322
|
"getkeyaccesstoken"
|
|
313
323
|
]);
|
|
314
324
|
var SECRET_SCAN_MAX_DEPTH = 32;
|
|
@@ -393,6 +403,7 @@ function mergePlayerConfig(partial) {
|
|
|
393
403
|
...DEFAULT_PLAYER_CONFIG.streaming.hls,
|
|
394
404
|
...partial?.streaming?.hls
|
|
395
405
|
},
|
|
406
|
+
mediaProxyUrlBuilder: partial?.streaming?.mediaProxyUrlBuilder,
|
|
396
407
|
keyProxyUrlBuilder: partial?.streaming?.keyProxyUrlBuilder,
|
|
397
408
|
getKeyAccessToken: partial?.streaming?.getKeyAccessToken,
|
|
398
409
|
keyProxyMaxFailures: partial?.streaming?.keyProxyMaxFailures
|
|
@@ -701,6 +712,7 @@ var RefreshManager = class {
|
|
|
701
712
|
constructor(options) {
|
|
702
713
|
this.options = options;
|
|
703
714
|
this.timer = null;
|
|
715
|
+
this.intervalTimer = null;
|
|
704
716
|
this.coalesceTimer = null;
|
|
705
717
|
this.inFlight = false;
|
|
706
718
|
this.consecutiveFailures = 0;
|
|
@@ -709,6 +721,7 @@ var RefreshManager = class {
|
|
|
709
721
|
}
|
|
710
722
|
start(initialExpiresAt) {
|
|
711
723
|
this.schedule(initialExpiresAt);
|
|
724
|
+
this.armInterval();
|
|
712
725
|
}
|
|
713
726
|
requestRenew(reason = "frag_error") {
|
|
714
727
|
if (this.stopped || this.options.isDestroyed()) return;
|
|
@@ -724,8 +737,10 @@ var RefreshManager = class {
|
|
|
724
737
|
stop() {
|
|
725
738
|
this.stopped = true;
|
|
726
739
|
if (this.timer) clearTimeout(this.timer);
|
|
740
|
+
if (this.intervalTimer) clearTimeout(this.intervalTimer);
|
|
727
741
|
if (this.coalesceTimer) clearTimeout(this.coalesceTimer);
|
|
728
742
|
this.timer = null;
|
|
743
|
+
this.intervalTimer = null;
|
|
729
744
|
this.coalesceTimer = null;
|
|
730
745
|
}
|
|
731
746
|
schedule(expiresAt) {
|
|
@@ -739,13 +754,25 @@ var RefreshManager = class {
|
|
|
739
754
|
void this.renew("proactive");
|
|
740
755
|
}, delay);
|
|
741
756
|
}
|
|
757
|
+
/** Rotate the token on a fixed cadence. The loader reads the store live. */
|
|
758
|
+
armInterval() {
|
|
759
|
+
const interval = this.options.refreshIntervalMs;
|
|
760
|
+
if (!interval || interval < 5e3 || this.stopped) return;
|
|
761
|
+
if (this.intervalTimer) clearTimeout(this.intervalTimer);
|
|
762
|
+
this.intervalTimer = setTimeout(() => {
|
|
763
|
+
this.intervalTimer = null;
|
|
764
|
+
if (this.stopped) return;
|
|
765
|
+
void this.renew("proactive");
|
|
766
|
+
this.armInterval();
|
|
767
|
+
}, interval);
|
|
768
|
+
}
|
|
742
769
|
async renew(reason) {
|
|
743
770
|
if (this.stopped || this.options.isDestroyed() || this.inFlight) {
|
|
744
771
|
if (this.inFlight) this.pendingReason = reason;
|
|
745
772
|
return;
|
|
746
773
|
}
|
|
747
774
|
this.inFlight = true;
|
|
748
|
-
this.options.onRenewing?.();
|
|
775
|
+
this.options.onRenewing?.(reason);
|
|
749
776
|
try {
|
|
750
777
|
await this.options.authManager.ensureToken({
|
|
751
778
|
reason: reason === "proactive" ? "expiring" : "unauthorized",
|
|
@@ -756,7 +783,7 @@ var RefreshManager = class {
|
|
|
756
783
|
reason: reason === "proactive" ? "expiring" : reason === "manual" ? "manual" : "auth_error"
|
|
757
784
|
});
|
|
758
785
|
this.consecutiveFailures = 0;
|
|
759
|
-
this.options.onRenewed?.(source.expiresAt);
|
|
786
|
+
this.options.onRenewed?.(source.expiresAt, reason);
|
|
760
787
|
this.schedule(source.expiresAt);
|
|
761
788
|
this.options.logger.debug("Playback source renewed", { reason });
|
|
762
789
|
} catch (error) {
|
|
@@ -834,6 +861,26 @@ function seekToLiveEdge(media, options) {
|
|
|
834
861
|
return { moved: true, edge };
|
|
835
862
|
}
|
|
836
863
|
|
|
864
|
+
// src/streaming/mediaUrl.ts
|
|
865
|
+
var LIVE_PLAYLIST_PATH = /\/(?:hls-web-live|live)\//i;
|
|
866
|
+
function isLivePlaylistUrl(value) {
|
|
867
|
+
if (LIVE_PLAYLIST_PATH.test(value)) return true;
|
|
868
|
+
try {
|
|
869
|
+
const parsed = new URL(value, "http://localhost");
|
|
870
|
+
const inner = parsed.searchParams.get("url");
|
|
871
|
+
return Boolean(inner && LIVE_PLAYLIST_PATH.test(inner));
|
|
872
|
+
} catch {
|
|
873
|
+
return false;
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
function isSameOriginHttpUrl(value, baseOrigin) {
|
|
877
|
+
try {
|
|
878
|
+
return new URL(value, baseOrigin).origin === new URL(baseOrigin).origin;
|
|
879
|
+
} catch {
|
|
880
|
+
return false;
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
|
|
837
884
|
// src/streaming/authParamsLoader.ts
|
|
838
885
|
var ENC_KEY_PATH_RE = /enc\.key$/i;
|
|
839
886
|
var BUILTIN_LOADER_NAMES = /* @__PURE__ */ new Set(["XhrLoader", "FetchLoader"]);
|
|
@@ -903,8 +950,16 @@ function rewriteHlsRequestUrl(rawUrl, store, options = {}, baseOrigin = typeof l
|
|
|
903
950
|
mobile: snapshot.mobile
|
|
904
951
|
});
|
|
905
952
|
}
|
|
906
|
-
|
|
907
|
-
return
|
|
953
|
+
const withAuth = store.hasParams() ? store.applyToUrl(rawUrl, baseOrigin) : parsed.toString();
|
|
954
|
+
return applyMediaProxy(withAuth, options, baseOrigin);
|
|
955
|
+
}
|
|
956
|
+
function applyMediaProxy(url, options, baseOrigin) {
|
|
957
|
+
if (!options.mediaProxyUrlBuilder) return url;
|
|
958
|
+
if (isSameOriginHttpUrl(url, baseOrigin)) return url;
|
|
959
|
+
return options.mediaProxyUrlBuilder({
|
|
960
|
+
url,
|
|
961
|
+
videoId: options.videoId
|
|
962
|
+
});
|
|
908
963
|
}
|
|
909
964
|
function createLoaderStats() {
|
|
910
965
|
const now = performance.now();
|
|
@@ -935,12 +990,14 @@ function isProxyUpstreamBlocked(status, contentType, bodyHead, errorText) {
|
|
|
935
990
|
return false;
|
|
936
991
|
}
|
|
937
992
|
async function fetchEncryptionKeyBytes(url, accessToken, signal) {
|
|
938
|
-
const
|
|
993
|
+
const pageOrigin = typeof location !== "undefined" ? location.origin : "http://localhost";
|
|
994
|
+
const sameOrigin = isSameOriginHttpUrl(url, pageOrigin);
|
|
995
|
+
const headers = !sameOrigin && accessToken ? { Authorization: `Bearer ${accessToken}`, Accept: "*/*" } : void 0;
|
|
939
996
|
try {
|
|
940
997
|
const response = await fetch(url, {
|
|
941
998
|
method: "GET",
|
|
942
999
|
...headers ? { headers } : {},
|
|
943
|
-
credentials: "omit",
|
|
1000
|
+
credentials: sameOrigin ? "same-origin" : "omit",
|
|
944
1001
|
cache: "no-store",
|
|
945
1002
|
signal
|
|
946
1003
|
});
|
|
@@ -1231,7 +1288,7 @@ function createAuthParamsLoader(HlsModule, store, options = {}) {
|
|
|
1231
1288
|
const originalUrl = context.url;
|
|
1232
1289
|
const isKey = isEncryptionKeyUrl(originalUrl);
|
|
1233
1290
|
if (!isKey) {
|
|
1234
|
-
if (store.hasParams()) {
|
|
1291
|
+
if (store.hasParams() || options.mediaProxyUrlBuilder) {
|
|
1235
1292
|
context.url = rewriteHlsRequestUrl(originalUrl, store, {
|
|
1236
1293
|
...options,
|
|
1237
1294
|
keyProxyUrlBuilder: void 0
|
|
@@ -1356,7 +1413,7 @@ var HlsEngine = class {
|
|
|
1356
1413
|
if (videoEl.canPlayType("application/vnd.apple.mpegurl")) {
|
|
1357
1414
|
this.supportMode = "native";
|
|
1358
1415
|
this.options.callbacks.onSupportMode?.("native");
|
|
1359
|
-
videoEl.src = this.
|
|
1416
|
+
videoEl.src = this.playbackRequestUrl(playbackUrl);
|
|
1360
1417
|
this.bindMediaEvents();
|
|
1361
1418
|
this.bindNativeTextTracks();
|
|
1362
1419
|
this.options.callbacks.onStateChange?.("ready");
|
|
@@ -1381,6 +1438,7 @@ var HlsEngine = class {
|
|
|
1381
1438
|
} = this.options;
|
|
1382
1439
|
const loader = createAuthParamsLoader(Hls, authParams, {
|
|
1383
1440
|
videoId,
|
|
1441
|
+
mediaProxyUrlBuilder: this.options.mediaProxyUrlBuilder,
|
|
1384
1442
|
keyProxyUrlBuilder,
|
|
1385
1443
|
getKeyAccessToken,
|
|
1386
1444
|
keyProxyMaxFailures: this.options.keyProxyMaxFailures
|
|
@@ -1391,25 +1449,25 @@ var HlsEngine = class {
|
|
|
1391
1449
|
"Disabling hls.js worker on Firefox to avoid MSE bufferAppendError"
|
|
1392
1450
|
);
|
|
1393
1451
|
}
|
|
1452
|
+
const startPosition = this.options.startPosition;
|
|
1394
1453
|
this.hls = new Hls({
|
|
1395
1454
|
enableWorker,
|
|
1396
1455
|
// LL mode on short encrypted VOD drives aggressive ABR thrash → MSE errors.
|
|
1397
1456
|
lowLatencyMode: hlsConfig.lowLatencyMode,
|
|
1398
1457
|
backBufferLength: hlsConfig.backBufferLength,
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1458
|
+
maxBufferLength: hlsConfig.maxBufferLength,
|
|
1459
|
+
maxMaxBufferLength: hlsConfig.maxMaxBufferLength,
|
|
1460
|
+
maxBufferSize: hlsConfig.maxBufferSize,
|
|
1461
|
+
startPosition: typeof startPosition === "number" && startPosition > 0 ? startPosition : -1,
|
|
1462
|
+
// A first-fragment bandwidth probe on short encrypted VODs truncates
|
|
1463
|
+
// the body and immediately hops levels. ABR itself stays on hls.js
|
|
1464
|
+
// defaults so a long VOD is not held on the lowest rung.
|
|
1402
1465
|
testBandwidth: false,
|
|
1403
|
-
abrEwmaDefaultEstimate: 5e5,
|
|
1404
|
-
abrBandWidthFactor: 0.8,
|
|
1405
|
-
abrBandWidthUpFactor: 0.5,
|
|
1406
|
-
maxStarvationDelay: 4,
|
|
1407
|
-
capLevelToPlayerSize: true,
|
|
1408
1466
|
startLevel: -1,
|
|
1409
1467
|
loader
|
|
1410
1468
|
});
|
|
1411
1469
|
this.hls.attachMedia(videoEl);
|
|
1412
|
-
this.hls.loadSource(
|
|
1470
|
+
this.hls.loadSource(this.playbackRequestUrl(playbackUrl));
|
|
1413
1471
|
this.hls.on(Hls.Events.MANIFEST_PARSED, (_event, data) => {
|
|
1414
1472
|
if (this.destroyed) return;
|
|
1415
1473
|
this.qualities = (data.levels ?? []).map((level, index) => ({
|
|
@@ -1512,35 +1570,35 @@ var HlsEngine = class {
|
|
|
1512
1570
|
}
|
|
1513
1571
|
}
|
|
1514
1572
|
clampStartPosition(raw, videoEl) {
|
|
1515
|
-
|
|
1573
|
+
const t = Math.max(0, raw);
|
|
1516
1574
|
const duration = videoEl.duration;
|
|
1517
1575
|
if (Number.isFinite(duration) && duration > 0) {
|
|
1518
|
-
|
|
1519
|
-
}
|
|
1520
|
-
if (videoEl.seekable.length > 0) {
|
|
1521
|
-
const end = videoEl.seekable.end(videoEl.seekable.length - 1);
|
|
1522
|
-
if (Number.isFinite(end)) {
|
|
1523
|
-
t = Math.min(t, end);
|
|
1524
|
-
}
|
|
1576
|
+
return Math.min(t, Math.max(0, duration - 0.35));
|
|
1525
1577
|
}
|
|
1526
1578
|
return t;
|
|
1527
1579
|
}
|
|
1528
1580
|
async applyStartPositionOnly() {
|
|
1529
1581
|
if (this.destroyed || this.startPositionApplied) return;
|
|
1530
1582
|
const { videoEl, startPosition } = this.options;
|
|
1583
|
+
if (typeof startPosition !== "number" || startPosition <= 0) {
|
|
1584
|
+
this.startPositionApplied = true;
|
|
1585
|
+
return;
|
|
1586
|
+
}
|
|
1587
|
+
const durationKnown = Number.isFinite(videoEl.duration) && videoEl.duration > 0;
|
|
1588
|
+
if (!durationKnown) {
|
|
1589
|
+
videoEl.addEventListener(
|
|
1590
|
+
"loadedmetadata",
|
|
1591
|
+
() => {
|
|
1592
|
+
void this.applyStartPositionOnly();
|
|
1593
|
+
},
|
|
1594
|
+
{ once: true }
|
|
1595
|
+
);
|
|
1596
|
+
return;
|
|
1597
|
+
}
|
|
1531
1598
|
this.startPositionApplied = true;
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
try {
|
|
1536
|
-
videoEl.currentTime = this.clampStartPosition(startPosition, videoEl);
|
|
1537
|
-
} catch {
|
|
1538
|
-
}
|
|
1539
|
-
};
|
|
1540
|
-
if (videoEl.seekable.length > 0 || Number.isFinite(videoEl.duration)) {
|
|
1541
|
-
seek();
|
|
1542
|
-
} else {
|
|
1543
|
-
videoEl.addEventListener("loadedmetadata", seek, { once: true });
|
|
1599
|
+
try {
|
|
1600
|
+
videoEl.currentTime = this.clampStartPosition(startPosition, videoEl);
|
|
1601
|
+
} catch {
|
|
1544
1602
|
}
|
|
1545
1603
|
}
|
|
1546
1604
|
async applyAutoplayOnly() {
|
|
@@ -1587,16 +1645,28 @@ var HlsEngine = class {
|
|
|
1587
1645
|
if (this.supportMode === "native" && this.options.videoEl) {
|
|
1588
1646
|
const time = this.options.videoEl.currentTime;
|
|
1589
1647
|
const wasPaused = this.options.videoEl.paused;
|
|
1590
|
-
this.options.videoEl.src = this.options.
|
|
1591
|
-
this.options.playbackUrl
|
|
1592
|
-
);
|
|
1648
|
+
this.options.videoEl.src = this.playbackRequestUrl(this.options.playbackUrl);
|
|
1593
1649
|
this.options.videoEl.currentTime = time;
|
|
1594
1650
|
if (!wasPaused) void this.options.videoEl.play();
|
|
1595
1651
|
}
|
|
1596
1652
|
}
|
|
1597
|
-
|
|
1653
|
+
playbackRequestUrl(playbackUrl) {
|
|
1654
|
+
return rewriteHlsRequestUrl(playbackUrl, this.options.authParams, {
|
|
1655
|
+
videoId: this.options.videoId,
|
|
1656
|
+
mediaProxyUrlBuilder: this.options.mediaProxyUrlBuilder,
|
|
1657
|
+
keyProxyUrlBuilder: this.options.keyProxyUrlBuilder,
|
|
1658
|
+
getKeyAccessToken: this.options.getKeyAccessToken,
|
|
1659
|
+
keyProxyMaxFailures: this.options.keyProxyMaxFailures
|
|
1660
|
+
});
|
|
1661
|
+
}
|
|
1662
|
+
/**
|
|
1663
|
+
* Auth params are already on the shared store, so the next request uses
|
|
1664
|
+
* the new token. Restart the loader only after a real auth failure.
|
|
1665
|
+
* A proactive refresh must not abort the buffered segments.
|
|
1666
|
+
*/
|
|
1667
|
+
resumeAfterAuthRenew(restart = true) {
|
|
1598
1668
|
this.networkRecoveryCount = 0;
|
|
1599
|
-
this.hls?.startLoad();
|
|
1669
|
+
if (restart) this.hls?.startLoad();
|
|
1600
1670
|
this.updateAuthParams();
|
|
1601
1671
|
}
|
|
1602
1672
|
setQuality(selection) {
|
|
@@ -1858,7 +1928,7 @@ function createVideoPlayer(options) {
|
|
|
1858
1928
|
const source = {
|
|
1859
1929
|
url: options.sourceUrl,
|
|
1860
1930
|
expiresAt: Date.now() + 24 * 60 * 60 * 1e3,
|
|
1861
|
-
live:
|
|
1931
|
+
live: isLivePlaylistUrl(options.sourceUrl)
|
|
1862
1932
|
};
|
|
1863
1933
|
sourceManager.applyDirectSource(source);
|
|
1864
1934
|
playbackUrl = source.url;
|
|
@@ -1888,6 +1958,7 @@ function createVideoPlayer(options) {
|
|
|
1888
1958
|
startPosition: config.player.startPosition,
|
|
1889
1959
|
volume: config.player.volume,
|
|
1890
1960
|
videoId: options.videoId,
|
|
1961
|
+
mediaProxyUrlBuilder: config.streaming.mediaProxyUrlBuilder,
|
|
1891
1962
|
keyProxyUrlBuilder: config.streaming.keyProxyUrlBuilder,
|
|
1892
1963
|
// Enterprise AES key auth (see authParamsLoader):
|
|
1893
1964
|
// 1) keyProxyUrlBuilder BFF — max 2 failures then circuit
|
|
@@ -1981,12 +2052,15 @@ function createVideoPlayer(options) {
|
|
|
1981
2052
|
renewMaxRetries: options.playback.renewMaxRetries ?? 3,
|
|
1982
2053
|
renewBackoffMs: options.playback.renewBackoffMs ?? 2e3,
|
|
1983
2054
|
coalesceMs: options.playback.authRecoveryCoalesceMs ?? 1e3,
|
|
2055
|
+
refreshIntervalMs: options.playback.refreshIntervalMs ?? DEFAULT_PLAYBACK_REFRESH_INTERVAL_MS,
|
|
1984
2056
|
logger,
|
|
1985
2057
|
isDestroyed: () => destroyed,
|
|
1986
|
-
onRenewing: () =>
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
2058
|
+
onRenewing: (reason) => {
|
|
2059
|
+
if (reason !== "proactive") setState("renewing");
|
|
2060
|
+
},
|
|
2061
|
+
onRenewed: (nextExpiresAt, reason) => {
|
|
2062
|
+
engine?.resumeAfterAuthRenew(reason !== "proactive");
|
|
2063
|
+
if (reason !== "proactive" && !destroyed) {
|
|
1990
2064
|
const el2 = videoEl;
|
|
1991
2065
|
if (el2 && !el2.paused && !el2.ended) {
|
|
1992
2066
|
setState("playing");
|
|
@@ -2046,8 +2120,13 @@ function createVideoPlayer(options) {
|
|
|
2046
2120
|
},
|
|
2047
2121
|
seek(time) {
|
|
2048
2122
|
const el = ensureVideoElement();
|
|
2049
|
-
const
|
|
2050
|
-
|
|
2123
|
+
const requested = Math.max(0, time);
|
|
2124
|
+
const duration = el.duration;
|
|
2125
|
+
if (Number.isFinite(duration) && duration > 0) {
|
|
2126
|
+
el.currentTime = Math.min(requested, Math.max(0, duration - 0.05));
|
|
2127
|
+
} else {
|
|
2128
|
+
el.currentTime = requested;
|
|
2129
|
+
}
|
|
2051
2130
|
},
|
|
2052
2131
|
goToLive() {
|
|
2053
2132
|
const el = ensureVideoElement();
|
|
@@ -2219,6 +2298,7 @@ function createVideoPlayer(options) {
|
|
|
2219
2298
|
streaming: {
|
|
2220
2299
|
engine: "hls",
|
|
2221
2300
|
hls: { ...config.streaming.hls, ...partial?.streaming?.hls },
|
|
2301
|
+
mediaProxyUrlBuilder: partial?.streaming?.mediaProxyUrlBuilder ?? config.streaming.mediaProxyUrlBuilder,
|
|
2222
2302
|
keyProxyUrlBuilder: partial?.streaming?.keyProxyUrlBuilder ?? config.streaming.keyProxyUrlBuilder,
|
|
2223
2303
|
getKeyAccessToken: partial?.streaming?.getKeyAccessToken ?? config.streaming.getKeyAccessToken ?? (() => authManager.getAccessToken()),
|
|
2224
2304
|
keyProxyMaxFailures: partial?.streaming?.keyProxyMaxFailures ?? config.streaming.keyProxyMaxFailures
|
|
@@ -2248,6 +2328,7 @@ function createVideoPlayer(options) {
|
|
|
2248
2328
|
AuthParamsStore,
|
|
2249
2329
|
DEFAULT_CONTROLS,
|
|
2250
2330
|
DEFAULT_LIVE_EDGE_TOLERANCE_SECONDS,
|
|
2331
|
+
DEFAULT_PLAYBACK_REFRESH_INTERVAL_MS,
|
|
2251
2332
|
DEFAULT_PLAYER_BEHAVIOR,
|
|
2252
2333
|
DEFAULT_PLAYER_CONFIG,
|
|
2253
2334
|
DEFAULT_THEME,
|
|
@@ -2267,7 +2348,9 @@ function createVideoPlayer(options) {
|
|
|
2267
2348
|
getLiveEdgeTime,
|
|
2268
2349
|
isAtLiveEdge,
|
|
2269
2350
|
isEncryptionKeyUrl,
|
|
2351
|
+
isLivePlaylistUrl,
|
|
2270
2352
|
isPlainObject,
|
|
2353
|
+
isSameOriginHttpUrl,
|
|
2271
2354
|
mergePlayerConfig,
|
|
2272
2355
|
redactObject,
|
|
2273
2356
|
redactSensitive,
|