@mottosports/motto-video-player 1.0.1-rc.52 → 1.0.1-rc.54

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
@@ -308,6 +308,11 @@ interface PlayerProps extends Omit<HTMLAttributes<HTMLVideoElement>, 'src' | 'on
308
308
  * Event callbacks
309
309
  */
310
310
  events?: PlayerEvents;
311
+ /**
312
+ * Locale for Shaka Player UI localization (e.g., 'en', 'ar', 'es')
313
+ * Defaults to 'en' if not provided
314
+ */
315
+ locale?: string;
311
316
  containerClassName?: string;
312
317
  }
313
318
  /**
package/dist/index.d.ts CHANGED
@@ -308,6 +308,11 @@ interface PlayerProps extends Omit<HTMLAttributes<HTMLVideoElement>, 'src' | 'on
308
308
  * Event callbacks
309
309
  */
310
310
  events?: PlayerEvents;
311
+ /**
312
+ * Locale for Shaka Player UI localization (e.g., 'en', 'ar', 'es')
313
+ * Defaults to 'en' if not provided
314
+ */
315
+ locale?: string;
311
316
  containerClassName?: string;
312
317
  }
313
318
  /**
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.52";
1214
+ var version = "1.0.1-rc.54";
1215
1215
 
1216
1216
  // src/utils/licenseCache.ts
1217
1217
  var PERSISTENT_LICENSE_PREFIX = "motto_lic_";
@@ -2000,7 +2000,7 @@ var SkipForwardButtonFactory = class {
2000
2000
  return new SkipForwardButton(rootElement, controls, this.onSkipForward, this.iconSize);
2001
2001
  }
2002
2002
  };
2003
- var useShakaUI = (playerRef, containerRef, videoRef, controls, chromecastConfig, seekbarColors, onSkipBack, onSkipForward, iconSizes) => {
2003
+ var useShakaUI = (playerRef, containerRef, videoRef, controls, chromecastConfig, seekbarColors, onSkipBack, onSkipForward, iconSizes, locale = "en") => {
2004
2004
  const uiRef = (0, import_react6.useRef)(null);
2005
2005
  const registeredElements = (0, import_react6.useRef)(/* @__PURE__ */ new Set());
