@mottosports/motto-video-player 1.0.1-rc.65 → 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.65";
1188
+ var version = "1.0.1-rc.66";
1189
1189
 
1190
1190
  // src/utils/licenseCache.ts
1191
1191
  var PERSISTENT_LICENSE_PREFIX = "motto_lic_";
@@ -1353,6 +1353,10 @@ var useShakaPlayer = ({
1353
1353
  const playerRef = useRef(null);
1354
1354
  const [isRetrying, setIsRetrying] = useState(false);
1355
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);
1356
1360
  const waitingForKeyTimerRef = useRef(null);
1357
1361
  const waitingForKeyHandlerRef = useRef(null);
1358
1362
  const playbackResumedHandlerRef = useRef(null);
@@ -1376,11 +1380,22 @@ var useShakaPlayer = ({
1376
1380
  }, [src]);
1377
1381
  const initializePlayerInternal = useCallback(async (video) => {
1378
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;
1379
1391
  videoElementRef.current = video;
1380
1392
  shaka.polyfill.installAll();
1381
1393
  if (!shaka.Player.isBrowserSupported()) {
1382
1394
  throw new Error("Browser not supported by Shaka Player");
1383
1395
  }
1396
+ if (isDestroyingRef.current) {
1397
+ return;
1398
+ }
1384
1399
  const player = new shaka.Player();
1385
1400
  playerRef.current = player;
1386
1401
  await player.attach(video);
@@ -1391,6 +1406,14 @@ var useShakaPlayer = ({
1391
1406
  let playlistId = src.id;
1392
1407
  const isDRM = Boolean(src.drm);
1393
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
+ }
1394
1417
  let storedSessionsMetadata = [];
1395
1418
  if (isDRM && playlistId) {
1396
1419
  storedSessionsMetadata = retrievePersistentLicense(playlistId, src.drm.licenseCacheKey ?? "");
@@ -1600,6 +1623,14 @@ var useShakaPlayer = ({
1600
1623
  console.error("Failed to initialize Mux Analytics:", error);
1601
1624
  }
1602
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
+ }
1603
1634
  await player.load(manifestUrl);
1604
1635
  onPlayerReady?.(player);
1605
1636
  return player;
@@ -1619,6 +1650,8 @@ var useShakaPlayer = ({
1619
1650
  const playerInstance = playerRef.current;
1620
1651
  if (playerInstance) {
1621
1652
  try {
1653
+ isDestroyingRef.current = true;
1654
+ activeInitIdRef.current = null;
1622
1655
  if (videoElementRef.current) {
1623
1656
  try {
1624
1657
  if (waitingForKeyHandlerRef.current) {
@@ -1646,7 +1679,21 @@ var useShakaPlayer = ({
1646
1679
  } finally {
1647
1680
  drmExpirationHandlerRef.current = null;
1648
1681
  }
1649
- await playerInstance.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;
1650
1697
  } catch (error) {
1651
1698
  console.warn("Error destroying Shaka Player:", error);
1652
1699
  } finally {
@@ -1654,6 +1701,8 @@ var useShakaPlayer = ({
1654
1701
  playerRef.current = null;
1655
1702
  }
1656
1703
  storedPersistentThisLoadRef.current = false;
1704
+ isDestroyingRef.current = false;
1705
+ destroyInProgressRef.current = null;
1657
1706
  }
1658
1707
  }
1659
1708
  }, [playerRef]);