ATJSSDK.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. // Import platform-specific SDKs
  2. import ATAndroidJS from "./Android/ATAndroidJS";
  3. import ATiOSJS from "./iOS/ATiOSJS";
  4. let isDebugLog = false;
  5. // Define platform bridge initialization
  6. const initPlatformBridge = (): any => {
  7. if (cc.sys.os === cc.sys.OS_IOS) {
  8. return ATiOSJS;
  9. } else if (cc.sys.os === cc.sys.OS_ANDROID) {
  10. return ATAndroidJS;
  11. }
  12. };
  13. // Initialize platform bridge
  14. const platformBridge = initPlatformBridge();
  15. // Define the ATSDK interface
  16. interface IATSDK {
  17. kATUserLocationUnknown: number;
  18. kATUserLocationInEU: number;
  19. kATUserLocationOutOfEU: number;
  20. PERSONALIZED: number;
  21. NONPERSONALIZED: number;
  22. UNKNOWN: number;
  23. // General keys
  24. OS_VERSION_NAME: string;
  25. OS_VERSION_CODE: string;
  26. APP_PACKAGE_NAME: string;
  27. APP_VERSION_NAME: string;
  28. APP_VERSION_CODE: string;
  29. // Device info keys
  30. BRAND: string;
  31. MODEL: string;
  32. DEVICE_SCREEN_SIZE: string;
  33. MNC: string;
  34. MCC: string;
  35. LANGUAGE: string;
  36. TIMEZONE: string;
  37. USER_AGENT: string;
  38. ORIENTATION: string;
  39. NETWORK_TYPE: string;
  40. // Android-specific keys
  41. INSTALLER: string;
  42. ANDROID_ID: string;
  43. GAID: string;
  44. MAC: string;
  45. IMEI: string;
  46. OAID: string;
  47. // iOS-specific keys
  48. IDFA: string;
  49. IDFV: string;
  50. ATSDKListener: {
  51. userLocationCallback: ((userLocation: number) => void) | null;
  52. getUserLocationCallback: (userLocation: number) => void;
  53. };
  54. initSDK(appId: string, appKey: string): void;
  55. initCustomMap(customMap: Record<string, any>): void;
  56. setPlacementCustomMap(placementId: string, customMap: Record<string, any>): void;
  57. setGDPRLevel(level: number): void;
  58. getGDPRLevel(): number;
  59. getUserLocation(userLocationCallback: (userLocation: number) => void): void;
  60. showGDPRAuth(): void;
  61. setLogDebug(debug: boolean): void;
  62. printLog(msg: string): void;
  63. deniedUploadDeviceInfo(deniedInfo: string[]): void;
  64. }
  65. // Define ATSDK object
  66. const ATSDK: IATSDK = {
  67. kATUserLocationUnknown: 0,
  68. kATUserLocationInEU: 1,
  69. kATUserLocationOutOfEU: 2,
  70. PERSONALIZED: 0,
  71. NONPERSONALIZED: 1,
  72. UNKNOWN: 2,
  73. // General keys
  74. OS_VERSION_NAME: "os_vn",
  75. OS_VERSION_CODE: "os_vc",
  76. APP_PACKAGE_NAME: "package_name",
  77. APP_VERSION_NAME: "app_vn",
  78. APP_VERSION_CODE: "app_vc",
  79. // Device info keys
  80. BRAND: "brand",
  81. MODEL: "model",
  82. DEVICE_SCREEN_SIZE: "screen",
  83. MNC: "mnc",
  84. MCC: "mcc",
  85. LANGUAGE: "language",
  86. TIMEZONE: "timezone",
  87. USER_AGENT: "ua",
  88. ORIENTATION: "orient",
  89. NETWORK_TYPE: "network_type",
  90. // Android-specific keys
  91. INSTALLER: "it_src",
  92. ANDROID_ID: "android_id",
  93. GAID: "gaid",
  94. MAC: "mac",
  95. IMEI: "imei",
  96. OAID: "oaid",
  97. // iOS-specific keys
  98. IDFA: "idfa",
  99. IDFV: "idfv",
  100. ATSDKListener: {
  101. userLocationCallback: null,
  102. getUserLocationCallback(userLocation: number) {
  103. this.userLocationCallback?.(userLocation);
  104. }
  105. },
  106. initSDK(appId: string, appKey: string) {
  107. if (platformBridge) {
  108. platformBridge.initSDK(appId, appKey);
  109. } else {
  110. cc.log("You must run on Android or iOS.");
  111. }
  112. },
  113. initCustomMap(customMap: Record<string, any>) {
  114. if (platformBridge) {
  115. if (customMap) {
  116. platformBridge.initCustomMap(JSON.stringify(customMap));
  117. }
  118. } else {
  119. cc.log("You must run on Android or iOS.");
  120. }
  121. },
  122. setPlacementCustomMap(placementId: string, customMap: Record<string, any>) {
  123. if (platformBridge) {
  124. if (customMap) {
  125. platformBridge.setPlacementCustomMap(placementId, JSON.stringify(customMap));
  126. }
  127. } else {
  128. cc.log("You must run on Android or iOS.");
  129. }
  130. },
  131. setGDPRLevel(level: number) {
  132. if (platformBridge) {
  133. platformBridge.setGDPRLevel(level);
  134. } else {
  135. cc.log("You must run on Android or iOS.");
  136. }
  137. },
  138. getGDPRLevel(): number {
  139. if (platformBridge) {
  140. return platformBridge.getGDPRLevel();
  141. } else {
  142. cc.log("You must run on Android or iOS.");
  143. }
  144. return this.UNKNOWN;
  145. },
  146. getUserLocation(userLocationCallback: (userLocation: number) => void) {
  147. this.ATSDKListener.userLocationCallback = userLocationCallback;
  148. if (platformBridge) {
  149. platformBridge.getUserLocation(GetUserLocationJsCallback);
  150. } else {
  151. cc.log("You must run on Android or iOS.");
  152. }
  153. },
  154. showGDPRAuth() {
  155. if (platformBridge) {
  156. platformBridge.showGDPRAuth();
  157. } else {
  158. cc.log("You must run on Android or iOS.");
  159. }
  160. },
  161. setLogDebug(debug: boolean) {
  162. isDebugLog = debug;
  163. if (platformBridge) {
  164. platformBridge.setLogDebug(debug);
  165. } else {
  166. cc.log("You must run on Android or iOS.");
  167. }
  168. },
  169. printLog(msg: string) {
  170. if (msg && isDebugLog && platformBridge) {
  171. platformBridge.printJsLog(msg);
  172. }
  173. },
  174. deniedUploadDeviceInfo(deniedInfo: string[]) {
  175. if (platformBridge) {
  176. if (deniedInfo && deniedInfo.length > 0) {
  177. const deniedInfoString = deniedInfo.join(",");
  178. cc.log("test__" + deniedInfoString);
  179. platformBridge.deniedUploadDeviceInfo(deniedInfoString);
  180. }
  181. } else {
  182. cc.log("You must run on Android or iOS.");
  183. }
  184. }
  185. };
  186. // Define callback constant
  187. const GetUserLocationJsCallback = "ATJSSDK.ATSDKListener.getUserLocationCallback";
  188. // Export the SDK to the global window object
  189. (window as any).ATJSSDK = ATSDK;
  190. export default ATSDK;