@mottosports/motto-video-player 1.0.1-rc.64 → 1.0.1-rc.66

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
@@ -314,6 +314,17 @@ interface PlayerProps extends Omit<HTMLAttributes<HTMLVideoElement>, 'src' | 'on
314
314
  */
315
315
  locale?: string;
316
316
  containerClassName?: string;
317
+ /**
318
+ * Motto public key used for authenticated requests
319
+ */
320
+ publicKey?: string;
321
+ /**
322
+ * Authentication context for player operations
323
+ */
324
+ auth?: {
325
+ mottoToken?: string;
326
+ userId?: string;
327
+ };
317
328
  }
318
329
  /**
319
330
  * Mux Analytics type definitions
package/dist/index.d.ts CHANGED
@@ -314,6 +314,17 @@ interface PlayerProps extends Omit<HTMLAttributes<HTMLVideoElement>, 'src' | 'on
314
314
  */
315
315
  locale?: string;
316
316
  containerClassName?: string;
317
+ /**
318
+ * Motto public key used for authenticated requests
319
+ */
320
+ publicKey?: string;
321
+ /**
322
+ * Authentication context for player operations
323
+ */
324
+ auth?: {
325
+ mottoToken?: string;
326
+ userId?: string;
327
+ };
317
328
  }
318
329
  /**
319
330
  * Mux Analytics type definitions
package/dist/index.js CHANGED
@@ -1226,7 +1226,7 @@ var supportsWidevinePersistentLicenses = () => {
1226
1226
  var import_mux_data_shakaplayer = __toESM(require("@mux/mux-data-shakaplayer"));
1227
1227
 
1228
1228
  // package.json
1229
- var version = "1.0.1-rc.64";
1229
+ var version = "1.0.1-rc.66";
1230
1230
 
1231
1231
  // src/utils/licenseCache.ts
1232
1232
  var PERSISTENT_LICENSE_PREFIX = "motto_lic_";
@@ -1387,11 +1387,17 @@ var useShakaPlayer = ({
1387
1387
  onPlayerReady,
1388
1388
  muxConfig,
1389
1389
  onMuxReady,
1390
- onMuxDataUpdate
1390
+ onMuxDataUpdate,
1391
+ publicKey,
1392
+ mottoToken
1391
1393
  }) => {
1392
1394
  const playerRef = (0, import_react.useRef)(null);
1393
1395
  const [isRetrying, setIsRetrying] = (0, import_react.useState)(false);
1394
1396
  const videoElementRef = (0, import_react.useRef)(null);
1397
+ const destroyInProgressRef = (0, import_react.useRef)(null);
1398
+ const isDestroyingRef = (0, import_react.useRef)(false);
1399
+ const initSequenceRef = (0, import_react.useRef)(0);
1400
+ const activeInitIdRef = (0, import_react.useRef)(null);
1395
1401
  const waitingForKeyTimerRef = (0, import_react.useRef)(null);
1396
1402
  const waitingForKeyHandlerRef = (0, import_react.useRef)(null);
1397
1403
  const playbackResumedHandlerRef = (0, import_react.useRef)(null);
@@ -1415,11 +1421,22 @@ var useShakaPlayer = ({
1415
1421
  }, [src]);
1416
1422
  const initializePlayerInternal = (0, import_react.useCallback)(async (video) => {
1417
1423
  try {
1424
+ if (destroyInProgressRef.current) {
1425
+ try {
1426
+ await destroyInProgressRef.current;
1427
+ } catch {
1428
+ }
1429
+ }
1430
+ const myInitId = ++initSequenceRef.current;
1431
+ activeInitIdRef.current = myInitId;
1418
1432
  videoElementRef.current = video;
1419
1433
  import_shaka_player.default.polyfill.installAll();
1420
1434
  if (!import_shaka_player.default.Player.isBrowserSupported()) {
1421
1435
  throw new Error("Browser not supported by Shaka Player");
1422
1436
  }
1437
+ if (isDestroyingRef.current) {
1438
+ return;
1439
+ }
1423
1440
  const player = new import_shaka_player.default.Player();
1424
1441
  playerRef.current = player;
1425
1442
  await player.attach(video);
@@ -1430,6 +1447,14 @@ var useShakaPlayer = ({
1430
1447
  let playlistId = src.id;
1431
1448
  const isDRM = Boolean(src.drm);
1432
1449
  storedPersistentThisLoadRef.current = false;
1450
+ if (activeInitIdRef.current !== myInitId || isDestroyingRef.current) {
1451
+ try {
1452
+ await player.destroy();
1453
+ } catch {
1454
+ }
1455
+ if (playerRef.current === player) playerRef.current = null;
1456
+ return;
1457
+ }
1433
1458
  let storedSessionsMetadata = [];
1434
1459
  if (isDRM && playlistId) {
1435
1460
  storedSessionsMetadata = retrievePersistentLicense(playlistId, src.drm.licenseCacheKey ?? "");
@@ -1528,7 +1553,12 @@ var useShakaPlayer = ({
1528
1553
  if (netEngine) {
1529
1554
  netEngine.registerRequestFilter((type, request) => {
1530
1555
  if (type === import_shaka_player.default.net.NetworkingEngine.RequestType.LICENSE) {
1531
- request.headers["x-dt-auth-token"] = src.drm.token;
1556
+ if (publicKey) {
1557
+ request.headers["authorization"] = `Bearer ${publicKey}`;
1558
+ }
1559
+ if (mottoToken) {
1560
+ request.headers["x-motto-token"] = mottoToken;
1561
+ }
1532
1562
  }
1533
1563
  });
1534
1564
  netEngine.registerResponseFilter((type, response) => {
@@ -1634,6 +1664,14 @@ var useShakaPlayer = ({
1634
1664
  console.error("Failed to initialize Mux Analytics:", error);
1635
1665
  }
1636
1666
  }
1667
+ if (activeInitIdRef.current !== myInitId || isDestroyingRef.current) {
1668
+ try {
1669
+ await player.destroy();
1670
+ } catch {
1671
+ }
1672
+ if (playerRef.current === player) playerRef.current = null;
1673
+ return;
1674
+ }
1637
1675
  await player.load(manifestUrl);
1638
1676
  onPlayerReady?.(player);
1639
1677
  return player;
@@ -1650,8 +1688,11 @@ var useShakaPlayer = ({
1650
1688
  return initializePlayerInternal(video);
1651
1689
  }, [initializePlayerInternal]);
1652
1690
  const destroyPlayer = (0, import_react.useCallback)(async () => {
1653
- if (playerRef.current) {
1691
+ const playerInstance = playerRef.current;
1692
+ if (playerInstance) {
1654
1693
  try {
1694
+ isDestroyingRef.current = true;
1695
+ activeInitIdRef.current = null;
1655
1696
  if (videoElementRef.current) {
1656
1697
  try {
1657
1698
  if (waitingForKeyHandlerRef.current) {
@@ -1671,20 +1712,38 @@ var useShakaPlayer = ({
1671
1712
  waitingForKeyTimerRef.current = null;
1672
1713
  }
1673
1714
  try {
1674
- if (drmExpirationHandlerRef.current && playerRef.current?.removeEventListener) {
1675
- playerRef.current.removeEventListener("drmsessionupdate", drmExpirationHandlerRef.current);
1715
+ if (drmExpirationHandlerRef.current && playerInstance.removeEventListener) {
1716
+ playerInstance.removeEventListener("drmsessionupdate", drmExpirationHandlerRef.current);
1676
1717
  }
1677
1718
  } catch (e) {
1678
1719
  console.warn("Error removing DRM expiration listener:", e);
1679
1720
  } finally {
1680
1721
  drmExpirationHandlerRef.current = null;
1681
1722
  }
1682
- await playerRef.current.destroy();
1723
+ const performDestroy = async () => {
1724
+ try {
1725
+ await playerInstance.destroy();
1726
+ } finally {
1727
+ try {
1728
+ if (videoElementRef.current) {
1729
+ videoElementRef.current.removeAttribute("src");
1730
+ videoElementRef.current.load();
1731
+ }
1732
+ } catch {
1733
+ }
1734
+ }
1735
+ };
1736
+ destroyInProgressRef.current = performDestroy();
1737
+ await destroyInProgressRef.current;
1683
1738
  } catch (error) {
1684
1739
  console.warn("Error destroying Shaka Player:", error);
1685
1740
  } finally {
1686
- playerRef.current = null;
1741
+ if (playerRef.current === playerInstance) {
1742
+ playerRef.current = null;
1743
+ }
1687
1744
  storedPersistentThisLoadRef.current = false;
1745
+ isDestroyingRef.current = false;
1746
+ destroyInProgressRef.current = null;
1688
1747
  }
1689
1748
  }
1690
1749
  }, [playerRef]);
@@ -2190,14 +2249,18 @@ var useShakaUI = (playerRef, containerRef, videoRef, controls, chromecastConfig,
2190
2249
  }
2191
2250
  return ui;
2192
2251
  }, [controls, containerRef, playerRef, videoRef, chromecastConfig, seekbarColors, onSkipBack, onSkipForward, iconSizes, locale]);
2193
- const destroyUI = (0, import_react6.useCallback)(() => {
2194
- if (uiRef.current) {
2252
+ const destroyUI = (0, import_react6.useCallback)(async () => {
2253
+ const uiInstance = uiRef.current;
2254
+ if (uiInstance) {
2195
2255
  try {
2196
- uiRef.current.destroy();
2256
+ await uiInstance.destroy();
2197
2257
  } catch (error) {
2198
2258
  console.error("Error destroying UI:", error);
2259
+ } finally {
2260
+ if (uiRef.current === uiInstance) {
2261
+ uiRef.current = null;
2262
+ }
2199
2263
  }
2200
- uiRef.current = null;
2201
2264
  }
2202
2265
  }, []);
2203
2266
  return {
@@ -3823,6 +3886,8 @@ var Player = (0, import_react12.forwardRef)(
3823
3886
  events,
3824
3887
  locale = "en",
3825
3888
  containerClassName,
3889
+ publicKey,
3890
+ auth,
3826
3891
  ...videoProps
3827
3892
  }, ref) => {
3828
3893
  const videoRef = (0, import_react12.useRef)(null);
@@ -3839,7 +3904,9 @@ var Player = (0, import_react12.forwardRef)(
3839
3904
  onPlayerReady: events?.onPlayerReady,
3840
3905
  muxConfig,
3841
3906
  onMuxReady: events?.onMuxReady,
3842
- onMuxDataUpdate: events?.onMuxDataUpdate
3907
+ onMuxDataUpdate: events?.onMuxDataUpdate,
3908
+ publicKey,
3909
+ mottoToken: auth?.mottoToken
3843
3910
  });
3844
3911
  const {
3845
3912
  initializeMux,
@@ -4686,6 +4753,8 @@ var Video = ({
4686
4753
  events,
4687
4754
  locale,
4688
4755
  containerClassName: "w-full h-full",
4756
+ publicKey,
4757
+ auth,
4689
4758
  children
4690
4759
  }
4691
4760
  ) }) });
@@ -4854,7 +4923,9 @@ var Event = ({
4854
4923
  className: (0, import_tailwind_merge4.twMerge)(className, "peer aspect-video"),
4855
4924
  events,
4856
4925
  locale,
4857
- containerClassName: "w-full h-full"
4926
+ containerClassName: "w-full h-full",
4927
+ publicKey,
4928
+ auth
4858
4929
  }
4859
4930
  ) }),
4860
4931
  !hideTitle && eventData && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
@@ -5210,7 +5281,9 @@ var CreativeWork = ({
5210
5281
  },
5211
5282
  src: activePlaylist,
5212
5283
  locale,
5213
- containerClassName: "w-full h-full"
5284
+ containerClassName: "w-full h-full",
5285
+ publicKey,
5286
+ auth
5214
5287
  }
5215
5288
  ),
5216
5289
  !hideTitle && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(