ATIntersitialAutoTSSDK.ts 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import {ATAndroidInterstitialAutoAdTS} from "./Android/ATAndroidIntersitialAutoTS";
  2. import {ATiOSInterstitialAutoAdTS} from "./iOS/ATiOSIntersitiaAutolTS";
  3. import {ATJSSDK} from "./ATJSSDK";
  4. var initPlatformBridge = function () {
  5. if (cc.sys.os === cc.sys.OS.IOS) {
  6. return ATiOSInterstitialAutoAdTS;
  7. } else if (cc.sys.os === cc.sys.OS.ANDROID) {
  8. return ATAndroidInterstitialAutoAdTS;
  9. }
  10. };
  11. var platformBridge = initPlatformBridge();
  12. export const ATInterstitialAutoAdSDK = {
  13. UseInterstitialAsInterstitial: "UseInterstitialAsInterstitial",
  14. UseRewardedVideoAsInterstitial:"UseRewardedVideoAsInterstitial",
  15. ATInterstitialListener: {
  16. developerCallback: null,
  17. onInterstitialAdLoaded : function (placementId) {
  18. if(this.developerCallback != null && this.developerCallback.onInterstitialAdLoaded != null && undefined != this.developerCallback.onInterstitialAdLoaded) {
  19. this.developerCallback.onInterstitialAdLoaded(placementId);
  20. }
  21. },
  22. onInterstitialAdLoadFail : function(placementId, errorInfo) {
  23. if(this.developerCallback != null && this.developerCallback.onInterstitialAdLoadFail != null && undefined != this.developerCallback.onInterstitialAdLoadFail) {
  24. this.developerCallback.onInterstitialAdLoadFail(placementId, errorInfo);
  25. }
  26. },
  27. onInterstitialAdShow : function(placementId, callbackInfo) {
  28. if(this.developerCallback != null && this.developerCallback.onInterstitialAdShow != null && undefined != this.developerCallback.onInterstitialAdShow) {
  29. this.developerCallback.onInterstitialAdShow(placementId, callbackInfo);
  30. }
  31. },
  32. onInterstitialAdStartPlayingVideo : function(placementId, callbackInfo) {
  33. if(this.developerCallback != null && this.developerCallback.onInterstitialAdStartPlayingVideo != null && undefined != this.developerCallback.onInterstitialAdStartPlayingVideo) {
  34. this.developerCallback.onInterstitialAdStartPlayingVideo(placementId, callbackInfo);
  35. }
  36. },
  37. onInterstitialAdEndPlayingVideo : function(placementId, callbackInfo) {
  38. if(this.developerCallback != null && this.developerCallback.onInterstitialAdEndPlayingVideo != null && undefined != this.developerCallback.onInterstitialAdEndPlayingVideo) {
  39. this.developerCallback.onInterstitialAdEndPlayingVideo(placementId, callbackInfo);
  40. }
  41. },
  42. onInterstitialAdFailedToPlayVideo : function(placementId, errorInfo) {
  43. if(this.developerCallback != null && this.developerCallback.onInterstitialAdFailedToPlayVideo != null && undefined != this.developerCallback.onInterstitialAdFailedToPlayVideo) {
  44. this.developerCallback.onInterstitialAdFailedToPlayVideo(placementId, errorInfo);
  45. }
  46. },
  47. onInterstitialAdFailedToShow : function(placementId, errorInfo, callbackInfo) {
  48. if(this.developerCallback != null && this.developerCallback.onInterstitialAdFailedToShow != null && undefined != this.developerCallback.onInterstitialAdFailedToShow) {
  49. this.developerCallback.onInterstitialAdFailedToShow(placementId, errorInfo, callbackInfo);
  50. }
  51. },
  52. onInterstitialAdClose : function(placementId, callbackInfo) {
  53. if(this.developerCallback != null && this.developerCallback.onInterstitialAdClose != null && undefined != this.developerCallback.onInterstitialAdClose) {
  54. this.developerCallback.onInterstitialAdClose(placementId, callbackInfo);
  55. }
  56. },
  57. onInterstitialAdClick : function(placementId, callbackInfo) {
  58. if(this.developerCallback != null && this.developerCallback.onInterstitialAdClick != null && undefined != this.developerCallback.onInterstitialAdClick) {
  59. this.developerCallback.onInterstitialAdClick(placementId, callbackInfo);
  60. }
  61. }
  62. },
  63. setAdExtraData: function (placementId, settings = {}) {
  64. if (undefined != platformBridge && platformBridge != null) {
  65. platformBridge.setAdExtraData(placementId, JSON.stringify(settings));
  66. } else {
  67. cc.log("You must run on Android or iOS.");
  68. }
  69. },
  70. addPlacementIds : function (placementIds){
  71. if (undefined != platformBridge && platformBridge != null) {
  72. platformBridge.addPlacementIds(JSON.stringify(placementIds));
  73. } else {
  74. cc.log("You must run on Android or iOS.");
  75. }
  76. },
  77. removePlacementId : function (placementIds){
  78. if (undefined != platformBridge && platformBridge != null) {
  79. platformBridge.removePlacementId(JSON.stringify(placementIds));
  80. } else {
  81. cc.log("You must run on Android or iOS.");
  82. }
  83. },
  84. setAdListener: function (listener) {
  85. var eventJSON = {};
  86. eventJSON[LoadedCallbackKey]="ATInterstitialAutoAdSDK.ATInterstitialListener.onInterstitialAdLoaded",
  87. eventJSON[LoadFailCallbackKey]= "ATInterstitialAutoAdSDK.ATInterstitialListener.onInterstitialAdLoadFail",
  88. eventJSON[PlayStartCallbackKey]= "ATInterstitialAutoAdSDK.ATInterstitialListener.onInterstitialAdStartPlayingVideo",
  89. eventJSON[PlayEndCallbackKey]= "ATInterstitialAutoAdSDK.ATInterstitialListener.onInterstitialAdEndPlayingVideo",
  90. eventJSON[PlayFailCallbackKey]= "ATInterstitialAutoAdSDK.ATInterstitialListener.onInterstitialAdFailedToPlayVideo",
  91. eventJSON[CloseCallbackKey]= "ATInterstitialAutoAdSDK.ATInterstitialListener.onInterstitialAdClose",
  92. eventJSON[ClickCallbackKey]= "ATInterstitialAutoAdSDK.ATInterstitialListener.onInterstitialAdClick",
  93. eventJSON[ShowCallbackKey]= "ATInterstitialAutoAdSDK.ATInterstitialListener.onInterstitialAdShow"
  94. eventJSON[ShowFailCallbackKey]= "ATInterstitialAutoAdSDK.ATInterstitialListener.onInterstitialAdFailedToShow"
  95. if (undefined != platformBridge && platformBridge != null) {
  96. platformBridge.setAdListener(JSON.stringify(eventJSON));
  97. } else {
  98. cc.log("You must run on Android or iOS.");
  99. }
  100. this.ATInterstitialListener.developerCallback = listener;
  101. },
  102. hasAdReady: function (placementId) {
  103. if (undefined != platformBridge && platformBridge != null) {
  104. return platformBridge.hasAdReady(placementId);
  105. } else {
  106. cc.log("You must run on Android or iOS.");
  107. }
  108. return false;
  109. },
  110. checkAdStatus: function (placementId) {
  111. if (undefined != platformBridge && platformBridge != null) {
  112. return platformBridge.checkAdStatus(placementId);
  113. } else {
  114. cc.log("You must run on Android or iOS.");
  115. }
  116. return "";
  117. },
  118. showAd: function (placementId) {
  119. if (undefined != platformBridge && platformBridge != null) {
  120. platformBridge.showAd(placementId);
  121. } else {
  122. cc.log("You must run on Android or iOS.");
  123. }
  124. },
  125. showAdInScenario: function (placementId, scenario = "") {
  126. if (undefined != platformBridge && platformBridge != null) {
  127. platformBridge.showAdInScenario(placementId, scenario);
  128. } else {
  129. cc.log("You must run on Android or iOS.");
  130. }
  131. },
  132. entryAdScenario: function (placementId, scenario = "") {
  133. if (undefined != platformBridge && platformBridge != null) {
  134. platformBridge.entryAdScenario(placementId, scenario);
  135. } else {
  136. cc.log("You must run on Android or iOS.");
  137. }
  138. }
  139. };
  140. const LoadedCallbackKey = "InterstitialAutoAdLoaded";
  141. const LoadFailCallbackKey = "InterstitialAutoAdLoadFail";
  142. const PlayStartCallbackKey = "InterstitialAutoAdPlayStart";
  143. const PlayEndCallbackKey = "InterstitialAutoAdPlayEnd";
  144. const PlayFailCallbackKey = "InterstitialAutoAdPlayFail";
  145. const CloseCallbackKey = "InterstitialAutoAdClose";
  146. const ClickCallbackKey = "InterstitialAutoAdClick";
  147. const ShowCallbackKey = "InterstitialAutoAdAdShow";
  148. const ShowFailCallbackKey = "InterstitialAutoAdShowFail";
  149. window["ATInterstitialAutoAdSDK"] = ATInterstitialAutoAdSDK;