@mottosports/motto-video-player 1.0.1-rc.77 → 1.0.1-rc.79

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.mts CHANGED
@@ -200,9 +200,10 @@ interface IconSizes {
200
200
  }
201
201
  interface PlayerProps extends Omit<HTMLAttributes<HTMLVideoElement>, 'src' | 'onError'> {
202
202
  /**
203
- * The source URL of the video (DASH, HLS, or regular MP4) or playlist object with DRM info
203
+ * The source URL of the video (DASH, HLS, or regular MP4) or playlist object with DRM info.
204
+ * Can be a plain URL string or a Playlist object.
204
205
  */
205
- src: Playlist;
206
+ src: Playlist | string;
206
207
  /**
207
208
  * When true, player only reinitializes based on playlist presence rather than src changes.
208
209
  * Used internally by Event, CreativeWork, and Video wrappers to optimize reinitialization.
@@ -352,6 +353,7 @@ interface PlayerProps extends Omit<HTMLAttributes<HTMLVideoElement>, 'src' | 'on
352
353
  auth?: {
353
354
  mottoToken?: string;
354
355
  userId?: string;
356
+ apiToken?: string;
355
357
  };
356
358
  }
357
359
  /**
package/dist/index.d.ts CHANGED
@@ -200,9 +200,10 @@ interface IconSizes {
200
200
  }
201
201
  interface PlayerProps extends Omit<HTMLAttributes<HTMLVideoElement>, 'src' | 'onError'> {
202
202
  /**
203
- * The source URL of the video (DASH, HLS, or regular MP4) or playlist object with DRM info
203
+ * The source URL of the video (DASH, HLS, or regular MP4) or playlist object with DRM info.
204
+ * Can be a plain URL string or a Playlist object.
204
205
  */
205
- src: Playlist;
206
+ src: Playlist | string;
206
207
  /**
207
208
  * When true, player only reinitializes based on playlist presence rather than src changes.
208
209
  * Used internally by Event, CreativeWork, and Video wrappers to optimize reinitialization.
@@ -352,6 +353,7 @@ interface PlayerProps extends Omit<HTMLAttributes<HTMLVideoElement>, 'src' | 'on
352
353
  auth?: {
353
354
  mottoToken?: string;
354
355
  userId?: string;
356
+ apiToken?: string;
355
357
  };
356
358
  }
357
359
  /**
package/dist/index.js CHANGED
@@ -490,7 +490,7 @@ var supportsWidevinePersistentLicenses = () => {
490
490
  var import_mux_data_shakaplayer = __toESM(require("@mux/mux-data-shakaplayer"));
491
491
 
492
492
  // package.json
493
- var version = "1.0.1-rc.77";
493
+ var version = "1.0.1-rc.79";
494
494
 
495
495
  // src/utils/licenseCache.ts
496
496
  var PERSISTENT_LICENSE_PREFIX = "motto_lic_";
@@ -643,6 +643,17 @@ var clearAllPersistentLicenses = () => {
643
643
  };
644
644
 
645
645
  // src/hooks/useShakaPlayer.ts
646
+ var normalizeSource = (src) => {
647
+ if (typeof src === "string") {
648
+ return {
649
+ id: "",
650
+ url: src,
651
+ format: "auto",
652
+ drm: {}
653
+ };
654
+ }
655
+ return src;
656
+ };
646
657
  var useShakaPlayer = ({
647
658
  src,
648
659
  shakaConfig,
@@ -655,7 +666,8 @@ var useShakaPlayer = ({
655
666
  publicKey,
656
667
  mottoToken,
657
668
  hasAds = false,
658
- hasSystem73 = false
669
+ hasSystem73 = false,
670
+ apiToken
659
671
  }) => {
660
672
  const playerRef = (0, import_react.useRef)(null);
661
673
  const [isRetrying, setIsRetrying] = (0, import_react.useState)(false);
@@ -671,16 +683,17 @@ var useShakaPlayer = ({
671
683
  const storedPersistentThisLoadRef = (0, import_react.useRef)(false);
672
684
  const drmExpirationHandlerRef = (0, import_react.useRef)(null);
673
685
  const getManifestUrl = (0, import_react.useCallback)(() => {
674
- let manifestUrl = src.url;
675
- const isDRM = Boolean(src.drm);
686
+ const playlistSrc = normalizeSource(src);
687
+ let manifestUrl = playlistSrc.url;
688
+ const isDRM = Boolean(playlistSrc.drm?.widevine || playlistSrc.drm?.fairplay || playlistSrc.drm?.playready);
676
689
  if (isDRM) {
677
690
  const isPlayReady = isPlayReadySupported();
678
- if (isAppleDevice() && src.drm.fairplay?.certificateUrl) {
679
- manifestUrl = src.drm.fairplay.playlistUrl;
680
- } else if (isPlayReady && src.drm.playready?.licenseUrl) {
681
- manifestUrl = src.drm.playready.playlistUrl;
691
+ if (isAppleDevice() && playlistSrc.drm?.fairplay?.certificateUrl) {
692
+ manifestUrl = playlistSrc.drm.fairplay.playlistUrl;
693
+ } else if (isPlayReady && playlistSrc.drm?.playready?.licenseUrl) {
694
+ manifestUrl = playlistSrc.drm.playready.playlistUrl;
682
695
  } else {
683
- manifestUrl = src.drm?.widevine?.playlistUrl || "";
696
+ manifestUrl = playlistSrc.drm?.widevine?.playlistUrl || "";
684
697
  }
685
698
  }
686
699
  return manifestUrl;
@@ -725,9 +738,10 @@ var useShakaPlayer = ({
725
738
  if (shakaConfig) {
726
739
  player.configure(shakaConfig);
727
740
  }
741
+ const playlistSrc = normalizeSource(src);
728
742
  const manifestUrl = getManifestUrl();
729
- let playlistId = src.id;
730
- const isDRM = Boolean(src.drm);
743
+ let playlistId = playlistSrc.id;
744
+ const isDRM = Boolean(playlistSrc.drm?.widevine || playlistSrc.drm?.fairplay || playlistSrc.drm?.playready);
731
745
  storedPersistentThisLoadRef.current = false;
732
746
  if (activeInitIdRef.current !== myInitId || isDestroyingRef.current) {
733
747
  try {
@@ -739,23 +753,23 @@ var useShakaPlayer = ({
739
753
  }
740
754
  let storedSessionsMetadata = [];
741
755
  if (isDRM && playlistId) {
742
- storedSessionsMetadata = retrievePersistentLicense(playlistId, src.drm.licenseCacheKey ?? "");
756
+ storedSessionsMetadata = retrievePersistentLicense(playlistId, playlistSrc.drm?.licenseCacheKey ?? "");
743
757
  }
744
758
  if (isDRM) {
745
759
  const drmConfig2 = {
746
760
  servers: {
747
- "com.widevine.alpha": src.drm.widevine?.licenseUrl,
748
- "com.microsoft.playready": src.drm.playready?.licenseUrl,
749
- "com.apple.fps": src.drm.fairplay?.licenseUrl
761
+ "com.widevine.alpha": playlistSrc.drm?.widevine?.licenseUrl,
762
+ "com.microsoft.playready": playlistSrc.drm?.playready?.licenseUrl,
763
+ "com.apple.fps": playlistSrc.drm?.fairplay?.licenseUrl
750
764
  },
751
765
  keySystemsMapping: {
752
- // Fall back or reroute to the platforms recommended PlayReady CDM if needed
766
+ // Fall back or reroute to the platform's recommended PlayReady CDM if needed
753
767
  "com.microsoft.playready": "com.microsoft.playready.recommendation"
754
768
  },
755
- ...src.drm.fairplay && {
769
+ ...playlistSrc.drm?.fairplay && {
756
770
  advanced: {
757
771
  "com.apple.fps": {
758
- serverCertificateUri: src.drm.fairplay.certificateUrl
772
+ serverCertificateUri: playlistSrc.drm.fairplay.certificateUrl
759
773
  }
760
774
  }
761
775
  }
@@ -860,6 +874,16 @@ var useShakaPlayer = ({
860
874
  });
861
875
  }
862
876
  }
877
+ if (apiToken) {
878
+ const netEngine = player.getNetworkingEngine();
879
+ if (netEngine) {
880
+ netEngine.registerRequestFilter((type, request) => {
881
+ if (type === import_shaka_player.default.net.NetworkingEngine.RequestType.MANIFEST) {
882
+ request.headers["authorization"] = `Bearer ${apiToken}`;
883
+ }
884
+ });
885
+ }
886
+ }
863
887
  if (isDRM && playlistId) {
864
888
  const onDRMSessionUpdate = () => {
865
889
  try {
@@ -876,7 +900,7 @@ var useShakaPlayer = ({
876
900
  initDataType: session.initDataType,
877
901
  keySystem: session.keySystem || "com.widevine.alpha"
878
902
  }));
879
- storePersistentLicense(playlistId, src.drm.licenseCacheKey ?? "", sessionsToStore);
903
+ storePersistentLicense(playlistId, playlistSrc.drm?.licenseCacheKey ?? "", sessionsToStore);
880
904
  storedPersistentThisLoadRef.current = true;
881
905
  }
882
906
  } catch (e) {
@@ -977,7 +1001,7 @@ var useShakaPlayer = ({
977
1001
  onError?.(error);
978
1002
  throw error;
979
1003
  }
980
- }, [shakaConfig, drmConfig, src, onError, onPlayerReady, muxConfig, onMuxReady, isRetrying, getManifestUrl]);
1004
+ }, [shakaConfig, drmConfig, src, onError, onPlayerReady, muxConfig, onMuxReady, isRetrying, getManifestUrl, apiToken]);
981
1005
  const initializePlayer = (0, import_react.useCallback)(async (video) => {
982
1006
  return initializePlayerInternal(video);
983
1007
  }, [initializePlayerInternal]);
@@ -2248,7 +2272,7 @@ var Player = (0, import_react13.forwardRef)(
2248
2272
  const [isScriptsLoaded, setIsScriptsLoaded] = (0, import_react13.useState)(false);
2249
2273
  const [isInitialLoading, setIsInitialLoading] = (0, import_react13.useState)(true);
2250
2274
  const [bfResetKey, setBfResetKey] = (0, import_react13.useState)(0);
2251
- const hasPlaylist = !!src && !!(src.url || src.drm?.widevine?.playlistUrl || src.drm?.playready?.playlistUrl || src.drm?.fairplay?.playlistUrl);
2275
+ const hasPlaylist = !!src && (typeof src === "string" || !!(src.url || src.drm?.widevine?.playlistUrl || src.drm?.playready?.playlistUrl || src.drm?.fairplay?.playlistUrl));
2252
2276
  (0, import_react13.useImperativeHandle)(ref, () => videoRef.current, []);
2253
2277
  const { playerRef, initializePlayer, loadManifest, destroyPlayer, isRetrying } = useShakaPlayer({
2254
2278
  src,
@@ -2262,7 +2286,8 @@ var Player = (0, import_react13.forwardRef)(
2262
2286
  publicKey,
2263
2287
  mottoToken: auth?.mottoToken,
2264
2288
  hasAds: !!imaConfig?.adTagUrl,
2265
- hasSystem73: !!system73Config?.apiKey
2289
+ hasSystem73: !!system73Config?.apiKey,
2290
+ apiToken: auth?.apiToken
2266
2291
  });
2267
2292
  const {
2268
2293
  initializeMux,