ATIntersitialTSSDK.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. import {ATAndroidInterstitialJS} from "./Android/ATAndroidIntersitialTS";
  2. import {ATiOSInterstitialJS} from "./iOS/ATiOSIntersitialTS";
  3. import {ATJSSDK} from "./ATJSSDK";
  4. var initPlatformBridge = function () {
  5. if (cc.sys.os === cc.sys.OS.IOS) {
  6. return ATiOSInterstitialJS;
  7. } else if (cc.sys.os === cc.sys.OS.ANDROID) {
  8. return ATAndroidInterstitialJS;
  9. }
  10. };
  11. var platformBridge = initPlatformBridge();
  12. export const ATInterstitialSDK = {
  13. UseInterstitialAsInterstitial: "UseInterstitialAsInterstitial",
  14. ATInterstitialListener: {
  15. developerCallback: null,
  16. onInterstitialAdLoaded: function (placementId) {
  17. if (this.developerCallback != null && this.developerCallback.onInterstitialAdLoaded != null && undefined != this.developerCallback.onInterstitialAdLoaded) {
  18. this.developerCallback.onInterstitialAdLoaded(placementId);
  19. }
  20. },
  21. onInterstitialAdLoadFail: function (placementId, errorInfo) {
  22. if (this.developerCallback != null && this.developerCallback.onInterstitialAdLoadFail != null && undefined != this.developerCallback.onInterstitialAdLoadFail) {
  23. this.developerCallback.onInterstitialAdLoadFail(placementId, errorInfo);
  24. }
  25. },
  26. onInterstitialAdShow: function (placementId, callbackInfo) {
  27. if (this.developerCallback != null && this.developerCallback.onInterstitialAdShow != null && undefined != this.developerCallback.onInterstitialAdShow) {
  28. this.developerCallback.onInterstitialAdShow(placementId, callbackInfo);
  29. }
  30. },
  31. onInterstitialAdStartPlayingVideo: function (placementId, callbackInfo) {
  32. if (this.developerCallback != null && this.developerCallback.onInterstitialAdStartPlayingVideo != null && undefined != this.developerCallback.onInterstitialAdStartPlayingVideo) {
  33. this.developerCallback.onInterstitialAdStartPlayingVideo(placementId, callbackInfo);
  34. }
  35. },
  36. onInterstitialAdEndPlayingVideo: function (placementId, callbackInfo) {
  37. if (this.developerCallback != null && this.developerCallback.onInterstitialAdEndPlayingVideo != null && undefined != this.developerCallback.onInterstitialAdEndPlayingVideo) {
  38. this.developerCallback.onInterstitialAdEndPlayingVideo(placementId, callbackInfo);
  39. }
  40. },
  41. onInterstitialAdFailedToPlayVideo: function (placementId, errorInfo) {
  42. if (this.developerCallback != null && this.developerCallback.onInterstitialAdFailedToPlayVideo != null && undefined != this.developerCallback.onInterstitialAdFailedToPlayVideo) {
  43. this.developerCallback.onInterstitialAdFailedToPlayVideo(placementId, errorInfo);
  44. }
  45. },
  46. onInterstitialAdFailedToShow: function (placementId, errorInfo, callbackInfo) {
  47. if (this.developerCallback != null && this.developerCallback.onInterstitialAdFailedToShow != null && undefined != this.developerCallback.onInterstitialAdFailedToShow) {
  48. this.developerCallback.onInterstitialAdFailedToShow(placementId, errorInfo, callbackInfo);
  49. }
  50. },
  51. onInterstitialAdClose: function (placementId, callbackInfo) {
  52. if (this.developerCallback != null && this.developerCallback.onInterstitialAdClose != null && undefined != this.developerCallback.onInterstitialAdClose) {
  53. this.developerCallback.onInterstitialAdClose(placementId, callbackInfo);
  54. }
  55. },
  56. onInterstitialAdClick: function (placementId, callbackInfo) {
  57. if (this.developerCallback != null && this.developerCallback.onInterstitialAdClick != null && undefined != this.developerCallback.onInterstitialAdClick) {
  58. this.developerCallback.onInterstitialAdClick(placementId, callbackInfo);
  59. }
  60. },
  61. //added v5.8.10
  62. onAdSourceBiddingAttempt: function (placementId, callbackInfo) {
  63. if (this.developerCallback != null && this.developerCallback.onAdSourceBiddingAttempt != null && undefined != this.developerCallback.onAdSourceBiddingAttempt) {
  64. this.developerCallback.onAdSourceBiddingAttempt(placementId, callbackInfo);
  65. }
  66. },
  67. onAdSourceBiddingFilled: function (placementId, callbackInfo) {
  68. if (this.developerCallback != null && this.developerCallback.onAdSourceBiddingFilled != null && undefined != this.developerCallback.onAdSourceBiddingFilled) {
  69. this.developerCallback.onAdSourceBiddingFilled(placementId, callbackInfo);
  70. }
  71. },
  72. onAdSourceBiddingFail: function (placementId, errorInfo, callbackInfo) {
  73. if (this.developerCallback != null && this.developerCallback.onAdSourceBiddingFail != null && undefined != this.developerCallback.onAdSourceBiddingFail) {
  74. this.developerCallback.onAdSourceBiddingFail(placementId, errorInfo, callbackInfo);
  75. }
  76. },
  77. onAdSourceAttemp: function (placementId, callbackInfo) {
  78. if (this.developerCallback != null && this.developerCallback.onAdSourceAttemp != null && undefined != this.developerCallback.onAdSourceAttemp) {
  79. this.developerCallback.onAdSourceAttemp(placementId, callbackInfo);
  80. }
  81. },
  82. onAdSourceLoadFilled: function (placementId, callbackInfo) {
  83. if (this.developerCallback != null && this.developerCallback.onAdSourceLoadFilled != null && undefined != this.developerCallback.onAdSourceLoadFilled) {
  84. this.developerCallback.onAdSourceLoadFilled(placementId, callbackInfo);
  85. }
  86. },
  87. onAdSourceLoadFail: function (placementId, errorInfo, callbackInfo) {
  88. if (this.developerCallback != null && this.developerCallback.onAdSourceLoadFail != null && undefined != this.developerCallback.onAdSourceLoadFail) {
  89. this.developerCallback.onAdSourceLoadFail(placementId, errorInfo, callbackInfo);
  90. }
  91. }
  92. },
  93. loadInterstitial: function (placementId, settings = {}) {
  94. if (undefined != platformBridge && platformBridge != null) {
  95. platformBridge.loadInterstitial(placementId, JSON.stringify(settings));
  96. } else {
  97. cc.log("You must run on Android or iOS.");
  98. }
  99. },
  100. setAdListener: function (listener) {
  101. var eventJSON = {};
  102. eventJSON[LoadedCallbackKey] = " ATInterstitialSDK.ATInterstitialListener.onInterstitialAdLoaded",
  103. eventJSON[LoadFailCallbackKey] = " ATInterstitialSDK.ATInterstitialListener.onInterstitialAdLoadFail",
  104. eventJSON[PlayStartCallbackKey] = " ATInterstitialSDK.ATInterstitialListener.onInterstitialAdStartPlayingVideo",
  105. eventJSON[PlayEndCallbackKey] = " ATInterstitialSDK.ATInterstitialListener.onInterstitialAdEndPlayingVideo",
  106. eventJSON[PlayFailCallbackKey] = " ATInterstitialSDK.ATInterstitialListener.onInterstitialAdFailedToPlayVideo",
  107. eventJSON[CloseCallbackKey] = " ATInterstitialSDK.ATInterstitialListener.onInterstitialAdClose",
  108. eventJSON[ClickCallbackKey] = " ATInterstitialSDK.ATInterstitialListener.onInterstitialAdClick",
  109. eventJSON[ShowCallbackKey] = " ATInterstitialSDK.ATInterstitialListener.onInterstitialAdShow",
  110. eventJSON[ShowFailCallbackKey] = " ATInterstitialSDK.ATInterstitialListener.onInterstitialAdFailedToShow",
  111. //added v5.8.10
  112. eventJSON[BiddingAttempt] = " ATInterstitialSDK.ATInterstitialListener.onAdSourceBiddingAttempt",
  113. eventJSON[BiddingFilled] = " ATInterstitialSDK.ATInterstitialListener.onAdSourceBiddingFilled",
  114. eventJSON[BiddingFail] = " ATInterstitialSDK.ATInterstitialListener.onAdSourceBiddingFail",
  115. eventJSON[Attemp] = " ATInterstitialSDK.ATInterstitialListener.onAdSourceAttemp",
  116. eventJSON[LoadFilled] = " ATInterstitialSDK.ATInterstitialListener.onAdSourceLoadFilled",
  117. eventJSON[LoadFail] = " ATInterstitialSDK.ATInterstitialListener.onAdSourceLoadFail"
  118. if (undefined != platformBridge && platformBridge != null) {
  119. platformBridge.setAdListener(JSON.stringify(eventJSON));
  120. } else {
  121. cc.log("You must run on Android or iOS.");
  122. }
  123. this.ATInterstitialListener.developerCallback = listener;
  124. },
  125. hasAdReady: function (placementId) {
  126. if (undefined != platformBridge && platformBridge != null) {
  127. return platformBridge.hasAdReady(placementId);
  128. } else {
  129. cc.log("You must run on Android or iOS.");
  130. }
  131. return false;
  132. },
  133. checkAdStatus: function (placementId) {
  134. if (undefined != platformBridge && platformBridge != null) {
  135. return platformBridge.checkAdStatus(placementId);
  136. } else {
  137. cc.log("You must run on Android or iOS.");
  138. }
  139. return "";
  140. },
  141. showAd: function (placementId) {
  142. if (undefined != platformBridge && platformBridge != null) {
  143. platformBridge.showAd(placementId);
  144. } else {
  145. cc.log("You must run on Android or iOS.");
  146. }
  147. },
  148. showAdInScenario: function (placementId, scenario = "") {
  149. if (undefined != platformBridge && platformBridge != null) {
  150. platformBridge.showAdInScenario(placementId, scenario);
  151. } else {
  152. cc.log("You must run on Android or iOS.");
  153. }
  154. },
  155. entryAdScenario: function (placementId, scenario = "") {
  156. if (undefined != platformBridge && platformBridge != null) {
  157. platformBridge.entryAdScenario(placementId, scenario);
  158. } else {
  159. cc.log("You must run on Android or iOS.");
  160. }
  161. }
  162. };
  163. const LoadedCallbackKey = "InterstitialLoaded";
  164. const LoadFailCallbackKey = "InterstitialLoadFail";
  165. const PlayStartCallbackKey = "InterstitialPlayStart";
  166. const PlayEndCallbackKey = "InterstitialPlayEnd";
  167. const PlayFailCallbackKey = "InterstitialPlayFail";
  168. const CloseCallbackKey = "InterstitialClose";
  169. const ClickCallbackKey = "InterstitialClick";
  170. const ShowCallbackKey = "InterstitialAdShow";
  171. const ShowFailCallbackKey = "InterstitialAdShowFail";
  172. const BiddingAttempt = "InterstitialBiddingAttempt";
  173. const BiddingFilled = "InterstitialBiddingFilled";
  174. const BiddingFail = "InterstitialBiddingFail";
  175. const Attemp = "InterstitialAttemp";
  176. const LoadFilled = "InterstitialLoadFilled";
  177. const LoadFail = "InterstitialLoadFail";
  178. window["ATInterstitialSDK"] = ATInterstitialSDK;