@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.mjs CHANGED
@@ -1185,7 +1185,7 @@ var supportsWidevinePersistentLicenses = () => {
1185
1185
  import initShakaPlayerMux from "@mux/mux-data-shakaplayer";
1186
1186
 
1187
1187
  // package.json
1188
- var version = "1.0.1-rc.64";
1188
+ var version = "1.0.1-rc.66";
1189
1189
 
1190
1190
  // src/utils/licenseCache.ts
1191
1191
  var PERSISTENT_LICENSE_PREFIX = "motto_lic_";
@@ -1346,11 +1346,17 @@ var useShakaPlayer = ({
1346
1346
  onPlayerReady,
1347
1347
  muxConfig,
1348
1348
  onMuxReady,
1349
- onMuxDataUpdate
1349
+ onMuxDataUpdate,
1350
+ publicKey,
1351
+ mottoToken
1350
1352
  }) => {
1351
1353
  const playerRef = useRef(null);
1352
1354
  const [isRetrying, setIsRetrying] = useState(false);
1353
1355
  const videoElementRef = useRef(null);
1356
+ const destroyInProgressRef = useRef(null);
1357
+ const isDestroyingRef = useRef(false);
1358
+ const initSequenceRef = useRef(0);
1359
+ const activeInitIdRef = useRef(null);
1354
1360
  const waitingForKeyTimerRef = useRef(null);
1355
1361
  const waitingForKeyHandlerRef = useRef(null);
1356
1362
  const playbackResumedHandlerRef = useRef(null);
@@ -1374,11 +1380,22 @@ var useShakaPlayer = ({
1374
1380
  }, [src]);
1375
1381
  const initializePlayerInternal = useCallback(async (video) => {
1376
1382
  try {
1383
+ if (destroyInProgressRef.current) {
1384
+ try {
1385
+ await destroyInProgressRef.current;
1386
+ } catch {
1387
+ }
1388
+ }
1389
+ const myInitId = ++initSequenceRef.current;
1390
+ activeInitIdRef.current = myInitId;
1377
1391
  videoElementRef.current = video;
1378
1392
  shaka.polyfill.installAll();
1379
1393
  if (!shaka.Player.isBrowserSupported()) {
1380
1394
  throw new Error("Browser not supported by Shaka Player");
1381
1395
  }
1396
+ if (isDestroyingRef.current) {
1397
+ return;
1398
+ }
1382
1399
  const player = new shaka.Player();
1383
1400
  playerRef.current = player;
1384
1401
  await player.attach(video);
@@ -1389,6 +1406,14 @@ var useShakaPlayer = ({
1389
1406
  let playlistId = src.id;
1390
1407
  const isDRM = Boolean(src.drm);
1391
1408
  storedPersistentThisLoadRef.current = false;
1409
+ if (activeInitIdRef.current !== myInitId || isDestroyingRef.current) {
1410
+ try {
1411
+ await player.destroy();
1412
+ } catch {
1413
+ }
1414
+ if (playerRef.current === player) playerRef.current = null;
1415
+ return;
1416
+ }
1392
1417
  let storedSessionsMetadata = [];
1393
1418
  if (isDRM && playlistId) {
1394
1419
  storedSessionsMetadata = retrievePersistentLicense(playlistId, src.drm.licenseCacheKey ?? "");
@@ -1487,7 +1512,12 @@ var useShakaPlayer = ({
1487
1512
  if (netEngine) {
1488
1513
  netEngine.registerRequestFilter((type, request) => {
1489
1514
  if (type === shaka.net.NetworkingEngine.RequestType.LICENSE) {
1490
- request.headers["x-dt-auth-token"] = src.drm.token;
1515
+ if (publicKey) {
1516
+ request.headers["authorization"] = `Bearer ${publicKey}`;
1517
+ }
1518
+ if (mottoToken) {
1519
+ request.headers["x-motto-token"] = mottoToken;
1520
+ }
1491
1521
  }
1492
1522
  });
1493
1523
  netEngine.registerResponseFilter((type, response) => {
@@ -1593,6 +1623,14 @@ var useShakaPlayer = ({
1593
1623
  console.error("Failed to initialize Mux Analytics:", error);
1594
1624
  }
1595
1625
  }
1626
+ if (activeInitIdRef.current !== myInitId || isDestroyingRef.current) {
1627
+ try {
1628
+ await player.destroy();
1629
+ } catch {
1630
+ }
1631
+ if (playerRef.current === player) playerRef.current = null;
1632
+ return;
1633
+ }
1596
1634
  await player.load(manifestUrl);
1597
1635
  onPlayerReady?.(player);
1598
1636
  return player;
@@ -1609,8 +1647,11 @@ var useShakaPlayer = ({
1609
1647
  return initializePlayerInternal(video);
1610
1648
  }, [initializePlayerInternal]);
1611
1649
  const destroyPlayer = useCallback(async () => {
1612
- if (playerRef.current) {
1650
+ const playerInstance = playerRef.current;
1651
+ if (playerInstance) {
1613
1652
  try {
1653
+ isDestroyingRef.current = true;
1654
+ activeInitIdRef.current = null;
1614
1655
  if (videoElementRef.current) {
1615
1656
  try {
1616
1657
  if (waitingForKeyHandlerRef.current) {
@@ -1630,20 +1671,38 @@ var useShakaPlayer = ({
1630
1671
  waitingForKeyTimerRef.current = null;
1631
1672
  }
1632
1673
  try {
1633
- if (drmExpirationHandlerRef.current && playerRef.current?.removeEventListener) {
1634
- playerRef.current.removeEventListener("drmsessionupdate", drmExpirationHandlerRef.current);
1674
+ if (drmExpirationHandlerRef.current && playerInstance.removeEventListener) {
1675
+ playerInstance.removeEventListener("drmsessionupdate", drmExpirationHandlerRef.current);
1635
1676
  }
1636
1677
  } catch (e) {
1637
1678
  console.warn("Error removing DRM expiration listener:", e);
1638
1679
  } finally {
1639
1680
  drmExpirationHandlerRef.current = null;
1640
1681
  }
1641
- await playerRef.current.destroy();
1682
+ const performDestroy = async () => {
1683
+ try {
1684
+ await playerInstance.destroy();
1685
+ } finally {
1686
+ try {
1687
+ if (videoElementRef.current) {
1688
+ videoElementRef.current.removeAttribute("src");
1689
+ videoElementRef.current.load();
1690
+ }
1691
+ } catch {
1692
+ }
1693
+ }
1694
+ };
1695
+ destroyInProgressRef.current = performDestroy();
1696
+ await destroyInProgressRef.current;
1642
1697
  } catch (error) {
1643
1698
  console.warn("Error destroying Shaka Player:", error);
1644
1699
  } finally {
1645
- playerRef.current = null;
1700
+ if (playerRef.current === playerInstance) {
1701
+ playerRef.current = null;
1702
+ }
1646
1703
  storedPersistentThisLoadRef.current = false;
1704
+ isDestroyingRef.current = false;
1705
+ destroyInProgressRef.current = null;
1647
1706
  }
1648
1707
  }
1649
1708
  }, [playerRef]);
@@ -2149,14 +2208,18 @@ var useShakaUI = (playerRef, containerRef, videoRef, controls, chromecastConfig,
2149
2208
  }
2150
2209
  return ui;
2151
2210
  }, [controls, containerRef, playerRef, videoRef, chromecastConfig, seekbarColors, onSkipBack, onSkipForward, iconSizes, locale]);
2152
- const destroyUI = useCallback5(() => {
2153
- if (uiRef.current) {
2211
+ const destroyUI = useCallback5(async () => {
2212
+ const uiInstance = uiRef.current;
2213
+ if (uiInstance) {
2154
2214
  try {
2155
- uiRef.current.destroy();
2215
+ await uiInstance.destroy();
2156
2216
  } catch (error) {
2157
2217
  console.error("Error destroying UI:", error);
2218
+ } finally {
2219
+ if (uiRef.current === uiInstance) {
2220
+ uiRef.current = null;
2221
+ }
2158
2222
  }
2159
- uiRef.current = null;
2160
2223
  }
2161
2224
  }, []);
2162
2225
  return {
@@ -3782,6 +3845,8 @@ var Player = forwardRef(
3782
3845
  events,
3783
3846
  locale = "en",
3784
3847
  containerClassName,
3848
+ publicKey,
3849
+ auth,
3785
3850
  ...videoProps
3786
3851
  }, ref) => {
3787
3852
  const videoRef = useRef8(null);
@@ -3798,7 +3863,9 @@ var Player = forwardRef(
3798
3863
  onPlayerReady: events?.onPlayerReady,
3799
3864
  muxConfig,
3800
3865
  onMuxReady: events?.onMuxReady,
3801
- onMuxDataUpdate: events?.onMuxDataUpdate
3866
+ onMuxDataUpdate: events?.onMuxDataUpdate,
3867
+ publicKey,
3868
+ mottoToken: auth?.mottoToken
3802
3869
  });
3803
3870
  const {
3804
3871
  initializeMux,
@@ -4645,6 +4712,8 @@ var Video = ({
4645
4712
  events,
4646
4713
  locale,
4647
4714
  containerClassName: "w-full h-full",
4715
+ publicKey,
4716
+ auth,
4648
4717
  children
4649
4718
  }
4650
4719
  ) }) });
@@ -4813,7 +4882,9 @@ var Event = ({
4813
4882
  className: twMerge4(className, "peer aspect-video"),
4814
4883
  events,
4815
4884
  locale,
4816
- containerClassName: "w-full h-full"
4885
+ containerClassName: "w-full h-full",
4886
+ publicKey,
4887
+ auth
4817
4888
  }
4818
4889
  ) }),
4819
4890
  !hideTitle && eventData && /* @__PURE__ */ jsx10(
@@ -5169,7 +5240,9 @@ var CreativeWork = ({
5169
5240
  },
5170
5241
  src: activePlaylist,
5171
5242
  locale,
5172
- containerClassName: "w-full h-full"
5243
+ containerClassName: "w-full h-full",
5244
+ publicKey,
5245
+ auth
5173
5246
  }
5174
5247
  ),
5175
5248
  !hideTitle && /* @__PURE__ */ jsx11(