ATInterstitialJSSDK.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. var ATiOSInterstitialJS = require("./iOS/ATiOSInterstitialJS");
  2. var ATAndroidInterstitialJS = require("./Android/ATAndroidInterstitialJS");
  3. var initPlatformBridge = function() {
  4. if (cc.sys.os === cc.sys.OS_IOS) {
  5. return ATiOSInterstitialJS;
  6. } else if (cc.sys.os === cc.sys.OS_ANDROID) {
  7. return ATAndroidInterstitialJS;
  8. }
  9. };
  10. var platformBridge = initPlatformBridge();
  11. var ATInterstitialSDK = ATInterstitialSDK || {
  12. UseRewardedVideoAsInterstitial: "UseRewardedVideoAsInterstitial",
  13. ATInterstitialListener : {
  14. developerCallback : null,
  15. onInterstitialAdLoaded : function (placementId) {
  16. if(this.developerCallback != null && this.developerCallback.onInterstitialAdLoaded != null && undefined != this.developerCallback.onInterstitialAdLoaded) {
  17. this.developerCallback.onInterstitialAdLoaded(placementId);
  18. }
  19. },
  20. onInterstitialAdLoadFail : function(placementId, errorInfo) {
  21. if(this.developerCallback != null && this.developerCallback.onInterstitialAdLoadFail != null && undefined != this.developerCallback.onInterstitialAdLoadFail) {
  22. this.developerCallback.onInterstitialAdLoadFail(placementId, errorInfo);
  23. }
  24. },
  25. onInterstitialAdShow : function(placementId, callbackInfo) {
  26. if(this.developerCallback != null && this.developerCallback.onInterstitialAdShow != null && undefined != this.developerCallback.onInterstitialAdShow) {
  27. this.developerCallback.onInterstitialAdShow(placementId, callbackInfo);
  28. }
  29. },
  30. onInterstitialAdStartPlayingVideo : function(placementId, callbackInfo) {
  31. if(this.developerCallback != null && this.developerCallback.onInterstitialAdStartPlayingVideo != null && undefined != this.developerCallback.onInterstitialAdStartPlayingVideo) {
  32. this.developerCallback.onInterstitialAdStartPlayingVideo(placementId, callbackInfo);
  33. }
  34. },
  35. onInterstitialAdEndPlayingVideo : function(placementId, callbackInfo) {
  36. if(this.developerCallback != null && this.developerCallback.onInterstitialAdEndPlayingVideo != null && undefined != this.developerCallback.onInterstitialAdEndPlayingVideo) {
  37. this.developerCallback.onInterstitialAdEndPlayingVideo(placementId, callbackInfo);
  38. }
  39. },
  40. onInterstitialAdFailedToPlayVideo : function(placementId, errorInfo) {
  41. if(this.developerCallback != null && this.developerCallback.onInterstitialAdFailedToPlayVideo != null && undefined != this.developerCallback.onInterstitialAdFailedToPlayVideo) {
  42. this.developerCallback.onInterstitialAdFailedToPlayVideo(placementId, errorInfo);
  43. }
  44. },
  45. onInterstitialAdFailedToShow : function(placementId) {
  46. if(this.developerCallback != null && this.developerCallback.onInterstitialAdFailedToShow != null && undefined != this.developerCallback.onInterstitialAdFailedToShow) {
  47. this.developerCallback.onInterstitialAdFailedToShow(placementId);
  48. }
  49. },
  50. onInterstitialAdClose : function(placementId, callbackInfo) {
  51. if(this.developerCallback != null && this.developerCallback.onInterstitialAdClose != null && undefined != this.developerCallback.onInterstitialAdClose) {
  52. this.developerCallback.onInterstitialAdClose(placementId, callbackInfo);
  53. }
  54. },
  55. onInterstitialAdClick : function(placementId, callbackInfo) {
  56. if(this.developerCallback != null && this.developerCallback.onInterstitialAdClick != null && undefined != this.developerCallback.onInterstitialAdClick) {
  57. this.developerCallback.onInterstitialAdClick(placementId, callbackInfo);
  58. }
  59. }
  60. },
  61. loadInterstitial : function(placementId, settings={}) {
  62. if (undefined != platformBridge && platformBridge != null) {
  63. platformBridge.loadInterstitial(placementId, JSON.stringify(settings));
  64. } else {
  65. cc.log("You must run on Android or iOS.");
  66. }
  67. },
  68. setAdListener : function(listener) {
  69. var eventJSON = {};
  70. eventJSON[LoadedCallbackKey]="ATInterstitialJSSDK.ATInterstitialListener.onInterstitialAdLoaded",
  71. eventJSON[LoadFailCallbackKey]= "ATInterstitialJSSDK.ATInterstitialListener.onInterstitialAdLoadFail",
  72. eventJSON[PlayStartCallbackKey]= "ATInterstitialJSSDK.ATInterstitialListener.onInterstitialAdStartPlayingVideo",
  73. eventJSON[PlayEndCallbackKey]= "ATInterstitialJSSDK.ATInterstitialListener.onInterstitialAdEndPlayingVideo",
  74. eventJSON[PlayFailCallbackKey]= "ATInterstitialJSSDK.ATInterstitialListener.onInterstitialAdFailedToPlayVideo",
  75. eventJSON[CloseCallbackKey]= "ATInterstitialJSSDK.ATInterstitialListener.onInterstitialAdClose",
  76. eventJSON[ClickCallbackKey]= "ATInterstitialJSSDK.ATInterstitialListener.onInterstitialAdClick",
  77. eventJSON[ShowCallbackKey]= "ATInterstitialJSSDK.ATInterstitialListener.onInterstitialAdShow",
  78. eventJSON[ShowFailCallbackKey]= "ATInterstitialJSSDK.ATInterstitialListener.onInterstitialAdFailedToShow"
  79. if (undefined != platformBridge && platformBridge != null) {
  80. platformBridge.setAdListener(JSON.stringify(eventJSON));
  81. } else {
  82. cc.log("You must run on Android or iOS.");
  83. }
  84. this.ATInterstitialListener.developerCallback = listener;
  85. },
  86. hasAdReady : function(placementId) {
  87. if (undefined != platformBridge && platformBridge != null) {
  88. return platformBridge.hasAdReady(placementId);
  89. } else {
  90. cc.log("You must run on Android or iOS.");
  91. }
  92. return false;
  93. },
  94. checkAdStatus : function(placementId) {
  95. if (undefined != platformBridge && platformBridge != null) {
  96. return platformBridge.checkAdStatus(placementId);
  97. } else {
  98. cc.log("You must run on Android or iOS.");
  99. }
  100. return "";
  101. },
  102. showAd : function(placementId) {
  103. if (undefined != platformBridge && platformBridge != null) {
  104. platformBridge.showAd(placementId);
  105. } else {
  106. cc.log("You must run on Android or iOS.");
  107. }
  108. },
  109. showAdInScenario : function(placementId, scenario="") {
  110. if (undefined != platformBridge && platformBridge != null) {
  111. platformBridge.showAdInScenario(placementId, scenario);
  112. } else {
  113. cc.log("You must run on Android or iOS.");
  114. }
  115. }
  116. };
  117. const LoadedCallbackKey = "InterstitialLoaded";
  118. const LoadFailCallbackKey = "InterstitialLoadFail";
  119. const PlayStartCallbackKey = "InterstitialPlayStart";
  120. const PlayEndCallbackKey = "InterstitialPlayEnd";
  121. const PlayFailCallbackKey = "InterstitialPlayFail";
  122. const CloseCallbackKey = "InterstitialClose";
  123. const ClickCallbackKey = "InterstitialClick";
  124. const ShowCallbackKey = "InterstitialAdShow";
  125. const ShowFailCallbackKey = "InterstitialAdShowFail";
  126. window.ATInterstitialJSSDK = ATInterstitialSDK;