@mottosports/motto-video-player 1.0.1-rc.52 → 1.0.1-rc.53
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 +121 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +140 -31
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1211,7 +1211,7 @@ var supportsWidevinePersistentLicenses = () => {
|
|
|
1211
1211
|
var import_mux_data_shakaplayer = __toESM(require("@mux/mux-data-shakaplayer"));
|
|
1212
1212
|
|
|
1213
1213
|
// package.json
|
|
1214
|
-
var version = "1.0.1-rc.
|
|
1214
|
+
var version = "1.0.1-rc.53";
|
|
1215
1215
|
|
|
1216
1216
|
// src/utils/licenseCache.ts
|
|
1217
1217
|
var PERSISTENT_LICENSE_PREFIX = "motto_lic_";
|
|
@@ -3598,6 +3598,81 @@ html[dir=rtl] .shaka-overflow-menu .shaka-overflow-button .material-svg-icon:fir
|
|
|
3598
3598
|
|
|
3599
3599
|
// src/Player.tsx
|
|
3600
3600
|
var import_tailwind_merge2 = require("tailwind-merge");
|
|
3601
|
+
|
|
3602
|
+
// src/utils/scriptLoader.ts
|
|
3603
|
+
var SCRIPT_CONFIGS = {
|
|
3604
|
+
ima: {
|
|
3605
|
+
src: "https://imasdk.googleapis.com/js/sdkloader/ima3.js",
|
|
3606
|
+
id: "ima-sdk",
|
|
3607
|
+
type: "text/javascript"
|
|
3608
|
+
},
|
|
3609
|
+
system73: {
|
|
3610
|
+
src: "//cdn.s73cloud.com/4/s73-sdk-shakaplayer.js",
|
|
3611
|
+
id: "system73-sdk",
|
|
3612
|
+
type: "application/javascript"
|
|
3613
|
+
}
|
|
3614
|
+
};
|
|
3615
|
+
function loadScript(config) {
|
|
3616
|
+
return new Promise((resolve, reject) => {
|
|
3617
|
+
if (document.getElementById(config.id)) {
|
|
3618
|
+
resolve();
|
|
3619
|
+
return;
|
|
3620
|
+
}
|
|
3621
|
+
const script = document.createElement("script");
|
|
3622
|
+
script.id = config.id;
|
|
3623
|
+
script.src = config.src;
|
|
3624
|
+
script.type = config.type || "text/javascript";
|
|
3625
|
+
script.async = true;
|
|
3626
|
+
script.onload = () => resolve();
|
|
3627
|
+
script.onerror = () => reject(new Error(`Failed to load script: ${config.src}`));
|
|
3628
|
+
document.head.appendChild(script);
|
|
3629
|
+
});
|
|
3630
|
+
}
|
|
3631
|
+
function getRequiredScriptLoaders(needsIma, needsSystem73) {
|
|
3632
|
+
const loaders = [];
|
|
3633
|
+
if (needsIma) {
|
|
3634
|
+
loaders.push(loadScript(SCRIPT_CONFIGS.ima));
|
|
3635
|
+
}
|
|
3636
|
+
if (needsSystem73) {
|
|
3637
|
+
loaders.push(loadScript(SCRIPT_CONFIGS.system73));
|
|
3638
|
+
}
|
|
3639
|
+
return loaders;
|
|
3640
|
+
}
|
|
3641
|
+
async function loadScripts(scriptLoaders) {
|
|
3642
|
+
if (scriptLoaders.length === 0) {
|
|
3643
|
+
return;
|
|
3644
|
+
}
|
|
3645
|
+
try {
|
|
3646
|
+
await Promise.all(scriptLoaders);
|
|
3647
|
+
} catch (error) {
|
|
3648
|
+
console.error("Error loading scripts:", error);
|
|
3649
|
+
throw error;
|
|
3650
|
+
}
|
|
3651
|
+
}
|
|
3652
|
+
function waitForGlobal(globalName, timeout = 5e3) {
|
|
3653
|
+
return new Promise((resolve, reject) => {
|
|
3654
|
+
const startTime = Date.now();
|
|
3655
|
+
function checkGlobal() {
|
|
3656
|
+
const global = window[globalName];
|
|
3657
|
+
if (global) {
|
|
3658
|
+
resolve(global);
|
|
3659
|
+
return;
|
|
3660
|
+
}
|
|
3661
|
+
if (Date.now() - startTime > timeout) {
|
|
3662
|
+
reject(new Error(`Timeout waiting for global: ${globalName}`));
|
|
3663
|
+
return;
|
|
3664
|
+
}
|
|
3665
|
+
setTimeout(checkGlobal, 100);
|
|
3666
|
+
}
|
|
3667
|
+
checkGlobal();
|
|
3668
|
+
});
|
|
3669
|
+
}
|
|
3670
|
+
async function waitForGlobals(globalNames, timeout = 5e3) {
|
|
3671
|
+
const promises = globalNames.map((name) => waitForGlobal(name, timeout));
|
|
3672
|
+
await Promise.all(promises);
|
|
3673
|
+
}
|
|
3674
|
+
|
|
3675
|
+
// src/Player.tsx
|
|
3601
3676
|
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
3602
3677
|
var Player = (0, import_react12.forwardRef)(
|
|
3603
3678
|
({
|
|
@@ -3623,9 +3698,9 @@ var Player = (0, import_react12.forwardRef)(
|
|
|
3623
3698
|
containerClassName,
|
|
3624
3699
|
...videoProps
|
|
3625
3700
|
}, ref) => {
|
|
3626
|
-
console.log("system73Config", system73Config);
|
|
3627
3701
|
const videoRef = (0, import_react12.useRef)(null);
|
|
3628
3702
|
const containerRef = (0, import_react12.useRef)(null);
|
|
3703
|
+
const [isScriptsLoaded, setIsScriptsLoaded] = (0, import_react12.useState)(false);
|
|
3629
3704
|
(0, import_react12.useImperativeHandle)(ref, () => videoRef.current, []);
|
|
3630
3705
|
const { playerRef, initializePlayer, destroyPlayer, isRetrying } = useShakaPlayer({
|
|
3631
3706
|
src,
|
|
@@ -3716,7 +3791,11 @@ var Player = (0, import_react12.forwardRef)(
|
|
|
3716
3791
|
if (!imaConfig?.adTagUrl || !playerRef.current || !videoRef.current || !uiRef.current) {
|
|
3717
3792
|
return;
|
|
3718
3793
|
}
|
|
3719
|
-
|
|
3794
|
+
if (!window.google?.ima) {
|
|
3795
|
+
console.error("Google IMA SDK not available when trying to initialize ads");
|
|
3796
|
+
return;
|
|
3797
|
+
}
|
|
3798
|
+
console.log("Initializing ads with autoplay:", autoPlay);
|
|
3720
3799
|
try {
|
|
3721
3800
|
const player = playerRef.current;
|
|
3722
3801
|
const video = videoRef.current;
|
|
@@ -3728,23 +3807,53 @@ var Player = (0, import_react12.forwardRef)(
|
|
|
3728
3807
|
console.error("Ad manager not available");
|
|
3729
3808
|
return;
|
|
3730
3809
|
}
|
|
3731
|
-
adManager.initClientSide(container, video);
|
|
3732
3810
|
const google = window.google;
|
|
3811
|
+
let adsRenderingSettings = null;
|
|
3812
|
+
if (imaConfig.adsRenderingSettings) {
|
|
3813
|
+
adsRenderingSettings = imaConfig.adsRenderingSettings;
|
|
3814
|
+
} else if (autoPlay) {
|
|
3815
|
+
adsRenderingSettings = new google.ima.AdsRenderingSettings();
|
|
3816
|
+
adsRenderingSettings.restoreCustomPlaybackStateOnAdBreakComplete = true;
|
|
3817
|
+
}
|
|
3818
|
+
adManager.initClientSide(container, video, adsRenderingSettings);
|
|
3733
3819
|
const adsRequest = new google.ima.AdsRequest();
|
|
3734
3820
|
adsRequest.adTagUrl = imaConfig.adTagUrl;
|
|
3735
3821
|
adManager.requestClientSideAds(adsRequest);
|
|
3736
|
-
console.log("Ads requested with tag:", imaConfig.adTagUrl);
|
|
3822
|
+
console.log("Ads requested successfully with tag:", imaConfig.adTagUrl, "autoplay:", autoPlay);
|
|
3737
3823
|
} catch (error) {
|
|
3738
3824
|
console.error("Error initializing ads:", error);
|
|
3739
3825
|
}
|
|
3740
|
-
}, [imaConfig]);
|
|
3826
|
+
}, [imaConfig, autoPlay]);
|
|
3827
|
+
(0, import_react12.useEffect)(() => {
|
|
3828
|
+
const loadRequiredScripts = async () => {
|
|
3829
|
+
try {
|
|
3830
|
+
const scriptLoaders = getRequiredScriptLoaders(!!imaConfig?.adTagUrl, !!system73Config?.apiKey);
|
|
3831
|
+
await loadScripts(scriptLoaders);
|
|
3832
|
+
const globalsToWait = [];
|
|
3833
|
+
if (imaConfig?.adTagUrl) {
|
|
3834
|
+
globalsToWait.push("google");
|
|
3835
|
+
}
|
|
3836
|
+
if (system73Config?.apiKey) {
|
|
3837
|
+
globalsToWait.push("S73ShakaPlayerWrapper");
|
|
3838
|
+
}
|
|
3839
|
+
if (globalsToWait.length > 0) {
|
|
3840
|
+
await waitForGlobals(globalsToWait);
|
|
3841
|
+
}
|
|
3842
|
+
setIsScriptsLoaded(true);
|
|
3843
|
+
} catch (error) {
|
|
3844
|
+
console.error("Error loading required scripts:", error);
|
|
3845
|
+
setIsScriptsLoaded(true);
|
|
3846
|
+
}
|
|
3847
|
+
};
|
|
3848
|
+
loadRequiredScripts();
|
|
3849
|
+
}, [imaConfig?.adTagUrl, system73Config?.apiKey]);
|
|
3741
3850
|
(0, import_react12.useEffect)(() => {
|
|
3742
3851
|
const video = videoRef.current;
|
|
3743
|
-
if (!video) return;
|
|
3852
|
+
if (!video || !isScriptsLoaded) return;
|
|
3744
3853
|
const initialize = async () => {
|
|
3745
3854
|
try {
|
|
3746
3855
|
let system73Wrapper = null;
|
|
3747
|
-
if (system73Config?.apiKey) {
|
|
3856
|
+
if (system73Config?.apiKey && window.S73ShakaPlayerWrapper) {
|
|
3748
3857
|
const playerConfig = { ...shakaConfig };
|
|
3749
3858
|
system73Wrapper = initializeSystem73(playerConfig);
|
|
3750
3859
|
if (system73Wrapper) {
|
|
@@ -3760,7 +3869,8 @@ var Player = (0, import_react12.forwardRef)(
|
|
|
3760
3869
|
const cleanupQuality = setupQualityTracking();
|
|
3761
3870
|
configureQuality();
|
|
3762
3871
|
await initializeUI();
|
|
3763
|
-
if (imaConfig) {
|
|
3872
|
+
if (imaConfig?.adTagUrl && window.google?.ima) {
|
|
3873
|
+
console.log("Initializing ads immediately after UI setup");
|
|
3764
3874
|
initializeAds();
|
|
3765
3875
|
}
|
|
3766
3876
|
} catch (error) {
|
|
@@ -3775,16 +3885,15 @@ var Player = (0, import_react12.forwardRef)(
|
|
|
3775
3885
|
destroyMux();
|
|
3776
3886
|
destroyPlayer();
|
|
3777
3887
|
};
|
|
3778
|
-
}, [src]);
|
|
3888
|
+
}, [src, isScriptsLoaded]);
|
|
3779
3889
|
(0, import_react12.useEffect)(() => {
|
|
3780
3890
|
const video = videoRef.current;
|
|
3781
3891
|
if (!video) return;
|
|
3782
3892
|
video.autoplay = autoPlay;
|
|
3783
3893
|
video.loop = loop;
|
|
3784
|
-
video.muted = muted;
|
|
3785
3894
|
video.controls = false;
|
|
3786
3895
|
if (poster) video.poster = poster;
|
|
3787
|
-
}, [autoPlay, loop, muted, poster]);
|
|
3896
|
+
}, [autoPlay, loop, muted, poster, imaConfig?.adTagUrl]);
|
|
3788
3897
|
(0, import_react12.useEffect)(() => {
|
|
3789
3898
|
const video = videoRef.current;
|
|
3790
3899
|
if (!video) return;
|