@codenkay/video-nsgplayer-core 2.0.0 → 3.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
@@ -279,7 +279,7 @@ type PlayerEventMap = {
279
279
  };
280
280
 
281
281
  declare const PLAYBACK_RATES: readonly [0.5, 0.75, 1, 1.25, 1.5, 2];
282
- declare const PACKAGE_VERSION = "0.1.8";
282
+ declare const PACKAGE_VERSION = "2.0.1";
283
283
  declare const DEFAULT_PLAYER_BEHAVIOR: Required<PlayerBehaviorConfig>;
284
284
  declare const DEFAULT_CONTROLS: Required<ControlsConfig>;
285
285
  declare const DEFAULT_THEME: Required<ThemeConfig>;
package/dist/index.d.ts CHANGED
@@ -279,7 +279,7 @@ type PlayerEventMap = {
279
279
  };
280
280
 
281
281
  declare const PLAYBACK_RATES: readonly [0.5, 0.75, 1, 1.25, 1.5, 2];
282
- declare const PACKAGE_VERSION = "0.1.8";
282
+ declare const PACKAGE_VERSION = "2.0.1";
283
283
  declare const DEFAULT_PLAYER_BEHAVIOR: Required<PlayerBehaviorConfig>;
284
284
  declare const DEFAULT_CONTROLS: Required<ControlsConfig>;
285
285
  declare const DEFAULT_THEME: Required<ThemeConfig>;
package/dist/index.js CHANGED
@@ -146,7 +146,7 @@ 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 PACKAGE_VERSION = "0.1.8";
149
+ var PACKAGE_VERSION = "2.0.1";
150
150
  var DEFAULT_PLAYER_BEHAVIOR = {
151
151
  autoplay: true,
152
152
  startMuted: true,
@@ -915,9 +915,48 @@ function createAuthParamsLoader(HlsClass, store, options = {}) {
915
915
  const usingKeyProxy = Boolean(
916
916
  isKey && options.keyProxyUrlBuilder && options.videoId
917
917
  );
918
+ const signedKeyUrl = isKey ? rewriteHlsRequestUrl(originalUrl, store, {
919
+ ...options,
920
+ keyProxyUrlBuilder: void 0
921
+ }) : context.url;
918
922
  context.url = rewriteHlsRequestUrl(originalUrl, store, options);
919
923
  if (usingKeyProxy) {
920
- this.inner.load(context, config, callbacks);
924
+ const accessToken = options.getKeyAccessToken?.() ?? null;
925
+ if (!accessToken) {
926
+ this.inner.load(context, config, callbacks);
927
+ return;
928
+ }
929
+ const proxyCallbacks = {
930
+ ...callbacks,
931
+ onError: (error, errContext, networkDetails, stats) => {
932
+ const code = error?.code;
933
+ const retryable = code === 0 || code === 502 || code === 403 || code === 401 || /Cloudflare|HTML|DOCTYPE|blocked/i.test(error?.text ?? "");
934
+ if (!retryable) {
935
+ callbacks.onError(error, errContext, networkDetails, stats);
936
+ return;
937
+ }
938
+ this.keyAbort?.abort();
939
+ this.keyAbort = new AbortController();
940
+ const bearerContext = { ...context, url: signedKeyUrl };
941
+ void loadEncryptionKeyWithFetch(
942
+ bearerContext,
943
+ callbacks,
944
+ accessToken,
945
+ this.keyAbort.signal
946
+ ).catch((fetchError) => {
947
+ callbacks.onError(
948
+ {
949
+ code: 0,
950
+ text: fetchError instanceof Error ? fetchError.message : error.text || "enc.key proxy and Bearer fetch failed"
951
+ },
952
+ bearerContext,
953
+ null,
954
+ stats
955
+ );
956
+ });
957
+ }
958
+ };
959
+ this.inner.load(context, config, proxyCallbacks);
921
960
  return;
922
961
  }
923
962
  if (isKey && typeof options.getKeyAccessToken === "function") {
@@ -935,6 +974,10 @@ function createAuthParamsLoader(HlsClass, store, options = {}) {
935
974
  ).catch((error) => {
936
975
  const stats = createLoaderStats();
937
976
  const aborted = error instanceof DOMException && error.name === "AbortError";
977
+ if (!aborted && (error instanceof TypeError || error instanceof Error && /Failed to fetch|NetworkError|CORS/i.test(error.message))) {
978
+ this.inner.load(context, config, callbacks);
979
+ return;
980
+ }
938
981
  callbacks.onError(
939
982
  {
940
983
  code: 0,
@@ -1443,12 +1486,11 @@ function createVideoPlayer(options) {
1443
1486
  volume: config.player.volume,
1444
1487
  videoId: options.videoId,
1445
1488
  keyProxyUrlBuilder: config.streaming.keyProxyUrlBuilder,
1446
- // Optional: browser Bearer for Video API–origin enc.key (CORS-dependent).
1447
- // CDN keys use signed query via the auth loader (no Bearer) — same as
1448
- // segments. Apps can pass getKeyAccessToken or rely on keyProxyUrlBuilder.
1449
- // When unset, defaults to AuthManager token only if explicitly requested
1450
- // via streaming.getKeyAccessToken; otherwise query-signed XHR.
1451
- getKeyAccessToken: config.streaming.getKeyAccessToken,
1489
+ // Enterprise AES key auth:
1490
+ // 1) keyProxyUrlBuilder (same-origin BFF) when configured
1491
+ // 2) else getKeyAccessToken / AuthManager Bearer via browser fetch
1492
+ // 3) else signed query + XHR (CDN hosts)
1493
+ getKeyAccessToken: config.streaming.getKeyAccessToken ?? (() => authManager.getAccessToken()),
1452
1494
  hlsConfig: config.streaming.hls,
1453
1495
  logger,
1454
1496
  callbacks: {
@@ -1766,7 +1808,7 @@ function createVideoPlayer(options) {
1766
1808
  engine: "hls",
1767
1809
  hls: { ...config.streaming.hls, ...partial?.streaming?.hls },
1768
1810
  keyProxyUrlBuilder: partial?.streaming?.keyProxyUrlBuilder ?? config.streaming.keyProxyUrlBuilder,
1769
- getKeyAccessToken: partial?.streaming?.getKeyAccessToken ?? config.streaming.getKeyAccessToken
1811
+ getKeyAccessToken: partial?.streaming?.getKeyAccessToken ?? config.streaming.getKeyAccessToken ?? (() => authManager.getAccessToken())
1770
1812
  },
1771
1813
  logging: { ...config.logging, ...partial?.logging },
1772
1814
  debug: { ...config.debug, ...partial?.debug },