@mottosports/motto-video-player 1.0.1-rc.65 → 1.0.1-rc.67
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.js +64 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +64 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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.
|
|
1229
|
+
var version = "1.0.1-rc.67";
|
|
1230
1230
|
|
|
1231
1231
|
// src/utils/licenseCache.ts
|
|
1232
1232
|
var PERSISTENT_LICENSE_PREFIX = "motto_lic_";
|
|
@@ -1394,6 +1394,10 @@ var useShakaPlayer = ({
|
|
|
1394
1394
|
const playerRef = (0, import_react.useRef)(null);
|
|
1395
1395
|
const [isRetrying, setIsRetrying] = (0, import_react.useState)(false);
|
|
1396
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);
|
|
1397
1401
|
const waitingForKeyTimerRef = (0, import_react.useRef)(null);
|
|
1398
1402
|
const waitingForKeyHandlerRef = (0, import_react.useRef)(null);
|
|
1399
1403
|
const playbackResumedHandlerRef = (0, import_react.useRef)(null);
|
|
@@ -1417,11 +1421,22 @@ var useShakaPlayer = ({
|
|
|
1417
1421
|
}, [src]);
|
|
1418
1422
|
const initializePlayerInternal = (0, import_react.useCallback)(async (video) => {
|
|
1419
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;
|
|
1420
1432
|
videoElementRef.current = video;
|
|
1421
1433
|
import_shaka_player.default.polyfill.installAll();
|
|
1422
1434
|
if (!import_shaka_player.default.Player.isBrowserSupported()) {
|
|
1423
1435
|
throw new Error("Browser not supported by Shaka Player");
|
|
1424
1436
|
}
|
|
1437
|
+
if (isDestroyingRef.current) {
|
|
1438
|
+
return;
|
|
1439
|
+
}
|
|
1425
1440
|
const player = new import_shaka_player.default.Player();
|
|
1426
1441
|
playerRef.current = player;
|
|
1427
1442
|
await player.attach(video);
|
|
@@ -1432,6 +1447,14 @@ var useShakaPlayer = ({
|
|
|
1432
1447
|
let playlistId = src.id;
|
|
1433
1448
|
const isDRM = Boolean(src.drm);
|
|
1434
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
|
+
}
|
|
1435
1458
|
let storedSessionsMetadata = [];
|
|
1436
1459
|
if (isDRM && playlistId) {
|
|
1437
1460
|
storedSessionsMetadata = retrievePersistentLicense(playlistId, src.drm.licenseCacheKey ?? "");
|
|
@@ -1529,13 +1552,19 @@ var useShakaPlayer = ({
|
|
|
1529
1552
|
const netEngine = player.getNetworkingEngine();
|
|
1530
1553
|
if (netEngine) {
|
|
1531
1554
|
netEngine.registerRequestFilter((type, request) => {
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1555
|
+
switch (type) {
|
|
1556
|
+
case import_shaka_player.default.net.NetworkingEngine.RequestType.LICENSE:
|
|
1557
|
+
if (publicKey) {
|
|
1558
|
+
request.headers["authorization"] = `Bearer ${publicKey}`;
|
|
1559
|
+
}
|
|
1560
|
+
if (mottoToken) {
|
|
1561
|
+
request.headers["x-motto-token"] = mottoToken;
|
|
1562
|
+
}
|
|
1563
|
+
break;
|
|
1564
|
+
case import_shaka_player.default.net.NetworkingEngine.RequestType.MANIFEST:
|
|
1565
|
+
case import_shaka_player.default.net.NetworkingEngine.RequestType.SEGMENT:
|
|
1566
|
+
request.allowCrossSiteCredentials = true;
|
|
1567
|
+
break;
|
|
1539
1568
|
}
|
|
1540
1569
|
});
|
|
1541
1570
|
netEngine.registerResponseFilter((type, response) => {
|
|
@@ -1641,6 +1670,14 @@ var useShakaPlayer = ({
|
|
|
1641
1670
|
console.error("Failed to initialize Mux Analytics:", error);
|
|
1642
1671
|
}
|
|
1643
1672
|
}
|
|
1673
|
+
if (activeInitIdRef.current !== myInitId || isDestroyingRef.current) {
|
|
1674
|
+
try {
|
|
1675
|
+
await player.destroy();
|
|
1676
|
+
} catch {
|
|
1677
|
+
}
|
|
1678
|
+
if (playerRef.current === player) playerRef.current = null;
|
|
1679
|
+
return;
|
|
1680
|
+
}
|
|
1644
1681
|
await player.load(manifestUrl);
|
|
1645
1682
|
onPlayerReady?.(player);
|
|
1646
1683
|
return player;
|
|
@@ -1660,6 +1697,8 @@ var useShakaPlayer = ({
|
|
|
1660
1697
|
const playerInstance = playerRef.current;
|
|
1661
1698
|
if (playerInstance) {
|
|
1662
1699
|
try {
|
|
1700
|
+
isDestroyingRef.current = true;
|
|
1701
|
+
activeInitIdRef.current = null;
|
|
1663
1702
|
if (videoElementRef.current) {
|
|
1664
1703
|
try {
|
|
1665
1704
|
if (waitingForKeyHandlerRef.current) {
|
|
@@ -1687,7 +1726,21 @@ var useShakaPlayer = ({
|
|
|
1687
1726
|
} finally {
|
|
1688
1727
|
drmExpirationHandlerRef.current = null;
|
|
1689
1728
|
}
|
|
1690
|
-
|
|
1729
|
+
const performDestroy = async () => {
|
|
1730
|
+
try {
|
|
1731
|
+
await playerInstance.destroy();
|
|
1732
|
+
} finally {
|
|
1733
|
+
try {
|
|
1734
|
+
if (videoElementRef.current) {
|
|
1735
|
+
videoElementRef.current.removeAttribute("src");
|
|
1736
|
+
videoElementRef.current.load();
|
|
1737
|
+
}
|
|
1738
|
+
} catch {
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
};
|
|
1742
|
+
destroyInProgressRef.current = performDestroy();
|
|
1743
|
+
await destroyInProgressRef.current;
|
|
1691
1744
|
} catch (error) {
|
|
1692
1745
|
console.warn("Error destroying Shaka Player:", error);
|
|
1693
1746
|
} finally {
|
|
@@ -1695,6 +1748,8 @@ var useShakaPlayer = ({
|
|
|
1695
1748
|
playerRef.current = null;
|
|
1696
1749
|
}
|
|
1697
1750
|
storedPersistentThisLoadRef.current = false;
|
|
1751
|
+
isDestroyingRef.current = false;
|
|
1752
|
+
destroyInProgressRef.current = null;
|
|
1698
1753
|
}
|
|
1699
1754
|
}
|
|
1700
1755
|
}, [playerRef]);
|