@hyve-sdk/js 1.5.0 → 1.5.1

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
@@ -200,6 +200,16 @@ declare class AdsService {
200
200
  * Show an ad break
201
201
  */
202
202
  private showAdBreak;
203
+ /**
204
+ * Returns the configured ad lifecycle callbacks.
205
+ * Used by platform-specific ad providers (e.g. Playgama) to fire the same
206
+ * onBeforeAd / onAfterAd / onRewardEarned hooks that the Google H5 path uses.
207
+ */
208
+ getCallbacks(): {
209
+ onBeforeAd: (type: AdType) => void;
210
+ onAfterAd: (type: AdType) => void;
211
+ onRewardEarned: () => void;
212
+ };
203
213
  /**
204
214
  * Check if ads are enabled
205
215
  */
@@ -444,6 +454,7 @@ declare class HyveClient {
444
454
  private gameId;
445
455
  private adsService;
446
456
  private playgamaService;
457
+ private playgamaInitPromise;
447
458
  private billingService;
448
459
  private billingConfig;
449
460
  private billingCallbacks;
@@ -688,6 +699,8 @@ declare class HyveClient {
688
699
  */
689
700
 
690
701
  interface PlaygamaBridgeAdvertisement {
702
+ isInterstitialSupported: boolean;
703
+ isRewardedSupported: boolean;
691
704
  interstitialState: string;
692
705
  rewardedState: string;
693
706
  showInterstitial(placement?: string): void;
@@ -698,6 +711,11 @@ interface PlaygamaBridgeAdvertisement {
698
711
  interface PlaygamaBridge {
699
712
  initialize(): Promise<void>;
700
713
  advertisement: PlaygamaBridgeAdvertisement;
714
+ EVENT_NAME: {
715
+ INTERSTITIAL_STATE_CHANGED: string;
716
+ REWARDED_STATE_CHANGED: string;
717
+ [key: string]: string;
718
+ };
701
719
  }
702
720
  declare global {
703
721
  interface Window {
@@ -718,8 +736,15 @@ declare class PlaygamaService {
718
736
  */
719
737
  initialize(): Promise<boolean>;
720
738
  isInitialized(): boolean;
721
- showInterstitial(): Promise<AdResult>;
722
- showRewarded(): Promise<AdResult>;
739
+ showInterstitial(callbacks?: {
740
+ onBeforeAd?: () => void;
741
+ onAfterAd?: () => void;
742
+ }): Promise<AdResult>;
743
+ showRewarded(callbacks?: {
744
+ onBeforeAd?: () => void;
745
+ onAfterAd?: () => void;
746
+ onRewardEarned?: () => void;
747
+ }): Promise<AdResult>;
723
748
  private loadScript;
724
749
  }
725
750
 
package/dist/index.d.ts CHANGED
@@ -200,6 +200,16 @@ declare class AdsService {
200
200
  * Show an ad break
201
201
  */
202
202
  private showAdBreak;
203
+ /**
204
+ * Returns the configured ad lifecycle callbacks.
205
+ * Used by platform-specific ad providers (e.g. Playgama) to fire the same
206
+ * onBeforeAd / onAfterAd / onRewardEarned hooks that the Google H5 path uses.
207
+ */
208
+ getCallbacks(): {
209
+ onBeforeAd: (type: AdType) => void;
210
+ onAfterAd: (type: AdType) => void;
211
+ onRewardEarned: () => void;
212
+ };
203
213
  /**
204
214
  * Check if ads are enabled
205
215
  */
@@ -444,6 +454,7 @@ declare class HyveClient {
444
454
  private gameId;
445
455
  private adsService;
446
456
  private playgamaService;
457
+ private playgamaInitPromise;
447
458
  private billingService;
448
459
  private billingConfig;
449
460
  private billingCallbacks;
@@ -688,6 +699,8 @@ declare class HyveClient {
688
699
  */
689
700
 
690
701
  interface PlaygamaBridgeAdvertisement {
702
+ isInterstitialSupported: boolean;
703
+ isRewardedSupported: boolean;
691
704
  interstitialState: string;
692
705
  rewardedState: string;
693
706
  showInterstitial(placement?: string): void;
@@ -698,6 +711,11 @@ interface PlaygamaBridgeAdvertisement {
698
711
  interface PlaygamaBridge {
699
712
  initialize(): Promise<void>;
700
713
  advertisement: PlaygamaBridgeAdvertisement;
714
+ EVENT_NAME: {
715
+ INTERSTITIAL_STATE_CHANGED: string;
716
+ REWARDED_STATE_CHANGED: string;
717
+ [key: string]: string;
718
+ };
701
719
  }
702
720
  declare global {
703
721
  interface Window {
@@ -718,8 +736,15 @@ declare class PlaygamaService {
718
736
  */
719
737
  initialize(): Promise<boolean>;
720
738
  isInitialized(): boolean;
721
- showInterstitial(): Promise<AdResult>;
722
- showRewarded(): Promise<AdResult>;
739
+ showInterstitial(callbacks?: {
740
+ onBeforeAd?: () => void;
741
+ onAfterAd?: () => void;
742
+ }): Promise<AdResult>;
743
+ showRewarded(callbacks?: {
744
+ onBeforeAd?: () => void;
745
+ onAfterAd?: () => void;
746
+ onRewardEarned?: () => void;
747
+ }): Promise<AdResult>;
723
748
  private loadScript;
724
749
  }
725
750
 
package/dist/index.js CHANGED
@@ -786,6 +786,18 @@ var AdsService = class {
786
786
  window.adBreak(adBreakConfig);
787
787
  });
788
788
  }
789
+ /**
790
+ * Returns the configured ad lifecycle callbacks.
791
+ * Used by platform-specific ad providers (e.g. Playgama) to fire the same
792
+ * onBeforeAd / onAfterAd / onRewardEarned hooks that the Google H5 path uses.
793
+ */
794
+ getCallbacks() {
795
+ return {
796
+ onBeforeAd: this.config.onBeforeAd,
797
+ onAfterAd: this.config.onAfterAd,
798
+ onRewardEarned: this.config.onRewardEarned
799
+ };
800
+ }
789
801
  /**
790
802
  * Check if ads are enabled
791
803
  */
@@ -850,9 +862,10 @@ var PlaygamaService = class {
850
862
  isInitialized() {
851
863
  return this.initialized;
852
864
  }
853
- async showInterstitial() {
865
+ async showInterstitial(callbacks) {
854
866
  const requestedAt = Date.now();
855
- if (!this.initialized || !window.bridge) {
867
+ const bridge = window.bridge;
868
+ if (!this.initialized || !bridge) {
856
869
  return {
857
870
  success: false,
858
871
  type: "interstitial",
@@ -861,13 +874,26 @@ var PlaygamaService = class {
861
874
  completedAt: Date.now()
862
875
  };
863
876
  }
877
+ if (!bridge.advertisement.isInterstitialSupported) {
878
+ return {
879
+ success: false,
880
+ type: "interstitial",
881
+ error: new Error("Interstitial ads not supported on this platform"),
882
+ requestedAt,
883
+ completedAt: Date.now()
884
+ };
885
+ }
864
886
  return new Promise((resolve) => {
865
887
  const handler = (state) => {
866
- if (state === "closed") {
867
- window.bridge.advertisement.off("interstitial_state_changed", handler);
888
+ if (state === "opened") {
889
+ callbacks?.onBeforeAd?.();
890
+ } else if (state === "closed") {
891
+ bridge.advertisement.off(bridge.EVENT_NAME.INTERSTITIAL_STATE_CHANGED, handler);
892
+ callbacks?.onAfterAd?.();
868
893
  resolve({ success: true, type: "interstitial", requestedAt, completedAt: Date.now() });
869
894
  } else if (state === "failed") {
870
- window.bridge.advertisement.off("interstitial_state_changed", handler);
895
+ bridge.advertisement.off(bridge.EVENT_NAME.INTERSTITIAL_STATE_CHANGED, handler);
896
+ callbacks?.onAfterAd?.();
871
897
  resolve({
872
898
  success: false,
873
899
  type: "interstitial",
@@ -877,13 +903,14 @@ var PlaygamaService = class {
877
903
  });
878
904
  }
879
905
  };
880
- window.bridge.advertisement.on("interstitial_state_changed", handler);
881
- window.bridge.advertisement.showInterstitial();
906
+ bridge.advertisement.on(bridge.EVENT_NAME.INTERSTITIAL_STATE_CHANGED, handler);
907
+ bridge.advertisement.showInterstitial();
882
908
  });
883
909
  }
884
- async showRewarded() {
910
+ async showRewarded(callbacks) {
885
911
  const requestedAt = Date.now();
886
- if (!this.initialized || !window.bridge) {
912
+ const bridge = window.bridge;
913
+ if (!this.initialized || !bridge) {
887
914
  return {
888
915
  success: false,
889
916
  type: "rewarded",
@@ -892,13 +919,26 @@ var PlaygamaService = class {
892
919
  completedAt: Date.now()
893
920
  };
894
921
  }
922
+ if (!bridge.advertisement.isRewardedSupported) {
923
+ return {
924
+ success: false,
925
+ type: "rewarded",
926
+ error: new Error("Rewarded ads not supported on this platform"),
927
+ requestedAt,
928
+ completedAt: Date.now()
929
+ };
930
+ }
895
931
  return new Promise((resolve) => {
896
932
  let rewarded = false;
897
933
  const handler = (state) => {
898
- if (state === "rewarded") {
934
+ if (state === "opened") {
935
+ callbacks?.onBeforeAd?.();
936
+ } else if (state === "rewarded") {
899
937
  rewarded = true;
938
+ callbacks?.onRewardEarned?.();
900
939
  } else if (state === "closed" || state === "failed") {
901
- window.bridge.advertisement.off("rewarded_state_changed", handler);
940
+ bridge.advertisement.off(bridge.EVENT_NAME.REWARDED_STATE_CHANGED, handler);
941
+ callbacks?.onAfterAd?.();
902
942
  resolve({
903
943
  success: rewarded,
904
944
  type: "rewarded",
@@ -908,8 +948,8 @@ var PlaygamaService = class {
908
948
  });
909
949
  }
910
950
  };
911
- window.bridge.advertisement.on("rewarded_state_changed", handler);
912
- window.bridge.advertisement.showRewarded();
951
+ bridge.advertisement.on(bridge.EVENT_NAME.REWARDED_STATE_CHANGED, handler);
952
+ bridge.advertisement.showRewarded();
913
953
  });
914
954
  }
915
955
  loadScript() {
@@ -1639,6 +1679,7 @@ var HyveClient = class {
1639
1679
  gameId = null;
1640
1680
  adsService;
1641
1681
  playgamaService = null;
1682
+ playgamaInitPromise = null;
1642
1683
  billingService;
1643
1684
  billingConfig;
1644
1685
  // Store callbacks to preserve them when recreating BillingService
@@ -1668,8 +1709,9 @@ var HyveClient = class {
1668
1709
  }
1669
1710
  if (typeof window !== "undefined" && PlaygamaService.isPlaygamaDomain()) {
1670
1711
  this.playgamaService = new PlaygamaService();
1671
- this.playgamaService.initialize().then((success) => {
1712
+ this.playgamaInitPromise = this.playgamaService.initialize().then((success) => {
1672
1713
  logger.info("Playgama Bridge initialized:", success);
1714
+ return success;
1673
1715
  });
1674
1716
  }
1675
1717
  this.billingConfig = config?.billing || {};
@@ -2121,9 +2163,24 @@ var HyveClient = class {
2121
2163
  * @returns Promise resolving to ad result
2122
2164
  */
2123
2165
  async showAd(type) {
2124
- if (this.playgamaService?.isInitialized()) {
2125
- if (type === "rewarded") return this.playgamaService.showRewarded();
2126
- return this.playgamaService.showInterstitial();
2166
+ if (this.playgamaService) {
2167
+ if (this.playgamaInitPromise) {
2168
+ await this.playgamaInitPromise;
2169
+ }
2170
+ if (this.playgamaService.isInitialized()) {
2171
+ const { onBeforeAd, onAfterAd, onRewardEarned } = this.adsService.getCallbacks();
2172
+ if (type === "rewarded") {
2173
+ return this.playgamaService.showRewarded({
2174
+ onBeforeAd: () => onBeforeAd("rewarded"),
2175
+ onAfterAd: () => onAfterAd("rewarded"),
2176
+ onRewardEarned
2177
+ });
2178
+ }
2179
+ return this.playgamaService.showInterstitial({
2180
+ onBeforeAd: () => onBeforeAd(type),
2181
+ onAfterAd: () => onAfterAd(type)
2182
+ });
2183
+ }
2127
2184
  }
2128
2185
  return this.adsService.show(type);
2129
2186
  }
package/dist/index.mjs CHANGED
@@ -743,6 +743,18 @@ var AdsService = class {
743
743
  window.adBreak(adBreakConfig);
744
744
  });
745
745
  }
746
+ /**
747
+ * Returns the configured ad lifecycle callbacks.
748
+ * Used by platform-specific ad providers (e.g. Playgama) to fire the same
749
+ * onBeforeAd / onAfterAd / onRewardEarned hooks that the Google H5 path uses.
750
+ */
751
+ getCallbacks() {
752
+ return {
753
+ onBeforeAd: this.config.onBeforeAd,
754
+ onAfterAd: this.config.onAfterAd,
755
+ onRewardEarned: this.config.onRewardEarned
756
+ };
757
+ }
746
758
  /**
747
759
  * Check if ads are enabled
748
760
  */
@@ -807,9 +819,10 @@ var PlaygamaService = class {
807
819
  isInitialized() {
808
820
  return this.initialized;
809
821
  }
810
- async showInterstitial() {
822
+ async showInterstitial(callbacks) {
811
823
  const requestedAt = Date.now();
812
- if (!this.initialized || !window.bridge) {
824
+ const bridge = window.bridge;
825
+ if (!this.initialized || !bridge) {
813
826
  return {
814
827
  success: false,
815
828
  type: "interstitial",
@@ -818,13 +831,26 @@ var PlaygamaService = class {
818
831
  completedAt: Date.now()
819
832
  };
820
833
  }
834
+ if (!bridge.advertisement.isInterstitialSupported) {
835
+ return {
836
+ success: false,
837
+ type: "interstitial",
838
+ error: new Error("Interstitial ads not supported on this platform"),
839
+ requestedAt,
840
+ completedAt: Date.now()
841
+ };
842
+ }
821
843
  return new Promise((resolve) => {
822
844
  const handler = (state) => {
823
- if (state === "closed") {
824
- window.bridge.advertisement.off("interstitial_state_changed", handler);
845
+ if (state === "opened") {
846
+ callbacks?.onBeforeAd?.();
847
+ } else if (state === "closed") {
848
+ bridge.advertisement.off(bridge.EVENT_NAME.INTERSTITIAL_STATE_CHANGED, handler);
849
+ callbacks?.onAfterAd?.();
825
850
  resolve({ success: true, type: "interstitial", requestedAt, completedAt: Date.now() });
826
851
  } else if (state === "failed") {
827
- window.bridge.advertisement.off("interstitial_state_changed", handler);
852
+ bridge.advertisement.off(bridge.EVENT_NAME.INTERSTITIAL_STATE_CHANGED, handler);
853
+ callbacks?.onAfterAd?.();
828
854
  resolve({
829
855
  success: false,
830
856
  type: "interstitial",
@@ -834,13 +860,14 @@ var PlaygamaService = class {
834
860
  });
835
861
  }
836
862
  };
837
- window.bridge.advertisement.on("interstitial_state_changed", handler);
838
- window.bridge.advertisement.showInterstitial();
863
+ bridge.advertisement.on(bridge.EVENT_NAME.INTERSTITIAL_STATE_CHANGED, handler);
864
+ bridge.advertisement.showInterstitial();
839
865
  });
840
866
  }
841
- async showRewarded() {
867
+ async showRewarded(callbacks) {
842
868
  const requestedAt = Date.now();
843
- if (!this.initialized || !window.bridge) {
869
+ const bridge = window.bridge;
870
+ if (!this.initialized || !bridge) {
844
871
  return {
845
872
  success: false,
846
873
  type: "rewarded",
@@ -849,13 +876,26 @@ var PlaygamaService = class {
849
876
  completedAt: Date.now()
850
877
  };
851
878
  }
879
+ if (!bridge.advertisement.isRewardedSupported) {
880
+ return {
881
+ success: false,
882
+ type: "rewarded",
883
+ error: new Error("Rewarded ads not supported on this platform"),
884
+ requestedAt,
885
+ completedAt: Date.now()
886
+ };
887
+ }
852
888
  return new Promise((resolve) => {
853
889
  let rewarded = false;
854
890
  const handler = (state) => {
855
- if (state === "rewarded") {
891
+ if (state === "opened") {
892
+ callbacks?.onBeforeAd?.();
893
+ } else if (state === "rewarded") {
856
894
  rewarded = true;
895
+ callbacks?.onRewardEarned?.();
857
896
  } else if (state === "closed" || state === "failed") {
858
- window.bridge.advertisement.off("rewarded_state_changed", handler);
897
+ bridge.advertisement.off(bridge.EVENT_NAME.REWARDED_STATE_CHANGED, handler);
898
+ callbacks?.onAfterAd?.();
859
899
  resolve({
860
900
  success: rewarded,
861
901
  type: "rewarded",
@@ -865,8 +905,8 @@ var PlaygamaService = class {
865
905
  });
866
906
  }
867
907
  };
868
- window.bridge.advertisement.on("rewarded_state_changed", handler);
869
- window.bridge.advertisement.showRewarded();
908
+ bridge.advertisement.on(bridge.EVENT_NAME.REWARDED_STATE_CHANGED, handler);
909
+ bridge.advertisement.showRewarded();
870
910
  });
871
911
  }
872
912
  loadScript() {
@@ -1596,6 +1636,7 @@ var HyveClient = class {
1596
1636
  gameId = null;
1597
1637
  adsService;
1598
1638
  playgamaService = null;
1639
+ playgamaInitPromise = null;
1599
1640
  billingService;
1600
1641
  billingConfig;
1601
1642
  // Store callbacks to preserve them when recreating BillingService
@@ -1625,8 +1666,9 @@ var HyveClient = class {
1625
1666
  }
1626
1667
  if (typeof window !== "undefined" && PlaygamaService.isPlaygamaDomain()) {
1627
1668
  this.playgamaService = new PlaygamaService();
1628
- this.playgamaService.initialize().then((success) => {
1669
+ this.playgamaInitPromise = this.playgamaService.initialize().then((success) => {
1629
1670
  logger.info("Playgama Bridge initialized:", success);
1671
+ return success;
1630
1672
  });
1631
1673
  }
1632
1674
  this.billingConfig = config?.billing || {};
@@ -2078,9 +2120,24 @@ var HyveClient = class {
2078
2120
  * @returns Promise resolving to ad result
2079
2121
  */
2080
2122
  async showAd(type) {
2081
- if (this.playgamaService?.isInitialized()) {
2082
- if (type === "rewarded") return this.playgamaService.showRewarded();
2083
- return this.playgamaService.showInterstitial();
2123
+ if (this.playgamaService) {
2124
+ if (this.playgamaInitPromise) {
2125
+ await this.playgamaInitPromise;
2126
+ }
2127
+ if (this.playgamaService.isInitialized()) {
2128
+ const { onBeforeAd, onAfterAd, onRewardEarned } = this.adsService.getCallbacks();
2129
+ if (type === "rewarded") {
2130
+ return this.playgamaService.showRewarded({
2131
+ onBeforeAd: () => onBeforeAd("rewarded"),
2132
+ onAfterAd: () => onAfterAd("rewarded"),
2133
+ onRewardEarned
2134
+ });
2135
+ }
2136
+ return this.playgamaService.showInterstitial({
2137
+ onBeforeAd: () => onBeforeAd(type),
2138
+ onAfterAd: () => onAfterAd(type)
2139
+ });
2140
+ }
2084
2141
  }
2085
2142
  return this.adsService.show(type);
2086
2143
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyve-sdk/js",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "Hyve SDK - TypeScript wrapper for Hyve game server integration",
5
5
  "private": false,
6
6
  "publishConfig": {