@codenkay/video-nsgplayer-core 5.1.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 +8 -0
- package/README.md +11 -8
- package/dist/index.cjs +77 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -5
- package/dist/index.d.ts +34 -5
- package/dist/index.js +76 -40
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -58,6 +58,12 @@ type PlaybackCredentialConfig = {
|
|
|
58
58
|
getSource: (context: PlaybackSourceContext) => Promise<PlaybackSource>;
|
|
59
59
|
refreshSource?: (context: PlaybackSourceContext) => Promise<PlaybackSource>;
|
|
60
60
|
refreshBeforeExpiryMs?: number;
|
|
61
|
+
/**
|
|
62
|
+
* Rotate the playback token on this cadence without restarting the loader.
|
|
63
|
+
* The working player refreshes every 45 seconds and applies the new token
|
|
64
|
+
* on the next media request.
|
|
65
|
+
*/
|
|
66
|
+
refreshIntervalMs?: number;
|
|
61
67
|
renewMaxRetries?: number;
|
|
62
68
|
renewBackoffMs?: number;
|
|
63
69
|
authRecoveryCoalesceMs?: number;
|
|
@@ -134,6 +140,12 @@ type StreamingConfig = {
|
|
|
134
140
|
enableWorker?: boolean;
|
|
135
141
|
lowLatencyMode?: boolean;
|
|
136
142
|
backBufferLength?: number;
|
|
143
|
+
/** Target forward buffer, in seconds. */
|
|
144
|
+
maxBufferLength?: number;
|
|
145
|
+
/** Upper forward buffer while bandwidth is spare, in seconds. */
|
|
146
|
+
maxMaxBufferLength?: number;
|
|
147
|
+
/** Forward buffer cap, in bytes. */
|
|
148
|
+
maxBufferSize?: number;
|
|
137
149
|
fatalRecoveryLimit?: number;
|
|
138
150
|
};
|
|
139
151
|
/**
|
|
@@ -300,7 +312,12 @@ type PlayerEventMap = {
|
|
|
300
312
|
};
|
|
301
313
|
|
|
302
314
|
declare const PLAYBACK_RATES: readonly [0.5, 0.75, 1, 1.25, 1.5, 2];
|
|
303
|
-
|
|
315
|
+
/**
|
|
316
|
+
* Rotate the playback token on this cadence. The loader keeps its buffer
|
|
317
|
+
* and applies the new token on the next media request.
|
|
318
|
+
*/
|
|
319
|
+
declare const DEFAULT_PLAYBACK_REFRESH_INTERVAL_MS = 45000;
|
|
320
|
+
declare const PACKAGE_VERSION = "5.2.0";
|
|
304
321
|
declare const DEFAULT_PLAYER_BEHAVIOR: Required<PlayerBehaviorConfig>;
|
|
305
322
|
declare const DEFAULT_CONTROLS: Required<ControlsConfig>;
|
|
306
323
|
declare const DEFAULT_THEME: Required<ThemeConfig>;
|
|
@@ -460,6 +477,9 @@ type HlsEngineOptions = {
|
|
|
460
477
|
enableWorker: boolean;
|
|
461
478
|
lowLatencyMode: boolean;
|
|
462
479
|
backBufferLength: number;
|
|
480
|
+
maxBufferLength: number;
|
|
481
|
+
maxMaxBufferLength: number;
|
|
482
|
+
maxBufferSize: number;
|
|
463
483
|
fatalRecoveryLimit: number;
|
|
464
484
|
};
|
|
465
485
|
logger: Logger;
|
|
@@ -494,7 +514,12 @@ declare class HlsEngine {
|
|
|
494
514
|
private bindMediaEvents;
|
|
495
515
|
updateAuthParams(): void;
|
|
496
516
|
private playbackRequestUrl;
|
|
497
|
-
|
|
517
|
+
/**
|
|
518
|
+
* Auth params are already on the shared store, so the next request uses
|
|
519
|
+
* the new token. Restart the loader only after a real auth failure.
|
|
520
|
+
* A proactive refresh must not abort the buffered segments.
|
|
521
|
+
*/
|
|
522
|
+
resumeAfterAuthRenew(restart?: boolean): void;
|
|
498
523
|
setQuality(selection: QualitySelection): void;
|
|
499
524
|
getQuality(): QualitySelection;
|
|
500
525
|
getQualities(): HlsQualityLevel[];
|
|
@@ -638,13 +663,14 @@ type RefreshManagerOptions = {
|
|
|
638
663
|
authManager: AuthManager;
|
|
639
664
|
sourceManager: PlaybackSourceManager;
|
|
640
665
|
refreshBeforeExpiryMs: number;
|
|
666
|
+
refreshIntervalMs?: number;
|
|
641
667
|
renewMaxRetries: number;
|
|
642
668
|
renewBackoffMs: number;
|
|
643
669
|
coalesceMs: number;
|
|
644
670
|
logger: Logger;
|
|
645
671
|
isDestroyed: () => boolean;
|
|
646
|
-
onRenewing?: () => void;
|
|
647
|
-
onRenewed?: (expiresAt: number) => void;
|
|
672
|
+
onRenewing?: (reason: RefreshReason) => void;
|
|
673
|
+
onRenewed?: (expiresAt: number, reason: RefreshReason) => void;
|
|
648
674
|
onFatal?: (message: string) => void;
|
|
649
675
|
};
|
|
650
676
|
/**
|
|
@@ -654,6 +680,7 @@ type RefreshManagerOptions = {
|
|
|
654
680
|
declare class RefreshManager {
|
|
655
681
|
private readonly options;
|
|
656
682
|
private timer;
|
|
683
|
+
private intervalTimer;
|
|
657
684
|
private coalesceTimer;
|
|
658
685
|
private inFlight;
|
|
659
686
|
private consecutiveFailures;
|
|
@@ -664,6 +691,8 @@ declare class RefreshManager {
|
|
|
664
691
|
requestRenew(reason?: RefreshReason): void;
|
|
665
692
|
stop(): void;
|
|
666
693
|
private schedule;
|
|
694
|
+
/** Rotate the token on a fixed cadence. The loader reads the store live. */
|
|
695
|
+
private armInterval;
|
|
667
696
|
private renew;
|
|
668
697
|
}
|
|
669
698
|
|
|
@@ -766,4 +795,4 @@ declare function redactValue(key: string, value: unknown, seen?: WeakSet<object>
|
|
|
766
795
|
*/
|
|
767
796
|
declare function redactObject(obj: Record<string, unknown>, seen?: WeakSet<object>, depth?: number): Record<string, unknown>;
|
|
768
797
|
|
|
769
|
-
export { type AccessibilityConfig, type AnalyticsConfig, type AuthConfig, AuthManager, AuthParamsStore, type AuthToken, type AuthTokenProviderContext, type BufferedRange, type ControlsConfig, type CreateVideoPlayerOptions, DEFAULT_CONTROLS, DEFAULT_LIVE_EDGE_TOLERANCE_SECONDS, DEFAULT_PLAYER_BEHAVIOR, DEFAULT_PLAYER_CONFIG, DEFAULT_THEME, DEFAULT_WATERMARK, type DebugConfig, EventEmitter, type HlsLoaderConstructor, type HlsModuleLike, type HlsQualityLevel, type HlsSupportMode, KEY_PROXY_MAX_FAILURES, type LiveMediaSnapshot, type LoggingConfig, PACKAGE_VERSION, PLAYBACK_RATES, type PlayIconPreset, type PlaybackCredentialConfig, type PlaybackRate, type PlaybackSource, type PlaybackSourceContext, PlaybackSourceManager, type PlayerAudioTrack, type PlayerBehaviorConfig, type PlayerConfig, type PlayerDiagnostics, type PlayerError, PlayerErrorCode, type PlayerEventMap, type PlayerSkipSeconds, type PlayerState, type PlayerTextTrack, type PlayerZoomLevel, type QualitySelection, RefreshManager, SECRET_SCAN_MAX_DEPTH, type SeekToLiveResult, type StreamingConfig, type TextTrackSelection, type ThemeConfig, type VideoPlayer, type WatermarkConfig, assertNoSecretsInConfig, createAuthParamsLoader, createPlayerError, createVideoPlayer, getLiveEdgeTime, isAtLiveEdge, isEncryptionKeyUrl, isLivePlaylistUrl, isPlainObject, isSameOriginHttpUrl, mergePlayerConfig, redactObject, redactSensitive, redactValue, resolveBuiltinHlsLoader, rewriteHlsRequestUrl, seekToLiveEdge, themeToCssVars };
|
|
798
|
+
export { type AccessibilityConfig, type AnalyticsConfig, type AuthConfig, AuthManager, AuthParamsStore, type AuthToken, type AuthTokenProviderContext, type BufferedRange, type ControlsConfig, type CreateVideoPlayerOptions, DEFAULT_CONTROLS, DEFAULT_LIVE_EDGE_TOLERANCE_SECONDS, DEFAULT_PLAYBACK_REFRESH_INTERVAL_MS, DEFAULT_PLAYER_BEHAVIOR, DEFAULT_PLAYER_CONFIG, DEFAULT_THEME, DEFAULT_WATERMARK, type DebugConfig, EventEmitter, type HlsLoaderConstructor, type HlsModuleLike, type HlsQualityLevel, type HlsSupportMode, KEY_PROXY_MAX_FAILURES, type LiveMediaSnapshot, type LoggingConfig, PACKAGE_VERSION, PLAYBACK_RATES, type PlayIconPreset, type PlaybackCredentialConfig, type PlaybackRate, type PlaybackSource, type PlaybackSourceContext, PlaybackSourceManager, type PlayerAudioTrack, type PlayerBehaviorConfig, type PlayerConfig, type PlayerDiagnostics, type PlayerError, PlayerErrorCode, type PlayerEventMap, type PlayerSkipSeconds, type PlayerState, type PlayerTextTrack, type PlayerZoomLevel, type QualitySelection, RefreshManager, SECRET_SCAN_MAX_DEPTH, type SeekToLiveResult, type StreamingConfig, type TextTrackSelection, type ThemeConfig, type VideoPlayer, type WatermarkConfig, assertNoSecretsInConfig, createAuthParamsLoader, createPlayerError, createVideoPlayer, getLiveEdgeTime, isAtLiveEdge, isEncryptionKeyUrl, isLivePlaylistUrl, isPlainObject, isSameOriginHttpUrl, mergePlayerConfig, redactObject, redactSensitive, redactValue, resolveBuiltinHlsLoader, rewriteHlsRequestUrl, seekToLiveEdge, themeToCssVars };
|
package/dist/index.d.ts
CHANGED
|
@@ -58,6 +58,12 @@ type PlaybackCredentialConfig = {
|
|
|
58
58
|
getSource: (context: PlaybackSourceContext) => Promise<PlaybackSource>;
|
|
59
59
|
refreshSource?: (context: PlaybackSourceContext) => Promise<PlaybackSource>;
|
|
60
60
|
refreshBeforeExpiryMs?: number;
|
|
61
|
+
/**
|
|
62
|
+
* Rotate the playback token on this cadence without restarting the loader.
|
|
63
|
+
* The working player refreshes every 45 seconds and applies the new token
|
|
64
|
+
* on the next media request.
|
|
65
|
+
*/
|
|
66
|
+
refreshIntervalMs?: number;
|
|
61
67
|
renewMaxRetries?: number;
|
|
62
68
|
renewBackoffMs?: number;
|
|
63
69
|
authRecoveryCoalesceMs?: number;
|
|
@@ -134,6 +140,12 @@ type StreamingConfig = {
|
|
|
134
140
|
enableWorker?: boolean;
|
|
135
141
|
lowLatencyMode?: boolean;
|
|
136
142
|
backBufferLength?: number;
|
|
143
|
+
/** Target forward buffer, in seconds. */
|
|
144
|
+
maxBufferLength?: number;
|
|
145
|
+
/** Upper forward buffer while bandwidth is spare, in seconds. */
|
|
146
|
+
maxMaxBufferLength?: number;
|
|
147
|
+
/** Forward buffer cap, in bytes. */
|
|
148
|
+
maxBufferSize?: number;
|
|
137
149
|
fatalRecoveryLimit?: number;
|
|
138
150
|
};
|
|
139
151
|
/**
|
|
@@ -300,7 +312,12 @@ type PlayerEventMap = {
|
|
|
300
312
|
};
|
|
301
313
|
|
|
302
314
|
declare const PLAYBACK_RATES: readonly [0.5, 0.75, 1, 1.25, 1.5, 2];
|
|
303
|
-
|
|
315
|
+
/**
|
|
316
|
+
* Rotate the playback token on this cadence. The loader keeps its buffer
|
|
317
|
+
* and applies the new token on the next media request.
|
|
318
|
+
*/
|
|
319
|
+
declare const DEFAULT_PLAYBACK_REFRESH_INTERVAL_MS = 45000;
|
|
320
|
+
declare const PACKAGE_VERSION = "5.2.0";
|
|
304
321
|
declare const DEFAULT_PLAYER_BEHAVIOR: Required<PlayerBehaviorConfig>;
|
|
305
322
|
declare const DEFAULT_CONTROLS: Required<ControlsConfig>;
|
|
306
323
|
declare const DEFAULT_THEME: Required<ThemeConfig>;
|
|
@@ -460,6 +477,9 @@ type HlsEngineOptions = {
|
|
|
460
477
|
enableWorker: boolean;
|
|
461
478
|
lowLatencyMode: boolean;
|
|
462
479
|
backBufferLength: number;
|
|
480
|
+
maxBufferLength: number;
|
|
481
|
+
maxMaxBufferLength: number;
|
|
482
|
+
maxBufferSize: number;
|
|
463
483
|
fatalRecoveryLimit: number;
|
|
464
484
|
};
|
|
465
485
|
logger: Logger;
|
|
@@ -494,7 +514,12 @@ declare class HlsEngine {
|
|
|
494
514
|
private bindMediaEvents;
|
|
495
515
|
updateAuthParams(): void;
|
|
496
516
|
private playbackRequestUrl;
|
|
497
|
-
|
|
517
|
+
/**
|
|
518
|
+
* Auth params are already on the shared store, so the next request uses
|
|
519
|
+
* the new token. Restart the loader only after a real auth failure.
|
|
520
|
+
* A proactive refresh must not abort the buffered segments.
|
|
521
|
+
*/
|
|
522
|
+
resumeAfterAuthRenew(restart?: boolean): void;
|
|
498
523
|
setQuality(selection: QualitySelection): void;
|
|
499
524
|
getQuality(): QualitySelection;
|
|
500
525
|
getQualities(): HlsQualityLevel[];
|
|
@@ -638,13 +663,14 @@ type RefreshManagerOptions = {
|
|
|
638
663
|
authManager: AuthManager;
|
|
639
664
|
sourceManager: PlaybackSourceManager;
|
|
640
665
|
refreshBeforeExpiryMs: number;
|
|
666
|
+
refreshIntervalMs?: number;
|
|
641
667
|
renewMaxRetries: number;
|
|
642
668
|
renewBackoffMs: number;
|
|
643
669
|
coalesceMs: number;
|
|
644
670
|
logger: Logger;
|
|
645
671
|
isDestroyed: () => boolean;
|
|
646
|
-
onRenewing?: () => void;
|
|
647
|
-
onRenewed?: (expiresAt: number) => void;
|
|
672
|
+
onRenewing?: (reason: RefreshReason) => void;
|
|
673
|
+
onRenewed?: (expiresAt: number, reason: RefreshReason) => void;
|
|
648
674
|
onFatal?: (message: string) => void;
|
|
649
675
|
};
|
|
650
676
|
/**
|
|
@@ -654,6 +680,7 @@ type RefreshManagerOptions = {
|
|
|
654
680
|
declare class RefreshManager {
|
|
655
681
|
private readonly options;
|
|
656
682
|
private timer;
|
|
683
|
+
private intervalTimer;
|
|
657
684
|
private coalesceTimer;
|
|
658
685
|
private inFlight;
|
|
659
686
|
private consecutiveFailures;
|
|
@@ -664,6 +691,8 @@ declare class RefreshManager {
|
|
|
664
691
|
requestRenew(reason?: RefreshReason): void;
|
|
665
692
|
stop(): void;
|
|
666
693
|
private schedule;
|
|
694
|
+
/** Rotate the token on a fixed cadence. The loader reads the store live. */
|
|
695
|
+
private armInterval;
|
|
667
696
|
private renew;
|
|
668
697
|
}
|
|
669
698
|
|
|
@@ -766,4 +795,4 @@ declare function redactValue(key: string, value: unknown, seen?: WeakSet<object>
|
|
|
766
795
|
*/
|
|
767
796
|
declare function redactObject(obj: Record<string, unknown>, seen?: WeakSet<object>, depth?: number): Record<string, unknown>;
|
|
768
797
|
|
|
769
|
-
export { type AccessibilityConfig, type AnalyticsConfig, type AuthConfig, AuthManager, AuthParamsStore, type AuthToken, type AuthTokenProviderContext, type BufferedRange, type ControlsConfig, type CreateVideoPlayerOptions, DEFAULT_CONTROLS, DEFAULT_LIVE_EDGE_TOLERANCE_SECONDS, DEFAULT_PLAYER_BEHAVIOR, DEFAULT_PLAYER_CONFIG, DEFAULT_THEME, DEFAULT_WATERMARK, type DebugConfig, EventEmitter, type HlsLoaderConstructor, type HlsModuleLike, type HlsQualityLevel, type HlsSupportMode, KEY_PROXY_MAX_FAILURES, type LiveMediaSnapshot, type LoggingConfig, PACKAGE_VERSION, PLAYBACK_RATES, type PlayIconPreset, type PlaybackCredentialConfig, type PlaybackRate, type PlaybackSource, type PlaybackSourceContext, PlaybackSourceManager, type PlayerAudioTrack, type PlayerBehaviorConfig, type PlayerConfig, type PlayerDiagnostics, type PlayerError, PlayerErrorCode, type PlayerEventMap, type PlayerSkipSeconds, type PlayerState, type PlayerTextTrack, type PlayerZoomLevel, type QualitySelection, RefreshManager, SECRET_SCAN_MAX_DEPTH, type SeekToLiveResult, type StreamingConfig, type TextTrackSelection, type ThemeConfig, type VideoPlayer, type WatermarkConfig, assertNoSecretsInConfig, createAuthParamsLoader, createPlayerError, createVideoPlayer, getLiveEdgeTime, isAtLiveEdge, isEncryptionKeyUrl, isLivePlaylistUrl, isPlainObject, isSameOriginHttpUrl, mergePlayerConfig, redactObject, redactSensitive, redactValue, resolveBuiltinHlsLoader, rewriteHlsRequestUrl, seekToLiveEdge, themeToCssVars };
|
|
798
|
+
export { type AccessibilityConfig, type AnalyticsConfig, type AuthConfig, AuthManager, AuthParamsStore, type AuthToken, type AuthTokenProviderContext, type BufferedRange, type ControlsConfig, type CreateVideoPlayerOptions, DEFAULT_CONTROLS, DEFAULT_LIVE_EDGE_TOLERANCE_SECONDS, DEFAULT_PLAYBACK_REFRESH_INTERVAL_MS, DEFAULT_PLAYER_BEHAVIOR, DEFAULT_PLAYER_CONFIG, DEFAULT_THEME, DEFAULT_WATERMARK, type DebugConfig, EventEmitter, type HlsLoaderConstructor, type HlsModuleLike, type HlsQualityLevel, type HlsSupportMode, KEY_PROXY_MAX_FAILURES, type LiveMediaSnapshot, type LoggingConfig, PACKAGE_VERSION, PLAYBACK_RATES, type PlayIconPreset, type PlaybackCredentialConfig, type PlaybackRate, type PlaybackSource, type PlaybackSourceContext, PlaybackSourceManager, type PlayerAudioTrack, type PlayerBehaviorConfig, type PlayerConfig, type PlayerDiagnostics, type PlayerError, PlayerErrorCode, type PlayerEventMap, type PlayerSkipSeconds, type PlayerState, type PlayerTextTrack, type PlayerZoomLevel, type QualitySelection, RefreshManager, SECRET_SCAN_MAX_DEPTH, type SeekToLiveResult, type StreamingConfig, type TextTrackSelection, type ThemeConfig, type VideoPlayer, type WatermarkConfig, assertNoSecretsInConfig, createAuthParamsLoader, createPlayerError, createVideoPlayer, getLiveEdgeTime, isAtLiveEdge, isEncryptionKeyUrl, isLivePlaylistUrl, isPlainObject, isSameOriginHttpUrl, mergePlayerConfig, redactObject, redactSensitive, redactValue, resolveBuiltinHlsLoader, rewriteHlsRequestUrl, seekToLiveEdge, themeToCssVars };
|
package/dist/index.js
CHANGED
|
@@ -146,7 +146,8 @@ var AuthManager = class {
|
|
|
146
146
|
|
|
147
147
|
// src/config/defaults.ts
|
|
148
148
|
var PLAYBACK_RATES = [0.5, 0.75, 1, 1.25, 1.5, 2];
|
|
149
|
-
var
|
|
149
|
+
var DEFAULT_PLAYBACK_REFRESH_INTERVAL_MS = 45e3;
|
|
150
|
+
var PACKAGE_VERSION = "5.2.0";
|
|
150
151
|
var DEFAULT_PLAYER_BEHAVIOR = {
|
|
151
152
|
autoplay: true,
|
|
152
153
|
startMuted: true,
|
|
@@ -218,7 +219,12 @@ var DEFAULT_PLAYER_CONFIG = {
|
|
|
218
219
|
enableWorker: true,
|
|
219
220
|
// VOD + AES-128: LL mode causes ABR thrash → bufferAppendError on MSE.
|
|
220
221
|
lowLatencyMode: false,
|
|
221
|
-
|
|
222
|
+
// Match a smooth encrypted VOD: 30s forward target, 60s ceiling,
|
|
223
|
+
// 20MB cap, and a short back buffer so MSE does not stall when full.
|
|
224
|
+
backBufferLength: 30,
|
|
225
|
+
maxBufferLength: 30,
|
|
226
|
+
maxMaxBufferLength: 60,
|
|
227
|
+
maxBufferSize: 20 * 1024 * 1024,
|
|
222
228
|
fatalRecoveryLimit: 3
|
|
223
229
|
}
|
|
224
230
|
},
|
|
@@ -636,6 +642,7 @@ var RefreshManager = class {
|
|
|
636
642
|
constructor(options) {
|
|
637
643
|
this.options = options;
|
|
638
644
|
this.timer = null;
|
|
645
|
+
this.intervalTimer = null;
|
|
639
646
|
this.coalesceTimer = null;
|
|
640
647
|
this.inFlight = false;
|
|
641
648
|
this.consecutiveFailures = 0;
|
|
@@ -644,6 +651,7 @@ var RefreshManager = class {
|
|
|
644
651
|
}
|
|
645
652
|
start(initialExpiresAt) {
|
|
646
653
|
this.schedule(initialExpiresAt);
|
|
654
|
+
this.armInterval();
|
|
647
655
|
}
|
|
648
656
|
requestRenew(reason = "frag_error") {
|
|
649
657
|
if (this.stopped || this.options.isDestroyed()) return;
|
|
@@ -659,8 +667,10 @@ var RefreshManager = class {
|
|
|
659
667
|
stop() {
|
|
660
668
|
this.stopped = true;
|
|
661
669
|
if (this.timer) clearTimeout(this.timer);
|
|
670
|
+
if (this.intervalTimer) clearTimeout(this.intervalTimer);
|
|
662
671
|
if (this.coalesceTimer) clearTimeout(this.coalesceTimer);
|
|
663
672
|
this.timer = null;
|
|
673
|
+
this.intervalTimer = null;
|
|
664
674
|
this.coalesceTimer = null;
|
|
665
675
|
}
|
|
666
676
|
schedule(expiresAt) {
|
|
@@ -674,13 +684,25 @@ var RefreshManager = class {
|
|
|
674
684
|
void this.renew("proactive");
|
|
675
685
|
}, delay);
|
|
676
686
|
}
|
|
687
|
+
/** Rotate the token on a fixed cadence. The loader reads the store live. */
|
|
688
|
+
armInterval() {
|
|
689
|
+
const interval = this.options.refreshIntervalMs;
|
|
690
|
+
if (!interval || interval < 5e3 || this.stopped) return;
|
|
691
|
+
if (this.intervalTimer) clearTimeout(this.intervalTimer);
|
|
692
|
+
this.intervalTimer = setTimeout(() => {
|
|
693
|
+
this.intervalTimer = null;
|
|
694
|
+
if (this.stopped) return;
|
|
695
|
+
void this.renew("proactive");
|
|
696
|
+
this.armInterval();
|
|
697
|
+
}, interval);
|
|
698
|
+
}
|
|
677
699
|
async renew(reason) {
|
|
678
700
|
if (this.stopped || this.options.isDestroyed() || this.inFlight) {
|
|
679
701
|
if (this.inFlight) this.pendingReason = reason;
|
|
680
702
|
return;
|
|
681
703
|
}
|
|
682
704
|
this.inFlight = true;
|
|
683
|
-
this.options.onRenewing?.();
|
|
705
|
+
this.options.onRenewing?.(reason);
|
|
684
706
|
try {
|
|
685
707
|
await this.options.authManager.ensureToken({
|
|
686
708
|
reason: reason === "proactive" ? "expiring" : "unauthorized",
|
|
@@ -691,7 +713,7 @@ var RefreshManager = class {
|
|
|
691
713
|
reason: reason === "proactive" ? "expiring" : reason === "manual" ? "manual" : "auth_error"
|
|
692
714
|
});
|
|
693
715
|
this.consecutiveFailures = 0;
|
|
694
|
-
this.options.onRenewed?.(source.expiresAt);
|
|
716
|
+
this.options.onRenewed?.(source.expiresAt, reason);
|
|
695
717
|
this.schedule(source.expiresAt);
|
|
696
718
|
this.options.logger.debug("Playback source renewed", { reason });
|
|
697
719
|
} catch (error) {
|
|
@@ -1357,20 +1379,20 @@ var HlsEngine = class {
|
|
|
1357
1379
|
"Disabling hls.js worker on Firefox to avoid MSE bufferAppendError"
|
|
1358
1380
|
);
|
|
1359
1381
|
}
|
|
1382
|
+
const startPosition = this.options.startPosition;
|
|
1360
1383
|
this.hls = new Hls({
|
|
1361
1384
|
enableWorker,
|
|
1362
1385
|
// LL mode on short encrypted VOD drives aggressive ABR thrash → MSE errors.
|
|
1363
1386
|
lowLatencyMode: hlsConfig.lowLatencyMode,
|
|
1364
1387
|
backBufferLength: hlsConfig.backBufferLength,
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1388
|
+
maxBufferLength: hlsConfig.maxBufferLength,
|
|
1389
|
+
maxMaxBufferLength: hlsConfig.maxMaxBufferLength,
|
|
1390
|
+
maxBufferSize: hlsConfig.maxBufferSize,
|
|
1391
|
+
startPosition: typeof startPosition === "number" && startPosition > 0 ? startPosition : -1,
|
|
1392
|
+
// A first-fragment bandwidth probe on short encrypted VODs truncates
|
|
1393
|
+
// the body and immediately hops levels. ABR itself stays on hls.js
|
|
1394
|
+
// defaults so a long VOD is not held on the lowest rung.
|
|
1368
1395
|
testBandwidth: false,
|
|
1369
|
-
abrEwmaDefaultEstimate: 5e5,
|
|
1370
|
-
abrBandWidthFactor: 0.8,
|
|
1371
|
-
abrBandWidthUpFactor: 0.5,
|
|
1372
|
-
maxStarvationDelay: 4,
|
|
1373
|
-
capLevelToPlayerSize: true,
|
|
1374
1396
|
startLevel: -1,
|
|
1375
1397
|
loader
|
|
1376
1398
|
});
|
|
@@ -1478,35 +1500,35 @@ var HlsEngine = class {
|
|
|
1478
1500
|
}
|
|
1479
1501
|
}
|
|
1480
1502
|
clampStartPosition(raw, videoEl) {
|
|
1481
|
-
|
|
1503
|
+
const t = Math.max(0, raw);
|
|
1482
1504
|
const duration = videoEl.duration;
|
|
1483
1505
|
if (Number.isFinite(duration) && duration > 0) {
|
|
1484
|
-
|
|
1485
|
-
}
|
|
1486
|
-
if (videoEl.seekable.length > 0) {
|
|
1487
|
-
const end = videoEl.seekable.end(videoEl.seekable.length - 1);
|
|
1488
|
-
if (Number.isFinite(end)) {
|
|
1489
|
-
t = Math.min(t, end);
|
|
1490
|
-
}
|
|
1506
|
+
return Math.min(t, Math.max(0, duration - 0.35));
|
|
1491
1507
|
}
|
|
1492
1508
|
return t;
|
|
1493
1509
|
}
|
|
1494
1510
|
async applyStartPositionOnly() {
|
|
1495
1511
|
if (this.destroyed || this.startPositionApplied) return;
|
|
1496
1512
|
const { videoEl, startPosition } = this.options;
|
|
1513
|
+
if (typeof startPosition !== "number" || startPosition <= 0) {
|
|
1514
|
+
this.startPositionApplied = true;
|
|
1515
|
+
return;
|
|
1516
|
+
}
|
|
1517
|
+
const durationKnown = Number.isFinite(videoEl.duration) && videoEl.duration > 0;
|
|
1518
|
+
if (!durationKnown) {
|
|
1519
|
+
videoEl.addEventListener(
|
|
1520
|
+
"loadedmetadata",
|
|
1521
|
+
() => {
|
|
1522
|
+
void this.applyStartPositionOnly();
|
|
1523
|
+
},
|
|
1524
|
+
{ once: true }
|
|
1525
|
+
);
|
|
1526
|
+
return;
|
|
1527
|
+
}
|
|
1497
1528
|
this.startPositionApplied = true;
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
try {
|
|
1502
|
-
videoEl.currentTime = this.clampStartPosition(startPosition, videoEl);
|
|
1503
|
-
} catch {
|
|
1504
|
-
}
|
|
1505
|
-
};
|
|
1506
|
-
if (videoEl.seekable.length > 0 || Number.isFinite(videoEl.duration)) {
|
|
1507
|
-
seek();
|
|
1508
|
-
} else {
|
|
1509
|
-
videoEl.addEventListener("loadedmetadata", seek, { once: true });
|
|
1529
|
+
try {
|
|
1530
|
+
videoEl.currentTime = this.clampStartPosition(startPosition, videoEl);
|
|
1531
|
+
} catch {
|
|
1510
1532
|
}
|
|
1511
1533
|
}
|
|
1512
1534
|
async applyAutoplayOnly() {
|
|
@@ -1567,9 +1589,14 @@ var HlsEngine = class {
|
|
|
1567
1589
|
keyProxyMaxFailures: this.options.keyProxyMaxFailures
|
|
1568
1590
|
});
|
|
1569
1591
|
}
|
|
1570
|
-
|
|
1592
|
+
/**
|
|
1593
|
+
* Auth params are already on the shared store, so the next request uses
|
|
1594
|
+
* the new token. Restart the loader only after a real auth failure.
|
|
1595
|
+
* A proactive refresh must not abort the buffered segments.
|
|
1596
|
+
*/
|
|
1597
|
+
resumeAfterAuthRenew(restart = true) {
|
|
1571
1598
|
this.networkRecoveryCount = 0;
|
|
1572
|
-
this.hls?.startLoad();
|
|
1599
|
+
if (restart) this.hls?.startLoad();
|
|
1573
1600
|
this.updateAuthParams();
|
|
1574
1601
|
}
|
|
1575
1602
|
setQuality(selection) {
|
|
@@ -1955,12 +1982,15 @@ function createVideoPlayer(options) {
|
|
|
1955
1982
|
renewMaxRetries: options.playback.renewMaxRetries ?? 3,
|
|
1956
1983
|
renewBackoffMs: options.playback.renewBackoffMs ?? 2e3,
|
|
1957
1984
|
coalesceMs: options.playback.authRecoveryCoalesceMs ?? 1e3,
|
|
1985
|
+
refreshIntervalMs: options.playback.refreshIntervalMs ?? DEFAULT_PLAYBACK_REFRESH_INTERVAL_MS,
|
|
1958
1986
|
logger,
|
|
1959
1987
|
isDestroyed: () => destroyed,
|
|
1960
|
-
onRenewing: () =>
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1988
|
+
onRenewing: (reason) => {
|
|
1989
|
+
if (reason !== "proactive") setState("renewing");
|
|
1990
|
+
},
|
|
1991
|
+
onRenewed: (nextExpiresAt, reason) => {
|
|
1992
|
+
engine?.resumeAfterAuthRenew(reason !== "proactive");
|
|
1993
|
+
if (reason !== "proactive" && !destroyed) {
|
|
1964
1994
|
const el2 = videoEl;
|
|
1965
1995
|
if (el2 && !el2.paused && !el2.ended) {
|
|
1966
1996
|
setState("playing");
|
|
@@ -2020,8 +2050,13 @@ function createVideoPlayer(options) {
|
|
|
2020
2050
|
},
|
|
2021
2051
|
seek(time) {
|
|
2022
2052
|
const el = ensureVideoElement();
|
|
2023
|
-
const
|
|
2024
|
-
|
|
2053
|
+
const requested = Math.max(0, time);
|
|
2054
|
+
const duration = el.duration;
|
|
2055
|
+
if (Number.isFinite(duration) && duration > 0) {
|
|
2056
|
+
el.currentTime = Math.min(requested, Math.max(0, duration - 0.05));
|
|
2057
|
+
} else {
|
|
2058
|
+
el.currentTime = requested;
|
|
2059
|
+
}
|
|
2025
2060
|
},
|
|
2026
2061
|
goToLive() {
|
|
2027
2062
|
const el = ensureVideoElement();
|
|
@@ -2222,6 +2257,7 @@ export {
|
|
|
2222
2257
|
AuthParamsStore,
|
|
2223
2258
|
DEFAULT_CONTROLS,
|
|
2224
2259
|
DEFAULT_LIVE_EDGE_TOLERANCE_SECONDS,
|
|
2260
|
+
DEFAULT_PLAYBACK_REFRESH_INTERVAL_MS,
|
|
2225
2261
|
DEFAULT_PLAYER_BEHAVIOR,
|
|
2226
2262
|
DEFAULT_PLAYER_CONFIG,
|
|
2227
2263
|
DEFAULT_THEME,
|