@codenkay/video-nsgplayer-core 0.1.3 → 1.0.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/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import Hls, { LoaderContext, LoaderConfiguration, LoaderCallbacks } from 'hls.js';
1
+ import Hls, { LoaderStats, LoaderContext, LoaderConfiguration, LoaderCallbacks } from 'hls.js';
2
2
 
3
3
  /** Player lifecycle states. */
4
4
  type PlayerState = "idle" | "loading" | "ready" | "playing" | "paused" | "buffering" | "renewing" | "ended" | "error" | "destroyed";
@@ -117,12 +117,24 @@ type StreamingConfig = {
117
117
  backBufferLength?: number;
118
118
  fatalRecoveryLimit?: number;
119
119
  };
120
+ /**
121
+ * Same-origin BFF proxy for `enc.key` (preferred in production when the
122
+ * server IP is allowlisted by the CDN / Cloudflare).
123
+ */
120
124
  keyProxyUrlBuilder?: (ctx: {
121
125
  videoId: string;
122
126
  keyUrl: string;
123
127
  token?: string;
124
128
  expires?: string;
129
+ username?: string;
130
+ mobile?: string;
125
131
  }) => string;
132
+ /**
133
+ * Browser-direct AES key auth: returns the Video API access token so hls.js
134
+ * can send `Authorization: Bearer …` on `enc.key` requests.
135
+ * Use when the BFF cannot reach Appextech (Cloudflare challenge on server IP).
136
+ */
137
+ getKeyAccessToken?: () => string | null | undefined;
126
138
  };
