@hyve-sdk/js 1.4.1 → 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 +75 -1
- package/dist/index.d.ts +75 -1
- package/dist/index.js +198 -0
- package/dist/index.mjs +197 -0
- package/package.json +1 -1
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
|
*/
|
|
@@ -443,6 +453,8 @@ declare class HyveClient {
|
|
|
443
453
|
private jwtToken;
|
|
444
454
|
private gameId;
|
|
445
455
|
private adsService;
|
|
456
|
+
private playgamaService;
|
|
457
|
+
private playgamaInitPromise;
|
|
446
458
|
private billingService;
|
|
447
459
|
private billingConfig;
|
|
448
460
|
private billingCallbacks;
|
|
@@ -674,6 +686,68 @@ declare class HyveClient {
|
|
|
674
686
|
onBillingLog(callback: (level: "info" | "warn" | "error", message: string, data?: any) => void): void;
|
|
675
687
|
}
|
|
676
688
|
|
|
689
|
+
/**
|
|
690
|
+
* Playgama Bridge integration service
|
|
691
|
+
*
|
|
692
|
+
* Loads and initializes the Playgama Bridge SDK when running on a Playgama domain.
|
|
693
|
+
* The bridge SDK is loaded from CDN and exposes a global `window.bridge` object.
|
|
694
|
+
*
|
|
695
|
+
* Detection: Playgama games receive a `platform_id=playgama` URL parameter when
|
|
696
|
+
* embedded on the platform.
|
|
697
|
+
*
|
|
698
|
+
* @packageDocumentation
|
|
699
|
+
*/
|
|
700
|
+
|
|
701
|
+
interface PlaygamaBridgeAdvertisement {
|
|
702
|
+
isInterstitialSupported: boolean;
|
|
703
|
+
isRewardedSupported: boolean;
|
|
704
|
+
interstitialState: string;
|
|
705
|
+
rewardedState: string;
|
|
706
|
+
showInterstitial(placement?: string): void;
|
|
707
|
+
showRewarded(placement?: string): void;
|
|
708
|
+
on(event: string, callback: (state: string) => void): void;
|
|
709
|
+
off(event: string, callback: (state: string) => void): void;
|
|
710
|
+
}
|
|
711
|
+
interface PlaygamaBridge {
|
|
712
|
+
initialize(): Promise<void>;
|
|
713
|
+
advertisement: PlaygamaBridgeAdvertisement;
|
|
714
|
+
EVENT_NAME: {
|
|
715
|
+
INTERSTITIAL_STATE_CHANGED: string;
|
|
716
|
+
REWARDED_STATE_CHANGED: string;
|
|
717
|
+
[key: string]: string;
|
|
718
|
+
};
|
|
719
|
+
}
|
|
720
|
+
declare global {
|
|
721
|
+
interface Window {
|
|
722
|
+
bridge?: PlaygamaBridge;
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
declare class PlaygamaService {
|
|
726
|
+
private initialized;
|
|
727
|
+
/**
|
|
728
|
+
* Detects if the game is running on the Playgama platform.
|
|
729
|
+
* Playgama injects a `platform_id=playgama` URL parameter into the game URL.
|
|
730
|
+
* Falls back to checking document.referrer for playgama.com.
|
|
731
|
+
*/
|
|
732
|
+
static isPlaygamaDomain(): boolean;
|
|
733
|
+
/**
|
|
734
|
+
* Loads the Playgama Bridge script from CDN and initializes it.
|
|
735
|
+
* Safe to call multiple times - resolves immediately if already initialized.
|
|
736
|
+
*/
|
|
737
|
+
initialize(): Promise<boolean>;
|
|
738
|
+
isInitialized(): boolean;
|
|
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>;
|
|
748
|
+
private loadScript;
|
|
749
|
+
}
|
|
750
|
+
|
|
677
751
|
/**
|
|
678
752
|
* Storage adapter interface - supports cloud and local implementations
|
|
679
753
|
*/
|
|
@@ -988,4 +1062,4 @@ declare class NativeBridge {
|
|
|
988
1062
|
*/
|
|
989
1063
|
declare function generateUUID(): string;
|
|
990
1064
|
|
|
991
|
-
export { type AdConfig$1 as AdConfig, type AdResult, type AdType, AdsService, type BillingConfig, BillingPlatform, type BillingProduct, BillingService, CloudStorageAdapter, type DeleteGameDataResponse, type GameDataBatchItem, type GameDataItem, type GameDataValue, type GetGameDataBatchResponse, type GetGameDataResponse, HyveClient, type HyveClientConfig, type Inventory, type InventoryItem, LocalStorageAdapter, Logger, NativeBridge, type NativeMessage, type NativeMessageHandler, NativeMessageType, type PurchaseResult, type SaveGameDataResponse, type StorageAdapter, type TelemetryAdditionalData, type TelemetryConfig, type TelemetryEvent, generateUUID, handleVerifyMessage, isDomainAllowed, logger, parseUrlParams, validateSignature, verifyAuthentication, verifyHyveToken };
|
|
1065
|
+
export { type AdConfig$1 as AdConfig, type AdResult, type AdType, AdsService, type BillingConfig, BillingPlatform, type BillingProduct, BillingService, CloudStorageAdapter, type DeleteGameDataResponse, type GameDataBatchItem, type GameDataItem, type GameDataValue, type GetGameDataBatchResponse, type GetGameDataResponse, HyveClient, type HyveClientConfig, type Inventory, type InventoryItem, LocalStorageAdapter, Logger, NativeBridge, type NativeMessage, type NativeMessageHandler, NativeMessageType, PlaygamaService, type PurchaseResult, type SaveGameDataResponse, type StorageAdapter, type TelemetryAdditionalData, type TelemetryConfig, type TelemetryEvent, generateUUID, handleVerifyMessage, isDomainAllowed, logger, parseUrlParams, validateSignature, verifyAuthentication, verifyHyveToken };
|
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
|
*/
|
|
@@ -443,6 +453,8 @@ declare class HyveClient {
|
|
|
443
453
|
private jwtToken;
|
|
444
454
|
private gameId;
|
|
445
455
|
private adsService;
|
|
456
|
+
private playgamaService;
|
|
457
|
+
private playgamaInitPromise;
|
|
446
458
|
private billingService;
|
|
447
459
|
private billingConfig;
|
|
448
460
|
private billingCallbacks;
|
|
@@ -674,6 +686,68 @@ declare class HyveClient {
|
|
|
674
686
|
onBillingLog(callback: (level: "info" | "warn" | "error", message: string, data?: any) => void): void;
|
|
675
687
|
}
|
|
676
688
|
|
|
689
|
+
/**
|
|
690
|
+
* Playgama Bridge integration service
|
|
691
|
+
*
|
|
692
|
+
* Loads and initializes the Playgama Bridge SDK when running on a Playgama domain.
|
|
693
|
+
* The bridge SDK is loaded from CDN and exposes a global `window.bridge` object.
|
|
694
|
+
*
|
|
695
|
+
* Detection: Playgama games receive a `platform_id=playgama` URL parameter when
|
|
696
|
+
* embedded on the platform.
|
|
697
|
+
*
|
|
698
|
+
* @packageDocumentation
|
|
699
|
+
*/
|
|
700
|
+
|
|
701
|
+
interface PlaygamaBridgeAdvertisement {
|
|
702
|
+
isInterstitialSupported: boolean;
|
|
703
|
+
isRewardedSupported: boolean;
|
|
704
|
+
interstitialState: string;
|
|
705
|
+
rewardedState: string;
|
|
706
|
+
showInterstitial(placement?: string): void;
|
|
707
|
+
showRewarded(placement?: string): void;
|
|
708
|
+
on(event: string, callback: (state: string) => void): void;
|
|
709
|
+
off(event: string, callback: (state: string) => void): void;
|
|
710
|
+
}
|
|
711
|
+
interface PlaygamaBridge {
|
|
712
|
+
initialize(): Promise<void>;
|
|
713
|
+
advertisement: PlaygamaBridgeAdvertisement;
|
|
714
|
+
EVENT_NAME: {
|
|
715
|
+
INTERSTITIAL_STATE_CHANGED: string;
|
|
716
|
+
REWARDED_STATE_CHANGED: string;
|
|
717
|
+
[key: string]: string;
|
|
718
|
+
};
|
|
719
|
+
}
|
|
720
|
+
declare global {
|
|
721
|
+
interface Window {
|
|
722
|
+
bridge?: PlaygamaBridge;
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
declare class PlaygamaService {
|
|
726
|
+
private initialized;
|
|
727
|
+
/**
|
|
728
|
+
* Detects if the game is running on the Playgama platform.
|
|
729
|
+
* Playgama injects a `platform_id=playgama` URL parameter into the game URL.
|
|
730
|
+
* Falls back to checking document.referrer for playgama.com.
|
|
731
|
+
*/
|
|
732
|
+
static isPlaygamaDomain(): boolean;
|
|
733
|
+
/**
|
|
734
|
+
* Loads the Playgama Bridge script from CDN and initializes it.
|
|
735
|
+
* Safe to call multiple times - resolves immediately if already initialized.
|
|
736
|
+
*/
|
|
737
|
+
initialize(): Promise<boolean>;
|
|
738
|
+
isInitialized(): boolean;
|
|
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>;
|
|
748
|
+
private loadScript;
|
|
749
|
+
}
|
|
750
|
+
|
|
677
751
|
/**
|
|
678
752
|
* Storage adapter interface - supports cloud and local implementations
|
|
679
753
|
*/
|
|
@@ -988,4 +1062,4 @@ declare class NativeBridge {
|
|
|
988
1062
|
*/
|
|
989
1063
|
declare function generateUUID(): string;
|
|
990
1064
|
|
|
991
|
-
export { type AdConfig$1 as AdConfig, type AdResult, type AdType, AdsService, type BillingConfig, BillingPlatform, type BillingProduct, BillingService, CloudStorageAdapter, type DeleteGameDataResponse, type GameDataBatchItem, type GameDataItem, type GameDataValue, type GetGameDataBatchResponse, type GetGameDataResponse, HyveClient, type HyveClientConfig, type Inventory, type InventoryItem, LocalStorageAdapter, Logger, NativeBridge, type NativeMessage, type NativeMessageHandler, NativeMessageType, type PurchaseResult, type SaveGameDataResponse, type StorageAdapter, type TelemetryAdditionalData, type TelemetryConfig, type TelemetryEvent, generateUUID, handleVerifyMessage, isDomainAllowed, logger, parseUrlParams, validateSignature, verifyAuthentication, verifyHyveToken };
|
|
1065
|
+
export { type AdConfig$1 as AdConfig, type AdResult, type AdType, AdsService, type BillingConfig, BillingPlatform, type BillingProduct, BillingService, CloudStorageAdapter, type DeleteGameDataResponse, type GameDataBatchItem, type GameDataItem, type GameDataValue, type GetGameDataBatchResponse, type GetGameDataResponse, HyveClient, type HyveClientConfig, type Inventory, type InventoryItem, LocalStorageAdapter, Logger, NativeBridge, type NativeMessage, type NativeMessageHandler, NativeMessageType, PlaygamaService, type PurchaseResult, type SaveGameDataResponse, type StorageAdapter, type TelemetryAdditionalData, type TelemetryConfig, type TelemetryEvent, generateUUID, handleVerifyMessage, isDomainAllowed, logger, parseUrlParams, validateSignature, verifyAuthentication, verifyHyveToken };
|
package/dist/index.js
CHANGED
|
@@ -29,6 +29,7 @@ __export(index_exports, {
|
|
|
29
29
|
Logger: () => Logger,
|
|
30
30
|
NativeBridge: () => NativeBridge,
|
|
31
31
|
NativeMessageType: () => NativeMessageType,
|
|
32
|
+
PlaygamaService: () => PlaygamaService,
|
|
32
33
|
generateUUID: () => generateUUID,
|
|
33
34
|
handleVerifyMessage: () => handleVerifyMessage,
|
|
34
35
|
isDomainAllowed: () => isDomainAllowed,
|
|
@@ -785,6 +786,18 @@ var AdsService = class {
|
|
|
785
786
|
window.adBreak(adBreakConfig);
|
|
786
787
|
});
|
|
787
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
|
+
}
|
|
788
801
|
/**
|
|
789
802
|
* Check if ads are enabled
|
|
790
803
|
*/
|
|
@@ -799,6 +812,161 @@ var AdsService = class {
|
|
|
799
812
|
}
|
|
800
813
|
};
|
|
801
814
|
|
|
815
|
+
// src/services/playgama.ts
|
|
816
|
+
var PLAYGAMA_BRIDGE_CDN = "https://bridge.playgama.com/v1/stable/playgama-bridge.js";
|
|
817
|
+
var PlaygamaService = class {
|
|
818
|
+
initialized = false;
|
|
819
|
+
/**
|
|
820
|
+
* Detects if the game is running on the Playgama platform.
|
|
821
|
+
* Playgama injects a `platform_id=playgama` URL parameter into the game URL.
|
|
822
|
+
* Falls back to checking document.referrer for playgama.com.
|
|
823
|
+
*/
|
|
824
|
+
static isPlaygamaDomain() {
|
|
825
|
+
try {
|
|
826
|
+
const url = new URL(window.location.href);
|
|
827
|
+
if (url.searchParams.get("platform_id") === "playgama") {
|
|
828
|
+
return true;
|
|
829
|
+
}
|
|
830
|
+
if (document.referrer.includes("playgama.com")) {
|
|
831
|
+
return true;
|
|
832
|
+
}
|
|
833
|
+
if (window !== window.top) {
|
|
834
|
+
try {
|
|
835
|
+
if (window.parent.location.hostname.includes("playgama.com")) {
|
|
836
|
+
return true;
|
|
837
|
+
}
|
|
838
|
+
} catch {
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
return false;
|
|
842
|
+
} catch {
|
|
843
|
+
return false;
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
/**
|
|
847
|
+
* Loads the Playgama Bridge script from CDN and initializes it.
|
|
848
|
+
* Safe to call multiple times - resolves immediately if already initialized.
|
|
849
|
+
*/
|
|
850
|
+
async initialize() {
|
|
851
|
+
if (this.initialized) return true;
|
|
852
|
+
try {
|
|
853
|
+
await this.loadScript();
|
|
854
|
+
await window.bridge.initialize();
|
|
855
|
+
this.initialized = true;
|
|
856
|
+
return true;
|
|
857
|
+
} catch (error) {
|
|
858
|
+
console.warn("[PlaygamaService] Failed to initialize:", error);
|
|
859
|
+
return false;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
isInitialized() {
|
|
863
|
+
return this.initialized;
|
|
864
|
+
}
|
|
865
|
+
async showInterstitial(callbacks) {
|
|
866
|
+
const requestedAt = Date.now();
|
|
867
|
+
const bridge = window.bridge;
|
|
868
|
+
if (!this.initialized || !bridge) {
|
|
869
|
+
return {
|
|
870
|
+
success: false,
|
|
871
|
+
type: "interstitial",
|
|
872
|
+
error: new Error("Playgama not initialized"),
|
|
873
|
+
requestedAt,
|
|
874
|
+
completedAt: Date.now()
|
|
875
|
+
};
|
|
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
|
+
}
|
|
886
|
+
return new Promise((resolve) => {
|
|
887
|
+
const handler = (state) => {
|
|
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?.();
|
|
893
|
+
resolve({ success: true, type: "interstitial", requestedAt, completedAt: Date.now() });
|
|
894
|
+
} else if (state === "failed") {
|
|
895
|
+
bridge.advertisement.off(bridge.EVENT_NAME.INTERSTITIAL_STATE_CHANGED, handler);
|
|
896
|
+
callbacks?.onAfterAd?.();
|
|
897
|
+
resolve({
|
|
898
|
+
success: false,
|
|
899
|
+
type: "interstitial",
|
|
900
|
+
error: new Error("Interstitial ad failed"),
|
|
901
|
+
requestedAt,
|
|
902
|
+
completedAt: Date.now()
|
|
903
|
+
});
|
|
904
|
+
}
|
|
905
|
+
};
|
|
906
|
+
bridge.advertisement.on(bridge.EVENT_NAME.INTERSTITIAL_STATE_CHANGED, handler);
|
|
907
|
+
bridge.advertisement.showInterstitial();
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
async showRewarded(callbacks) {
|
|
911
|
+
const requestedAt = Date.now();
|
|
912
|
+
const bridge = window.bridge;
|
|
913
|
+
if (!this.initialized || !bridge) {
|
|
914
|
+
return {
|
|
915
|
+
success: false,
|
|
916
|
+
type: "rewarded",
|
|
917
|
+
error: new Error("Playgama not initialized"),
|
|
918
|
+
requestedAt,
|
|
919
|
+
completedAt: Date.now()
|
|
920
|
+
};
|
|
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
|
+
}
|
|
931
|
+
return new Promise((resolve) => {
|
|
932
|
+
let rewarded = false;
|
|
933
|
+
const handler = (state) => {
|
|
934
|
+
if (state === "opened") {
|
|
935
|
+
callbacks?.onBeforeAd?.();
|
|
936
|
+
} else if (state === "rewarded") {
|
|
937
|
+
rewarded = true;
|
|
938
|
+
callbacks?.onRewardEarned?.();
|
|
939
|
+
} else if (state === "closed" || state === "failed") {
|
|
940
|
+
bridge.advertisement.off(bridge.EVENT_NAME.REWARDED_STATE_CHANGED, handler);
|
|
941
|
+
callbacks?.onAfterAd?.();
|
|
942
|
+
resolve({
|
|
943
|
+
success: rewarded,
|
|
944
|
+
type: "rewarded",
|
|
945
|
+
error: !rewarded ? new Error("Rewarded ad not completed") : void 0,
|
|
946
|
+
requestedAt,
|
|
947
|
+
completedAt: Date.now()
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
};
|
|
951
|
+
bridge.advertisement.on(bridge.EVENT_NAME.REWARDED_STATE_CHANGED, handler);
|
|
952
|
+
bridge.advertisement.showRewarded();
|
|
953
|
+
});
|
|
954
|
+
}
|
|
955
|
+
loadScript() {
|
|
956
|
+
return new Promise((resolve, reject) => {
|
|
957
|
+
if (window.bridge) {
|
|
958
|
+
resolve();
|
|
959
|
+
return;
|
|
960
|
+
}
|
|
961
|
+
const script = document.createElement("script");
|
|
962
|
+
script.src = PLAYGAMA_BRIDGE_CDN;
|
|
963
|
+
script.onload = () => resolve();
|
|
964
|
+
script.onerror = () => reject(new Error("Failed to load Playgama Bridge script"));
|
|
965
|
+
document.head.appendChild(script);
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
};
|
|
969
|
+
|
|
802
970
|
// src/services/billing.ts
|
|
803
971
|
var BillingPlatform = /* @__PURE__ */ ((BillingPlatform3) => {
|
|
804
972
|
BillingPlatform3["WEB"] = "web";
|
|
@@ -1510,6 +1678,8 @@ var HyveClient = class {
|
|
|
1510
1678
|
jwtToken = null;
|
|
1511
1679
|
gameId = null;
|
|
1512
1680
|
adsService;
|
|
1681
|
+
playgamaService = null;
|
|
1682
|
+
playgamaInitPromise = null;
|
|
1513
1683
|
billingService;
|
|
1514
1684
|
billingConfig;
|
|
1515
1685
|
// Store callbacks to preserve them when recreating BillingService
|
|
@@ -1537,6 +1707,13 @@ var HyveClient = class {
|
|
|
1537
1707
|
if (config?.ads) {
|
|
1538
1708
|
this.adsService.configure(config.ads);
|
|
1539
1709
|
}
|
|
1710
|
+
if (typeof window !== "undefined" && PlaygamaService.isPlaygamaDomain()) {
|
|
1711
|
+
this.playgamaService = new PlaygamaService();
|
|
1712
|
+
this.playgamaInitPromise = this.playgamaService.initialize().then((success) => {
|
|
1713
|
+
logger.info("Playgama Bridge initialized:", success);
|
|
1714
|
+
return success;
|
|
1715
|
+
});
|
|
1716
|
+
}
|
|
1540
1717
|
this.billingConfig = config?.billing || {};
|
|
1541
1718
|
this.billingService = new BillingService(this.billingConfig);
|
|
1542
1719
|
this.storageMode = config?.storageMode || "cloud";
|
|
@@ -1556,6 +1733,7 @@ var HyveClient = class {
|
|
|
1556
1733
|
);
|
|
1557
1734
|
logger.info("API Base URL:", this.apiBaseUrl);
|
|
1558
1735
|
logger.info("Ads enabled:", this.adsService.isEnabled());
|
|
1736
|
+
logger.info("Playgama platform:", this.playgamaService !== null);
|
|
1559
1737
|
logger.info(
|
|
1560
1738
|
"Billing configured:",
|
|
1561
1739
|
Object.keys(this.billingConfig).length > 0
|
|
@@ -1985,6 +2163,25 @@ var HyveClient = class {
|
|
|
1985
2163
|
* @returns Promise resolving to ad result
|
|
1986
2164
|
*/
|
|
1987
2165
|
async showAd(type) {
|
|
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
|
+
}
|
|
2184
|
+
}
|
|
1988
2185
|
return this.adsService.show(type);
|
|
1989
2186
|
}
|
|
1990
2187
|
/**
|
|
@@ -2114,6 +2311,7 @@ var HyveClient = class {
|
|
|
2114
2311
|
Logger,
|
|
2115
2312
|
NativeBridge,
|
|
2116
2313
|
NativeMessageType,
|
|
2314
|
+
PlaygamaService,
|
|
2117
2315
|
generateUUID,
|
|
2118
2316
|
handleVerifyMessage,
|
|
2119
2317
|
isDomainAllowed,
|
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
|
*/
|
|
@@ -757,6 +769,161 @@ var AdsService = class {
|
|
|
757
769
|
}
|
|
758
770
|
};
|
|
759
771
|
|
|
772
|
+
// src/services/playgama.ts
|
|
773
|
+
var PLAYGAMA_BRIDGE_CDN = "https://bridge.playgama.com/v1/stable/playgama-bridge.js";
|
|
774
|
+
var PlaygamaService = class {
|
|
775
|
+
initialized = false;
|
|
776
|
+
/**
|
|
777
|
+
* Detects if the game is running on the Playgama platform.
|
|
778
|
+
* Playgama injects a `platform_id=playgama` URL parameter into the game URL.
|
|
779
|
+
* Falls back to checking document.referrer for playgama.com.
|
|
780
|
+
*/
|
|
781
|
+
static isPlaygamaDomain() {
|
|
782
|
+
try {
|
|
783
|
+
const url = new URL(window.location.href);
|
|
784
|
+
if (url.searchParams.get("platform_id") === "playgama") {
|
|
785
|
+
return true;
|
|
786
|
+
}
|
|
787
|
+
if (document.referrer.includes("playgama.com")) {
|
|
788
|
+
return true;
|
|
789
|
+
}
|
|
790
|
+
if (window !== window.top) {
|
|
791
|
+
try {
|
|
792
|
+
if (window.parent.location.hostname.includes("playgama.com")) {
|
|
793
|
+
return true;
|
|
794
|
+
}
|
|
795
|
+
} catch {
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
return false;
|
|
799
|
+
} catch {
|
|
800
|
+
return false;
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* Loads the Playgama Bridge script from CDN and initializes it.
|
|
805
|
+
* Safe to call multiple times - resolves immediately if already initialized.
|
|
806
|
+
*/
|
|
807
|
+
async initialize() {
|
|
808
|
+
if (this.initialized) return true;
|
|
809
|
+
try {
|
|
810
|
+
await this.loadScript();
|
|
811
|
+
await window.bridge.initialize();
|
|
812
|
+
this.initialized = true;
|
|
813
|
+
return true;
|
|
814
|
+
} catch (error) {
|
|
815
|
+
console.warn("[PlaygamaService] Failed to initialize:", error);
|
|
816
|
+
return false;
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
isInitialized() {
|
|
820
|
+
return this.initialized;
|
|
821
|
+
}
|
|
822
|
+
async showInterstitial(callbacks) {
|
|
823
|
+
const requestedAt = Date.now();
|
|
824
|
+
const bridge = window.bridge;
|
|
825
|
+
if (!this.initialized || !bridge) {
|
|
826
|
+
return {
|
|
827
|
+
success: false,
|
|
828
|
+
type: "interstitial",
|
|
829
|
+
error: new Error("Playgama not initialized"),
|
|
830
|
+
requestedAt,
|
|
831
|
+
completedAt: Date.now()
|
|
832
|
+
};
|
|
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
|
+
}
|
|
843
|
+
return new Promise((resolve) => {
|
|
844
|
+
const handler = (state) => {
|
|
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?.();
|
|
850
|
+
resolve({ success: true, type: "interstitial", requestedAt, completedAt: Date.now() });
|
|
851
|
+
} else if (state === "failed") {
|
|
852
|
+
bridge.advertisement.off(bridge.EVENT_NAME.INTERSTITIAL_STATE_CHANGED, handler);
|
|
853
|
+
callbacks?.onAfterAd?.();
|
|
854
|
+
resolve({
|
|
855
|
+
success: false,
|
|
856
|
+
type: "interstitial",
|
|
857
|
+
error: new Error("Interstitial ad failed"),
|
|
858
|
+
requestedAt,
|
|
859
|
+
completedAt: Date.now()
|
|
860
|
+
});
|
|
861
|
+
}
|
|
862
|
+
};
|
|
863
|
+
bridge.advertisement.on(bridge.EVENT_NAME.INTERSTITIAL_STATE_CHANGED, handler);
|
|
864
|
+
bridge.advertisement.showInterstitial();
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
async showRewarded(callbacks) {
|
|
868
|
+
const requestedAt = Date.now();
|
|
869
|
+
const bridge = window.bridge;
|
|
870
|
+
if (!this.initialized || !bridge) {
|
|
871
|
+
return {
|
|
872
|
+
success: false,
|
|
873
|
+
type: "rewarded",
|
|
874
|
+
error: new Error("Playgama not initialized"),
|
|
875
|
+
requestedAt,
|
|
876
|
+
completedAt: Date.now()
|
|
877
|
+
};
|
|
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
|
+
}
|
|
888
|
+
return new Promise((resolve) => {
|
|
889
|
+
let rewarded = false;
|
|
890
|
+
const handler = (state) => {
|
|
891
|
+
if (state === "opened") {
|
|
892
|
+
callbacks?.onBeforeAd?.();
|
|
893
|
+
} else if (state === "rewarded") {
|
|
894
|
+
rewarded = true;
|
|
895
|
+
callbacks?.onRewardEarned?.();
|
|
896
|
+
} else if (state === "closed" || state === "failed") {
|
|
897
|
+
bridge.advertisement.off(bridge.EVENT_NAME.REWARDED_STATE_CHANGED, handler);
|
|
898
|
+
callbacks?.onAfterAd?.();
|
|
899
|
+
resolve({
|
|
900
|
+
success: rewarded,
|
|
901
|
+
type: "rewarded",
|
|
902
|
+
error: !rewarded ? new Error("Rewarded ad not completed") : void 0,
|
|
903
|
+
requestedAt,
|
|
904
|
+
completedAt: Date.now()
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
};
|
|
908
|
+
bridge.advertisement.on(bridge.EVENT_NAME.REWARDED_STATE_CHANGED, handler);
|
|
909
|
+
bridge.advertisement.showRewarded();
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
loadScript() {
|
|
913
|
+
return new Promise((resolve, reject) => {
|
|
914
|
+
if (window.bridge) {
|
|
915
|
+
resolve();
|
|
916
|
+
return;
|
|
917
|
+
}
|
|
918
|
+
const script = document.createElement("script");
|
|
919
|
+
script.src = PLAYGAMA_BRIDGE_CDN;
|
|
920
|
+
script.onload = () => resolve();
|
|
921
|
+
script.onerror = () => reject(new Error("Failed to load Playgama Bridge script"));
|
|
922
|
+
document.head.appendChild(script);
|
|
923
|
+
});
|
|
924
|
+
}
|
|
925
|
+
};
|
|
926
|
+
|
|
760
927
|
// src/services/billing.ts
|
|
761
928
|
var BillingPlatform = /* @__PURE__ */ ((BillingPlatform3) => {
|
|
762
929
|
BillingPlatform3["WEB"] = "web";
|
|
@@ -1468,6 +1635,8 @@ var HyveClient = class {
|
|
|
1468
1635
|
jwtToken = null;
|
|
1469
1636
|
gameId = null;
|
|
1470
1637
|
adsService;
|
|
1638
|
+
playgamaService = null;
|
|
1639
|
+
playgamaInitPromise = null;
|
|
1471
1640
|
billingService;
|
|
1472
1641
|
billingConfig;
|
|
1473
1642
|
// Store callbacks to preserve them when recreating BillingService
|
|
@@ -1495,6 +1664,13 @@ var HyveClient = class {
|
|
|
1495
1664
|
if (config?.ads) {
|
|
1496
1665
|
this.adsService.configure(config.ads);
|
|
1497
1666
|
}
|
|
1667
|
+
if (typeof window !== "undefined" && PlaygamaService.isPlaygamaDomain()) {
|
|
1668
|
+
this.playgamaService = new PlaygamaService();
|
|
1669
|
+
this.playgamaInitPromise = this.playgamaService.initialize().then((success) => {
|
|
1670
|
+
logger.info("Playgama Bridge initialized:", success);
|
|
1671
|
+
return success;
|
|
1672
|
+
});
|
|
1673
|
+
}
|
|
1498
1674
|
this.billingConfig = config?.billing || {};
|
|
1499
1675
|
this.billingService = new BillingService(this.billingConfig);
|
|
1500
1676
|
this.storageMode = config?.storageMode || "cloud";
|
|
@@ -1514,6 +1690,7 @@ var HyveClient = class {
|
|
|
1514
1690
|
);
|
|
1515
1691
|
logger.info("API Base URL:", this.apiBaseUrl);
|
|
1516
1692
|
logger.info("Ads enabled:", this.adsService.isEnabled());
|
|
1693
|
+
logger.info("Playgama platform:", this.playgamaService !== null);
|
|
1517
1694
|
logger.info(
|
|
1518
1695
|
"Billing configured:",
|
|
1519
1696
|
Object.keys(this.billingConfig).length > 0
|
|
@@ -1943,6 +2120,25 @@ var HyveClient = class {
|
|
|
1943
2120
|
* @returns Promise resolving to ad result
|
|
1944
2121
|
*/
|
|
1945
2122
|
async showAd(type) {
|
|
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
|
+
}
|
|
2141
|
+
}
|
|
1946
2142
|
return this.adsService.show(type);
|
|
1947
2143
|
}
|
|
1948
2144
|
/**
|
|
@@ -2071,6 +2267,7 @@ export {
|
|
|
2071
2267
|
Logger,
|
|
2072
2268
|
NativeBridge,
|
|
2073
2269
|
NativeMessageType,
|
|
2270
|
+
PlaygamaService,
|
|
2074
2271
|
generateUUID,
|
|
2075
2272
|
handleVerifyMessage,
|
|
2076
2273
|
isDomainAllowed,
|