2006
2006
  const initializeUI = (0, import_react6.useCallback)(async () => {
@@ -2017,6 +2017,14 @@ var useShakaUI = (playerRef, containerRef, videoRef, controls, chromecastConfig,
2017
2017
  }
2018
2018
  const ui = new import_shaka_player3.ui.Overlay(playerRef.current, containerRef.current, videoRef.current);
2019
2019
  uiRef.current = ui;
2020
+ if (locale !== "en") {
2021
+ try {
2022
+ ui.getControls().getLocalization().changeLocale([locale]);
2023
+ console.log(`Set locale to '${locale}'`);
2024
+ } catch (error) {
2025
+ console.warn(`Failed to set locale to '${locale}', falling back to 'en':`, error);
2026
+ }
2027
+ }
2020
2028
  const isMobile = window.innerWidth <= 767;
2021
2029
  const controlPanelElements = [
2022
2030
  ...isMobile ? [] : ["skip_back_button"],
@@ -2081,7 +2089,7 @@ var useShakaUI = (playerRef, containerRef, videoRef, controls, chromecastConfig,
2081
2089
  }
2082
2090
  }
2083
2091
  return ui;
2084
- }, [controls, containerRef, playerRef, videoRef, chromecastConfig, seekbarColors, onSkipBack, onSkipForward, iconSizes]);
2092
+ }, [controls, containerRef, playerRef, videoRef, chromecastConfig, seekbarColors, onSkipBack, onSkipForward, iconSizes, locale]);
2085
2093
  const destroyUI = (0, import_react6.useCallback)(() => {
2086
2094
  if (uiRef.current) {
2087
2095
  try {
@@ -3598,6 +3606,81 @@ html[dir=rtl] .shaka-overflow-menu .shaka-overflow-button .material-svg-icon:fir
3598
3606
 
3599
3607
  // src/Player.tsx
3600
3608
  var import_tailwind_merge2 = require("tailwind-merge");
3609
+
3610
+ // src/utils/scriptLoader.ts
3611
+ var SCRIPT_CONFIGS = {
3612
+ ima: {
3613
+ src: "https://imasdk.googleapis.com/js/sdkloader/ima3.js",
3614
+ id: "ima-sdk",
3615
+ type: "text/javascript"
3616
+ },
3617
+ system73: {
3618
+ src: "//cdn.s73cloud.com/4/s73-sdk-shakaplayer.js",
3619
+ id: "system73-sdk",
3620
+ type: "application/javascript"
3621
+ }
3622
+ };
3623
+ function loadScript(config) {
3624
+ return new Promise((resolve, reject) => {
3625
+ if (document.getElementById(config.id)) {
3626
+ resolve();
3627
+ return;
3628
+ }
3629
+ const script = document.createElement("script");
3630
+ script.id = config.id;
3631
+ script.src = config.src;
3632
+ script.type = config.type || "text/javascript";
3633
+ script.async = true;
3634
+ script.onload = () => resolve();
3635
+ script.onerror = () => reject(new Error(`Failed to load script: ${config.src}`));
3636
+ document.head.appendChild(script);
3637
+ });
3638
+ }
3639
+ function getRequiredScriptLoaders(needsIma, needsSystem73) {
3640
+ const loaders = [];
3641
+ if (needsIma) {
3642
+ loaders.push(loadScript(SCRIPT_CONFIGS.ima));
3643
+ }
3644
+ if (needsSystem73) {
3645
+ loaders.push(loadScript(SCRIPT_CONFIGS.system73));
3646
+ }
3647
+ return loaders;
3648
+ }
3649
+ async function loadScripts(scriptLoaders) {
3650
+ if (scriptLoaders.length === 0) {
3651
+ return;
3652
+ }
3653
+ try {
3654
+ await Promise.all(scriptLoaders);
3655
+ } catch (error) {
3656
+ console.error("Error loading scripts:", error);
3657
+ throw error;
3658
+ }
3659
+ }
3660
+ function waitForGlobal(globalName, timeout = 5e3) {
3661
+ return new Promise((resolve, reject) => {
3662
+ const startTime = Date.now();
3663
+ function checkGlobal() {
3664
+ const global = window[globalName];
3665
+ if (global) {
3666
+ resolve(global);
3667
+ return;
3668
+ }
3669
+ if (Date.now() - startTime > timeout) {
3670
+ reject(new Error(`Timeout waiting for global: ${globalName}`));
3671
+ return;
3672
+ }
3673
+ setTimeout(checkGlobal, 100);
3674
+ }
3675
+ checkGlobal();
3676
+ });
3677
+ }
3678
+ async function waitForGlobals(globalNames, timeout = 5e3) {
3679
+ const promises = globalNames.map((name) => waitForGlobal(name, timeout));
3680
+ await Promise.all(promises);
3681
+ }
3682
+
3683
+ // src/Player.tsx
3601
3684
  var import_jsx_runtime8 = require("react/jsx-runtime");
3602
3685
  var Player = (0, import_react12.forwardRef)(
3603
3686
  ({
@@ -3620,12 +3703,13 @@ var Player = (0, import_react12.forwardRef)(
3620
3703
  seekbarConfig,
3621
3704
  iconSizes,
3622
3705
  events,
3706
+ locale = "en",
3623
3707
  containerClassName,
3624
3708
  ...videoProps
3625
3709
  }, ref) => {
3626
- console.log("system73Config", system73Config);
3627
3710
  const videoRef = (0, import_react12.useRef)(null);
3628
3711
  const containerRef = (0, import_react12.useRef)(null);
3712
+ const [isScriptsLoaded, setIsScriptsLoaded] = (0, import_react12.useState)(false);
3629
3713
  (0, import_react12.useImperativeHandle)(ref, () => videoRef.current, []);
3630
3714
  const { playerRef, initializePlayer, destroyPlayer, isRetrying } = useShakaPlayer({
3631
3715
  src,
@@ -3676,7 +3760,8 @@ var Player = (0, import_react12.forwardRef)(
3676
3760
  seekbarConfig,
3677
3761
  events?.onSkipBack,
3678
3762
  events?.onSkipForward,
3679
- iconSizes
3763
+ iconSizes,
3764
+ locale
3680
3765
  );
3681
3766
  const { isLive, isVisible: isLiveBadgeVisible } = useLiveBadge(playerRef, {
3682
3767
  enabled: true,
@@ -3716,7 +3801,11 @@ var Player = (0, import_react12.forwardRef)(
3716
3801
  if (!imaConfig?.adTagUrl || !playerRef.current || !videoRef.current || !uiRef.current) {
3717
3802
  return;
3718
3803
  }
3719
- console.log("Initializing ads...");
3804
+ if (!window.google?.ima) {
3805
+ console.error("Google IMA SDK not available when trying to initialize ads");
3806
+ return;
3807
+ }
3808
+ console.log("Initializing ads with autoplay:", autoPlay);
3720
3809
  try {
3721
3810
  const player = playerRef.current;
3722
3811
  const video = videoRef.current;
@@ -3728,23 +3817,53 @@ var Player = (0, import_react12.forwardRef)(
3728
3817
  console.error("Ad manager not available");
3729
3818
  return;
3730
3819
  }
3731
- adManager.initClientSide(container, video);
3732
3820
  const google = window.google;
3821
+ let adsRenderingSettings = null;
3822
+ if (imaConfig.adsRenderingSettings) {
3823
+ adsRenderingSettings = imaConfig.adsRenderingSettings;
3824
+ } else if (autoPlay) {
3825
+ adsRenderingSettings = new google.ima.AdsRenderingSettings();
3826
+ adsRenderingSettings.restoreCustomPlaybackStateOnAdBreakComplete = true;
3827
+ }
3828
+ adManager.initClientSide(container, video, adsRenderingSettings);
3733
3829
  const adsRequest = new google.ima.AdsRequest();
3734
3830
  adsRequest.adTagUrl = imaConfig.adTagUrl;
3735
3831
  adManager.requestClientSideAds(adsRequest);
3736
- console.log("Ads requested with tag:", imaConfig.adTagUrl);
3832
+ console.log("Ads requested successfully with tag:", imaConfig.adTagUrl, "autoplay:", autoPlay);
3737
3833
  } catch (error) {
3738
3834
  console.error("Error initializing ads:", error);
3739
3835
  }
3740
- }, [imaConfig]);
3836
+ }, [imaConfig, autoPlay]);
3837
+ (0, import_react12.useEffect)(() => {
3838
+ const loadRequiredScripts = async () => {
3839
+ try {
3840
+ const scriptLoaders = getRequiredScriptLoaders(!!imaConfig?.adTagUrl, !!system73Config?.apiKey);
3841
+ await loadScripts(scriptLoaders);
3842
+ const globalsToWait = [];
3843
+ if (imaConfig?.adTagUrl) {
3844
+ globalsToWait.push("google");
3845
+ }
3846
+ if (system73Config?.apiKey) {
3847
+ globalsToWait.push("S73ShakaPlayerWrapper");
3848
+ }
3849
+ if (globalsToWait.length > 0) {
3850
+ await waitForGlobals(globalsToWait);
3851
+ }
3852
+ setIsScriptsLoaded(true);
3853
+ } catch (error) {
3854
+ console.error("Error loading required scripts:", error);
3855
+ setIsScriptsLoaded(true);
3856
+ }
3857
+ };
3858
+ loadRequiredScripts();
3859
+ }, [imaConfig?.adTagUrl, system73Config?.apiKey]);
3741
3860
  (0, import_react12.useEffect)(() => {
3742
3861
  const video = videoRef.current;
3743
- if (!video) return;
3862
+ if (!video || !isScriptsLoaded) return;
3744
3863
  const initialize = async () => {
3745
3864
  try {
3746
3865
  let system73Wrapper = null;
3747
- if (system73Config?.apiKey) {
3866
+ if (system73Config?.apiKey && window.S73ShakaPlayerWrapper) {
3748
3867
  const playerConfig = { ...shakaConfig };
3749
3868
  system73Wrapper = initializeSystem73(playerConfig);
3750
3869
  if (system73Wrapper) {
@@ -3760,7 +3879,8 @@ var Player = (0, import_react12.forwardRef)(
3760
3879
  const cleanupQuality = setupQualityTracking();
3761
3880
  configureQuality();
3762
3881
  await initializeUI();
3763
- if (imaConfig) {
3882
+ if (imaConfig?.adTagUrl && window.google?.ima) {
3883
+ console.log("Initializing ads immediately after UI setup");
3764
3884
  initializeAds();
3765
3885
  }
3766
3886
  } catch (error) {
@@ -3775,16 +3895,15 @@ var Player = (0, import_react12.forwardRef)(
3775
3895
  destroyMux();
3776
3896
  destroyPlayer();
3777
3897
  };
3778
- }, [src]);
3898
+ }, [src, isScriptsLoaded]);
3779
3899
  (0, import_react12.useEffect)(() => {
3780
3900
  const video = videoRef.current;
3781
3901
  if (!video) return;
3782
3902
  video.autoplay = autoPlay;
3783
3903
  video.loop = loop;
3784
- video.muted = muted;
3785
3904
  video.controls = false;
3786
3905
  if (poster) video.poster = poster;
3787
- }, [autoPlay, loop, muted, poster]);
3906
+ }, [autoPlay, loop, muted, poster, imaConfig?.adTagUrl]);
3788
3907
  (0, import_react12.useEffect)(() => {
3789
3908
  const video = videoRef.current;
3790
3909
  if (!video) return;
@@ -4413,6 +4532,7 @@ var Video = ({
4413
4532
  src: activePlaylist,
4414
4533
  className: (0, import_tailwind_merge3.twMerge)("video-player-container", className),
4415
4534
  events,
4535
+ locale,
4416
4536
  containerClassName: "w-full h-full",
4417
4537
  children
4418
4538
  }
@@ -4581,6 +4701,7 @@ var Event = ({
4581
4701
  src: activePlaylist,
4582
4702
  className: (0, import_tailwind_merge4.twMerge)(className, "peer"),
4583
4703
  events,
4704
+ locale,
4584
4705
  containerClassName: "w-full h-full"
4585
4706
  }
4586
4707
  ) }),
@@ -4936,6 +5057,7 @@ var CreativeWork = ({
4936
5057
  ...events
4937
5058
  },
4938
5059
  src: activePlaylist,
5060
+ locale,
4939
5061
  containerClassName: "w-full h-full"
4940
5062
  }
4941
5063
  ),