127
139
  type LoggingConfig = {
128
140
  enabled?: boolean;
@@ -169,6 +181,7 @@ type PlayerConfig = Required<{
169
181
  engine: "hls";
170
182
  hls: Required<NonNullable<StreamingConfig["hls"]>>;
171
183
  keyProxyUrlBuilder?: StreamingConfig["keyProxyUrlBuilder"];
184
+ getKeyAccessToken?: StreamingConfig["getKeyAccessToken"];
172
185
  };
173
186
  logging: Required<LoggingConfig>;
174
187
  debug: Required<DebugConfig>;
@@ -242,7 +255,7 @@ type PlayerEventMap = {
242
255
  };
243
256
 
244
257
  declare const PLAYBACK_RATES: readonly [0.5, 0.75, 1, 1.25, 1.5, 2];
245
- declare const PACKAGE_VERSION = "0.1.3";
258
+ declare const PACKAGE_VERSION = "0.1.8";
246
259
  declare const DEFAULT_PLAYER_BEHAVIOR: Required<PlayerBehaviorConfig>;
247
260
  declare const DEFAULT_CONTROLS: Required<ControlsConfig>;
248
261
  declare const DEFAULT_THEME: Required<ThemeConfig>;
@@ -274,6 +287,7 @@ type PlayerConfigPartial = Partial<{
274
287
  engine?: "hls";
275
288
  hls?: Partial<PlayerConfig["streaming"]["hls"]>;
276
289
  keyProxyUrlBuilder?: PlayerConfig["streaming"]["keyProxyUrlBuilder"];
290
+ getKeyAccessToken?: PlayerConfig["streaming"]["getKeyAccessToken"];
277
291
  };
278
292
  logging: Partial<PlayerConfig["logging"]>;
279
293
  debug: Partial<PlayerConfig["debug"]>;
@@ -388,6 +402,7 @@ type HlsEngineOptions = {
388
402
  volume?: number;
389
403
  videoId?: string;
390
404
  keyProxyUrlBuilder?: StreamingConfig["keyProxyUrlBuilder"];
405
+ getKeyAccessToken?: StreamingConfig["getKeyAccessToken"];
391
406
  hlsConfig: {
392
407
  enableWorker: boolean;
393
408
  lowLatencyMode: boolean;
@@ -400,10 +415,12 @@ type HlsEngineOptions = {
400
415
  /**
401
416
  * Dual-path HLS engine: hls.js when supported, otherwise native Safari HLS.
402
417
  *
403
- * Signed CDN playback requires auth query params on *every* HLS request
404
- * (master, media playlist, segments, keys). hls.js only receives the signed
405
- * master URL via loadSource; child URIs are relative and unsigned unless a
406
- * custom loader re-applies AuthParamsStore on each request.
418
+ * Signed CDN playback requires auth query params on every HLS request
419
+ * (playlists, segments, and AES `enc.key` on CDN hosts).
420
+ *
421
+ * Optional `streaming.keyProxyUrlBuilder` (same-origin BFF) or
422
+ * `streaming.getKeyAccessToken` (browser Bearer) for Video API–origin keys
423
+ * when query-signed CDN access is insufficient.
407
424
  */
408
425
  declare class HlsEngine {
409
426
  private readonly options;
@@ -417,6 +434,8 @@ declare class HlsEngine {
417
434
  constructor(options: HlsEngineOptions);
418
435
  start(): Promise<void>;
419
436
  private startWithHlsJs;
437
+ private handleHlsError;
438
+ private applyStartPositionAndAutoplay;
420
439
  private bindMediaEvents;
421
440
  updateAuthParams(): void;
422
441
  resumeAfterAuthRenew(): void;
@@ -575,27 +594,52 @@ declare class RefreshManager {
575
594
  private renew;
576
595
  }
577
596
 
578
- type HlsLoader = new (config: object) => {
597
+ type HlsLoaderInstance = {
598
+ stats: LoaderStats;
579
599
  load(context: LoaderContext, config: LoaderConfiguration, callbacks: LoaderCallbacks<LoaderContext>): void;
580
600
  destroy(): void;
601
+ abort?: () => void;
581
602
  };
603
+ type HlsLoader = new (config: object) => HlsLoaderInstance;
582
604
  type AuthParamsLoaderOptions = {
583
605
  videoId?: string;
584
606
  keyProxyUrlBuilder?: StreamingConfig["keyProxyUrlBuilder"];
607
+ getKeyAccessToken?: StreamingConfig["getKeyAccessToken"];
585
608
  };
609
+ declare function isEncryptionKeyUrl(rawUrl: string, baseOrigin?: string): boolean;
610
+ /**
611
+ * Always resolve a builtin hls.js loader (XhrLoader).
612
+ *
613
+ * Never trust `Hls.DefaultConfig.loader` alone — if it was reassigned to a
614
+ * custom wrapper, `extends` / nested `inner.load()` chains blow Firefox's
615
+ * stack (`InternalError: too much recursion`).
616
+ */
617
+ declare function resolveBuiltinHlsLoader(HlsClass: typeof Hls): HlsLoader;
586
618
  /**
587
619
  * Rewrites an HLS request URL so signed auth query params are present.
588
- * Master playlists are signed on loadSource; child playlists / segments / keys
589
- * are relative and would otherwise be fetched unsigned → CDN 403.
620
+ *
621
+ * AES `enc.key` handling (enterprise priority order):
622
+ * 1. `keyProxyUrlBuilder` — same-origin BFF (production; server IP must pass CDN/WAF)
623
+ * 2. Otherwise keep CDN/API URL and apply signed `token`/`expires` (and related) query
624
+ * params — same auth model as segments on Appextech CDN hosts
625
+ * 3. Optional `getKeyAccessToken` is applied at load-time (Bearer), not in this rewrite
590
626
  */
591
627
  declare function rewriteHlsRequestUrl(rawUrl: string, store: AuthParamsStore, options?: AuthParamsLoaderOptions, baseOrigin?: string): string;
592
628
  /**
593
- * hls.js loader that re-applies live AuthParamsStore credentials on every
594
- * manifest / level / fragment / key request.
629
+ * hls.js loader that:
630
+ * - Re-applies signed auth query params on every media request
631
+ * - Loads AES `enc.key` via BFF / optional Bearer fetch / signed-query XHR
632
+ *
633
+ * Uses composition (not `extends DefaultConfig.loader`) so repeated mounts,
634
+ * HMR, or a polluted DefaultConfig cannot nest `super.load()` into recursion.
595
635
  */
596
636
  declare function createAuthParamsLoader(HlsClass: typeof Hls, store: AuthParamsStore, options?: AuthParamsLoaderOptions): HlsLoader;
597
637
 
598
638
  declare function redactValue(key: string, value: unknown, seen?: WeakSet<object>, depth?: number): unknown;
639
+ /**
640
+ * Redacts sensitive fields. Cycle-safe and depth-capped.
641
+ * Only walks plain objects/arrays — never DOM / host graphs.
642
+ */
599
643
  declare function redactObject(obj: Record<string, unknown>, seen?: WeakSet<object>, depth?: number): Record<string, unknown>;
600
644
 
601
- 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 HlsQualityLevel, type HlsSupportMode, type LiveMediaSnapshot, type LoggingConfig, PACKAGE_VERSION, PLAYBACK_RATES, type PlayIconPreset, type PlaybackCredentialConfig, type PlaybackRate, type PlaybackSource, type PlaybackSourceContext, PlaybackSourceManager, type PlayerBehaviorConfig, type PlayerConfig, type PlayerDiagnostics, type PlayerError, PlayerErrorCode, type PlayerEventMap, type PlayerSkipSeconds, type PlayerState, type PlayerZoomLevel, type QualitySelection, RefreshManager, SECRET_SCAN_MAX_DEPTH, type SeekToLiveResult, type StreamingConfig, type ThemeConfig, type VideoPlayer, type WatermarkConfig, assertNoSecretsInConfig, createAuthParamsLoader, createPlayerError, createVideoPlayer, getLiveEdgeTime, isAtLiveEdge, isPlainObject, mergePlayerConfig, redactObject, redactSensitive, redactValue, rewriteHlsRequestUrl, seekToLiveEdge, themeToCssVars };
645
+ 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 HlsQualityLevel, type HlsSupportMode, type LiveMediaSnapshot, type LoggingConfig, PACKAGE_VERSION, PLAYBACK_RATES, type PlayIconPreset, type PlaybackCredentialConfig, type PlaybackRate, type PlaybackSource, type PlaybackSourceContext, PlaybackSourceManager, type PlayerBehaviorConfig, type PlayerConfig, type PlayerDiagnostics, type PlayerError, PlayerErrorCode, type PlayerEventMap, type PlayerSkipSeconds, type PlayerState, type PlayerZoomLevel, type QualitySelection, RefreshManager, SECRET_SCAN_MAX_DEPTH, type SeekToLiveResult, type StreamingConfig, type ThemeConfig, type VideoPlayer, type WatermarkConfig, assertNoSecretsInConfig, createAuthParamsLoader, createPlayerError, createVideoPlayer, getLiveEdgeTime, isAtLiveEdge, isEncryptionKeyUrl, isPlainObject, mergePlayerConfig, redactObject, redactSensitive, redactValue, resolveBuiltinHlsLoader, rewriteHlsRequestUrl, seekToLiveEdge, themeToCssVars };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import Hls, { LoaderContext, LoaderConfiguration, LoaderCallbacks } from 'hls.js';
1
+ import Hls, { LoaderStats, LoaderContext, LoaderConfiguration, LoaderCallbacks } from 'hls.js';
2
2
 
3
3
  /** Player lifecycle states. */
4
4
  type PlayerState = "idle" | "loading" | "ready" | "playing" | "paused" | "buffering" | "renewing" | "ended" | "error" | "destroyed";
@@ -117,12 +117,24 @@ type StreamingConfig = {
117
117
  backBufferLength?: number;
118
118
  fatalRecoveryLimit?: number;
119
119
  };
120
+ /**
121
+ * Same-origin BFF proxy for `enc.key` (preferred in production when the
122
+ * server IP is allowlisted by the CDN / Cloudflare).
123
+ */
120
124
  keyProxyUrlBuilder?: (ctx: {
121
125
  videoId: string;
122
126
  keyUrl: string;
123
127
  token?: string;
124
128
  expires?: string;
129
+ username?: string;
130
+ mobile?: string;
125
131
  }) => string;
132
+ /**
133
+ * Browser-direct AES key auth: returns the Video API access token so hls.js
134
+ * can send `Authorization: Bearer …` on `enc.key` requests.
135
+ * Use when the BFF cannot reach Appextech (Cloudflare challenge on server IP).
136
+ */
137
+ getKeyAccessToken?: () => string | null | undefined;
126
138
  };
127
139
  type LoggingConfig = {
128
140
  enabled?: boolean;
@@ -169,6 +181,7 @@ type PlayerConfig = Required<{
169
181
  engine: "hls";
170
182
  hls: Required<NonNullable<StreamingConfig["hls"]>>;
171
183
  keyProxyUrlBuilder?: StreamingConfig["keyProxyUrlBuilder"];
184
+ getKeyAccessToken?: StreamingConfig["getKeyAccessToken"];
172
185
  };
173
186
  logging: Required<LoggingConfig>;
174
187
  debug: Required<DebugConfig>;
@@ -242,7 +255,7 @@ type PlayerEventMap = {
242
255
  };
243
256
 
244
257
  declare const PLAYBACK_RATES: readonly [0.5, 0.75, 1, 1.25, 1.5, 2];
245
- declare const PACKAGE_VERSION = "0.1.3";
258
+ declare const PACKAGE_VERSION = "0.1.8";
246
259
  declare const DEFAULT_PLAYER_BEHAVIOR: Required<PlayerBehaviorConfig>;
247
260
  declare const DEFAULT_CONTROLS: Required<ControlsConfig>;
248
261
  declare const DEFAULT_THEME: Required<ThemeConfig>;
@@ -274,6 +287,7 @@ type PlayerConfigPartial = Partial<{
274
287
  engine?: "hls";
275
288
  hls?: Partial<PlayerConfig["streaming"]["hls"]>;
276
289
  keyProxyUrlBuilder?: PlayerConfig["streaming"]["keyProxyUrlBuilder"];
290
+ getKeyAccessToken?: PlayerConfig["streaming"]["getKeyAccessToken"];
277
291
  };
278
292
  logging: Partial<PlayerConfig["logging"]>;
279
293
  debug: Partial<PlayerConfig["debug"]>;
@@ -388,6 +402,7 @@ type HlsEngineOptions = {
388
402
  volume?: number;
389
403
  videoId?: string;
390
404
  keyProxyUrlBuilder?: StreamingConfig["keyProxyUrlBuilder"];
405
+ getKeyAccessToken?: StreamingConfig["getKeyAccessToken"];
391
406
  hlsConfig: {
392
407
  enableWorker: boolean;
393
408
  lowLatencyMode: boolean;
@@ -400,10 +415,12 @@ type HlsEngineOptions = {
400
415
  /**
401
416
  * Dual-path HLS engine: hls.js when supported, otherwise native Safari HLS.
402
417
  *
403
- * Signed CDN playback requires auth query params on *every* HLS request
404
- * (master, media playlist, segments, keys). hls.js only receives the signed
405
- * master URL via loadSource; child URIs are relative and unsigned unless a
406
- * custom loader re-applies AuthParamsStore on each request.
418
+ * Signed CDN playback requires auth query params on every HLS request
419
+ * (playlists, segments, and AES `enc.key` on CDN hosts).
420
+ *
421
+ * Optional `streaming.keyProxyUrlBuilder` (same-origin BFF) or
422
+ * `streaming.getKeyAccessToken` (browser Bearer) for Video API–origin keys
423
+ * when query-signed CDN access is insufficient.
407
424
  */
408
425
  declare class HlsEngine {
409
426
  private readonly options;
@@ -417,6 +434,8 @@ declare class HlsEngine {
417
434
  constructor(options: HlsEngineOptions);
418
435
  start(): Promise<void>;
419
436
  private startWithHlsJs;
437
+ private handleHlsError;
438
+ private applyStartPositionAndAutoplay;
420
439
  private bindMediaEvents;
421
440
  updateAuthParams(): void;
422
441
  resumeAfterAuthRenew(): void;
@@ -575,27 +594,52 @@ declare class RefreshManager {
575
594
  private renew;
576
595
  }
577
596
 
578
- type HlsLoader = new (config: object) => {
597
+ type HlsLoaderInstance = {
598
+ stats: LoaderStats;
579
599
  load(context: LoaderContext, config: LoaderConfiguration, callbacks: LoaderCallbacks<LoaderContext>): void;
580
600
  destroy(): void;
601
+ abort?: () => void;
581
602
  };
603
+ type HlsLoader = new (config: object) => HlsLoaderInstance;
582
604
  type AuthParamsLoaderOptions = {
583
605
  videoId?: string;
584
606
  keyProxyUrlBuilder?: StreamingConfig["keyProxyUrlBuilder"];
607
+ getKeyAccessToken?: StreamingConfig["getKeyAccessToken"];
585
608
  };
609
+ declare function isEncryptionKeyUrl(rawUrl: string, baseOrigin?: string): boolean;
610
+ /**
611
+ * Always resolve a builtin hls.js loader (XhrLoader).
612
+ *
613
+ * Never trust `Hls.DefaultConfig.loader` alone — if it was reassigned to a
614
+ * custom wrapper, `extends` / nested `inner.load()` chains blow Firefox's
615
+ * stack (`InternalError: too much recursion`).
616
+ */
617
+ declare function resolveBuiltinHlsLoader(HlsClass: typeof Hls): HlsLoader;
586
618
  /**
587
619
  * Rewrites an HLS request URL so signed auth query params are present.
588
- * Master playlists are signed on loadSource; child playlists / segments / keys
589
- * are relative and would otherwise be fetched unsigned → CDN 403.
620
+ *
621
+ * AES `enc.key` handling (enterprise priority order):
622
+ * 1. `keyProxyUrlBuilder` — same-origin BFF (production; server IP must pass CDN/WAF)
623
+ * 2. Otherwise keep CDN/API URL and apply signed `token`/`expires` (and related) query
624
+ * params — same auth model as segments on Appextech CDN hosts
625
+ * 3. Optional `getKeyAccessToken` is applied at load-time (Bearer), not in this rewrite
590
626
  */
591
627
  declare function rewriteHlsRequestUrl(rawUrl: string, store: AuthParamsStore, options?: AuthParamsLoaderOptions, baseOrigin?: string): string;
592
628
  /**
593
- * hls.js loader that re-applies live AuthParamsStore credentials on every
594
- * manifest / level / fragment / key request.
629
+ * hls.js loader that:
630
+ * - Re-applies signed auth query params on every media request
631
+ * - Loads AES `enc.key` via BFF / optional Bearer fetch / signed-query XHR
632
+ *
633
+ * Uses composition (not `extends DefaultConfig.loader`) so repeated mounts,
634
+ * HMR, or a polluted DefaultConfig cannot nest `super.load()` into recursion.
595
635
  */
596
636
  declare function createAuthParamsLoader(HlsClass: typeof Hls, store: AuthParamsStore, options?: AuthParamsLoaderOptions): HlsLoader;
597
637
 
598
638
  declare function redactValue(key: string, value: unknown, seen?: WeakSet<object>, depth?: number): unknown;
639
+ /**
640
+ * Redacts sensitive fields. Cycle-safe and depth-capped.
641
+ * Only walks plain objects/arrays — never DOM / host graphs.
642
+ */
599
643
  declare function redactObject(obj: Record<string, unknown>, seen?: WeakSet<object>, depth?: number): Record<string, unknown>;
600
644
 
601
- 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 HlsQualityLevel, type HlsSupportMode, type LiveMediaSnapshot, type LoggingConfig, PACKAGE_VERSION, PLAYBACK_RATES, type PlayIconPreset, type PlaybackCredentialConfig, type PlaybackRate, type PlaybackSource, type PlaybackSourceContext, PlaybackSourceManager, type PlayerBehaviorConfig, type PlayerConfig, type PlayerDiagnostics, type PlayerError, PlayerErrorCode, type PlayerEventMap, type PlayerSkipSeconds, type PlayerState, type PlayerZoomLevel, type QualitySelection, RefreshManager, SECRET_SCAN_MAX_DEPTH, type SeekToLiveResult, type StreamingConfig, type ThemeConfig, type VideoPlayer, type WatermarkConfig, assertNoSecretsInConfig, createAuthParamsLoader, createPlayerError, createVideoPlayer, getLiveEdgeTime, isAtLiveEdge, isPlainObject, mergePlayerConfig, redactObject, redactSensitive, redactValue, rewriteHlsRequestUrl, seekToLiveEdge, themeToCssVars };
645
+ 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 HlsQualityLevel, type HlsSupportMode, type LiveMediaSnapshot, type LoggingConfig, PACKAGE_VERSION, PLAYBACK_RATES, type PlayIconPreset, type PlaybackCredentialConfig, type PlaybackRate, type PlaybackSource, type PlaybackSourceContext, PlaybackSourceManager, type PlayerBehaviorConfig, type PlayerConfig, type PlayerDiagnostics, type PlayerError, PlayerErrorCode, type PlayerEventMap, type PlayerSkipSeconds, type PlayerState, type PlayerZoomLevel, type QualitySelection, RefreshManager, SECRET_SCAN_MAX_DEPTH, type SeekToLiveResult, type StreamingConfig, type ThemeConfig, type VideoPlayer, type WatermarkConfig, assertNoSecretsInConfig, createAuthParamsLoader, createPlayerError, createVideoPlayer, getLiveEdgeTime, isAtLiveEdge, isEncryptionKeyUrl, isPlainObject, mergePlayerConfig, redactObject, redactSensitive, redactValue, resolveBuiltinHlsLoader, rewriteHlsRequestUrl, seekToLiveEdge, themeToCssVars };