ATRewardedVideoTSSDK.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. import {ATAndroidRewardedVideoJS} from "./Android/ATAndroidRewardedVideoTS";
  2. import {ATiOSRewardedVideoTS} from "./iOS/ATiOSRewardedVideoTS";
  3. import {ATJSSDK} from "./ATJSSDK";
  4. import { _decorator, Component, Node, sys ,log } from 'cc';
  5. var initPlatformBridge = function () {
  6. if (sys.os === sys.OS.IOS) {
  7. return ATiOSRewardedVideoTS;
  8. } else if (sys.os === sys.OS.ANDROID) {
  9. return ATAndroidRewardedVideoJS;
  10. }
  11. };
  12. var platformBridge = initPlatformBridge();
  13. export const ATRewardedVideoSDK = {
  14. userIdKey: "userID",
  15. userDataKey: "media_ext",
  16. ATRewardedVideoListener: {
  17. developerCallback: null,
  18. onRewardedVideoAdLoaded: function (placementId) {
  19. ATJSSDK.printLog("ATRewardedVideoSDK.ATRewardedVideoListener.onRewardedVideoAdLoaded(" + placementId + ")");
  20. if (this.developerCallback != null && this.developerCallback.onRewardedVideoAdLoaded != null && undefined != this.developerCallback.onRewardedVideoAdLoaded) {
  21. this.developerCallback.onRewardedVideoAdLoaded(placementId);
  22. }
  23. },
  24. onRewardedVideoAdFailed: function (placementId, errorInfo) {
  25. ATJSSDK.printLog("ATRewardedVideoSDK.ATRewardedVideoListener.onRewardedVideoAdFailed(" + placementId + ", " + errorInfo + ")");
  26. if (this.developerCallback != null && this.developerCallback.onRewardedVideoAdFailed != null && undefined != this.developerCallback.onRewardedVideoAdFailed) {
  27. this.developerCallback.onRewardedVideoAdFailed(placementId, errorInfo);
  28. }
  29. },
  30. onRewardedVideoAdPlayStart: function (placementId, callbackInfo) {
  31. ATJSSDK.printLog("ATRewardedVideoSDK.ATRewardedVideoListener.onRewardedVideoAdPlayStart(" + placementId + ", " + callbackInfo + ")");
  32. if (this.developerCallback != null && this.developerCallback.onRewardedVideoAdPlayStart != null && undefined != this.developerCallback.onRewardedVideoAdPlayStart) {
  33. this.developerCallback.onRewardedVideoAdPlayStart(placementId, callbackInfo);
  34. }
  35. },
  36. onRewardedVideoAdPlayEnd: function (placementId, callbackInfo) {
  37. ATJSSDK.printLog("ATRewardedVideoSDK.ATRewardedVideoListener.onRewardedVideoAdPlayEnd(" + placementId + ", " + callbackInfo + ")");
  38. if (this.developerCallback != null && this.developerCallback.onRewardedVideoAdPlayEnd != null && undefined != this.developerCallback.onRewardedVideoAdPlayEnd) {
  39. this.developerCallback.onRewardedVideoAdPlayEnd(placementId, callbackInfo);
  40. }
  41. },
  42. onRewardedVideoAdPlayFailed: function (placementId, errorInfo, callbackInfo) {
  43. ATJSSDK.printLog("ATRewardedVideoSDK.ATRewardedVideoListener.onRewardedVideoAdPlayFailed(" + placementId + ", " + errorInfo + ", " + callbackInfo + ")");
  44. if (this.developerCallback != null && this.developerCallback.onRewardedVideoAdPlayFailed != null && undefined != this.developerCallback.onRewardedVideoAdPlayFailed) {
  45. this.developerCallback.onRewardedVideoAdPlayFailed(placementId, errorInfo, callbackInfo);
  46. }
  47. },
  48. onRewardedVideoAdClosed: function (placementId, callbackInfo) {
  49. ATJSSDK.printLog("ATRewardedVideoSDK.ATRewardedVideoListener.onRewardedVideoAdClosed(" + placementId + ", " + callbackInfo + ")");
  50. if (this.developerCallback != null && this.developerCallback.onRewardedVideoAdClosed != null && undefined != this.developerCallback.onRewardedVideoAdClosed) {
  51. this.developerCallback.onRewardedVideoAdClosed(placementId, callbackInfo);
  52. }
  53. },
  54. onRewardedVideoAdPlayClicked: function (placementId, callbackInfo) {
  55. ATJSSDK.printLog("ATRewardedVideoSDK.ATRewardedVideoListener.onRewardedVideoAdPlayClicked(" + placementId + ", " + callbackInfo + ")");
  56. if (this.developerCallback != null && this.developerCallback.onRewardedVideoAdPlayClicked != null && undefined != this.developerCallback.onRewardedVideoAdPlayClicked) {
  57. this.developerCallback.onRewardedVideoAdPlayClicked(placementId, callbackInfo);
  58. }
  59. },
  60. onReward: function (placementId, callbackInfo) {
  61. ATJSSDK.printLog("ATRewardedVideoSDK.ATRewardedVideoListener.onReward(" + placementId + ", " + callbackInfo + ")");
  62. if (this.developerCallback != null && this.developerCallback.onReward != null && undefined != this.developerCallback.onReward) {
  63. this.developerCallback.onReward(placementId, callbackInfo);
  64. }
  65. },
  66. //added v5.8.10
  67. onAdSourceBiddingAttempt: function (placementId, callbackInfo) {
  68. ATJSSDK.printLog("ATRewardedVideoSDK.ATRewardedVideoListener.onAdSourceBiddingAttempt(" + placementId + ", " + callbackInfo + ")");
  69. if (this.developerCallback != null && this.developerCallback.onAdSourceBiddingAttempt != null && undefined != this.developerCallback.onAdSourceBiddingAttempt) {
  70. this.developerCallback.onAdSourceBiddingAttempt(placementId, callbackInfo);
  71. }
  72. },
  73. onAdSourceBiddingFilled: function (placementId, callbackInfo) {
  74. ATJSSDK.printLog("ATRewardedVideoSDK.ATRewardedVideoListener.onAdSourceBiddingFilled(" + placementId + ", " + callbackInfo + ")");
  75. if (this.developerCallback != null && this.developerCallback.onAdSourceBiddingFilled != null && undefined != this.developerCallback.onAdSourceBiddingFilled) {
  76. this.developerCallback.onAdSourceBiddingFilled(placementId, callbackInfo);
  77. }
  78. },
  79. onAdSourceBiddingFail: function (placementId, errorInfo, callbackInfo) {
  80. ATJSSDK.printLog("ATRewardedVideoSDK.ATRewardedVideoListener.onAdSourceBiddingFail(" + placementId + ", " + errorInfo + ", " + callbackInfo + ")");
  81. if (this.developerCallback != null && this.developerCallback.onAdSourceBiddingFail != null && undefined != this.developerCallback.onAdSourceBiddingFail) {
  82. this.developerCallback.onAdSourceBiddingFail(placementId, errorInfo, callbackInfo);
  83. }
  84. },
  85. onAdSourceAttemp: function (placementId, callbackInfo) {
  86. ATJSSDK.printLog("ATRewardedVideoSDK.ATRewardedVideoListener.onAdSourceAttemp(" + placementId + ", " + callbackInfo + ")");
  87. if (this.developerCallback != null && this.developerCallback.onAdSourceAttemp != null && undefined != this.developerCallback.onAdSourceAttemp) {
  88. this.developerCallback.onAdSourceAttemp(placementId, callbackInfo);
  89. }
  90. },
  91. onAdSourceLoadFilled: function (placementId, callbackInfo) {
  92. ATJSSDK.printLog("ATRewardedVideoSDK.ATRewardedVideoListener.onAdSourceLoadFilled(" + placementId + ", " + callbackInfo + ")");
  93. if (this.developerCallback != null && this.developerCallback.onAdSourceLoadFilled != null && undefined != this.developerCallback.onAdSourceLoadFilled) {
  94. this.developerCallback.onAdSourceLoadFilled(placementId, callbackInfo);
  95. }
  96. },
  97. onAdSourceLoadFail: function (placementId, errorInfo, callbackInfo) {
  98. ATJSSDK.printLog("ATRewardedVideoSDK.ATRewardedVideoListener.onAdSourceLoadFail(" + placementId + ", " + errorInfo + ", " + callbackInfo + ")");
  99. if (this.developerCallback != null && this.developerCallback.onAdSourceLoadFail != null && undefined != this.developerCallback.onAdSourceLoadFail) {
  100. this.developerCallback.onAdSourceLoadFail(placementId, errorInfo, callbackInfo);
  101. }
  102. },
  103. onRewardedVideoAdAgainPlayStart: function (placementId, callbackInfo) {
  104. ATJSSDK.printLog("ATRewardedVideoSDK.ATRewardedVideoListener.onRewardedVideoAdAgainPlayStart(" + placementId + ", " + callbackInfo + ")");
  105. if (this.developerCallback != null && this.developerCallback.onRewardedVideoAdAgainPlayStart != null && undefined != this.developerCallback.onRewardedVideoAdAgainPlayStart) {
  106. this.developerCallback.onRewardedVideoAdAgainPlayStart(placementId, callbackInfo);
  107. }
  108. },
  109. onRewardedVideoAdAgainPlayEnd: function (placementId, callbackInfo) {
  110. ATJSSDK.printLog("ATRewardedVideoSDK.ATRewardedVideoListener.onRewardedVideoAdAgainPlayEnd(" + placementId + ", " + callbackInfo + ")");
  111. if (this.developerCallback != null && this.developerCallback.onRewardedVideoAdAgainPlayEnd != null && undefined != this.developerCallback.onRewardedVideoAdAgainPlayEnd) {
  112. this.developerCallback.onRewardedVideoAdAgainPlayEnd(placementId, callbackInfo);
  113. }
  114. },
  115. onRewardedVideoAdAgainPlayFailed: function (placementId, errorInfo, callbackInfo) {
  116. ATJSSDK.printLog("ATRewardedVideoSDK.ATRewardedVideoListener.onRewardedVideoAdAgainPlayFailed(" + placementId + ", " + errorInfo + ", " + callbackInfo + ")");
  117. if (this.developerCallback != null && this.developerCallback.onRewardedVideoAdAgainPlayFailed != null && undefined != this.developerCallback.onRewardedVideoAdAgainPlayFailed) {
  118. this.developerCallback.onRewardedVideoAdAgainPlayFailed(placementId, errorInfo, callbackInfo);
  119. }
  120. },
  121. onRewardedVideoAdAgainPlayClicked: function (placementId, callbackInfo) {
  122. ATJSSDK.printLog("ATRewardedVideoSDK.ATRewardedVideoListener.onRewardedVideoAdAgainPlayClicked(" + placementId + ", " + callbackInfo + ")");
  123. if (this.developerCallback != null && this.developerCallback.onRewardedVideoAdAgainPlayClicked != null && undefined != this.developerCallback.onRewardedVideoAdAgainPlayClicked) {
  124. this.developerCallback.onRewardedVideoAdAgainPlayClicked(placementId, callbackInfo);
  125. }
  126. },
  127. onAgainReward: function (placementId, callbackInfo) {
  128. ATJSSDK.printLog("ATRewardedVideoSDK.ATRewardedVideoListener.onAgainReward(" + placementId + ", " + callbackInfo + ")");
  129. if (this.developerCallback != null && this.developerCallback.onAgainReward != null && undefined != this.developerCallback.onAgainReward) {
  130. this.developerCallback.onAgainReward(placementId, callbackInfo);
  131. }
  132. }
  133. },
  134. loadRewardedVideo: function (placementId, settings = {}) {
  135. if (undefined != platformBridge && platformBridge != null) {
  136. platformBridge.loadRewardedVideo(placementId, JSON.stringify(settings));
  137. } else {
  138. log("You must run on Android or iOS.");
  139. }
  140. },
  141. setAdListener: function (listener) {
  142. var eventJSON = {};
  143. eventJSON[LoadedCallbackKey] = "ATRewardedVideoSDK.ATRewardedVideoListener.onRewardedVideoAdLoaded",
  144. eventJSON[LoadFailCallbackKey] = "ATRewardedVideoSDK.ATRewardedVideoListener.onRewardedVideoAdFailed",
  145. eventJSON[PlayStartCallbackKey] = "ATRewardedVideoSDK.ATRewardedVideoListener.onRewardedVideoAdPlayStart",
  146. eventJSON[PlayEndCallbackKey] = "ATRewardedVideoSDK.ATRewardedVideoListener.onRewardedVideoAdPlayEnd",
  147. eventJSON[PlayFailCallbackKey] = "ATRewardedVideoSDK.ATRewardedVideoListener.onRewardedVideoAdPlayFailed",
  148. eventJSON[CloseCallbackKey] = "ATRewardedVideoSDK.ATRewardedVideoListener.onRewardedVideoAdClosed",
  149. eventJSON[ClickCallbackKey] = "ATRewardedVideoSDK.ATRewardedVideoListener.onRewardedVideoAdPlayClicked",
  150. eventJSON[RewardCallbackKey] = "ATRewardedVideoSDK.ATRewardedVideoListener.onReward",
  151. //added v5.8.10
  152. eventJSON[BiddingAttempt] = "ATRewardedVideoSDK.ATRewardedVideoListener.onAdSourceBiddingAttempt",
  153. eventJSON[BiddingFilled] = "ATRewardedVideoSDK.ATRewardedVideoListener.onAdSourceBiddingFilled",
  154. eventJSON[BiddingFail] = "ATRewardedVideoSDK.ATRewardedVideoListener.onAdSourceBiddingFail",
  155. eventJSON[Attemp] = "ATRewardedVideoSDK.ATRewardedVideoListener.onAdSourceAttemp",
  156. eventJSON[LoadFilled] = "ATRewardedVideoSDK.ATRewardedVideoListener.onAdSourceLoadFilled",
  157. eventJSON[LoadFail] = "ATRewardedVideoSDK.ATRewardedVideoListener.onAdSourceLoadFail",
  158. //added v5.8.10 playAgain listener
  159. eventJSON[AgainPlayStartCallbackKey] = "ATRewardedVideoSDK.ATRewardedVideoListener.onRewardedVideoAdAgainPlayStart",
  160. eventJSON[AgainPlayEndCallbackKey] = "ATRewardedVideoSDK.ATRewardedVideoListener.onRewardedVideoAdAgainPlayEnd",
  161. eventJSON[AgainPlayFailCallbackKey] = "ATRewardedVideoSDK.ATRewardedVideoListener.onRewardedVideoAdAgainPlayFailed",
  162. eventJSON[AgainClickCallbackKey] = "ATRewardedVideoSDK.ATRewardedVideoListener.onRewardedVideoAdAgainPlayClicked",
  163. eventJSON[AgainRewardCallbackKey] = "ATRewardedVideoSDK.ATRewardedVideoListener.onAgainReward"
  164. if (undefined != platformBridge && platformBridge != null) {
  165. platformBridge.setAdListener(JSON.stringify(eventJSON));
  166. } else {
  167. log("You must run on Android or iOS.");
  168. }
  169. this.ATRewardedVideoListener.developerCallback = listener;
  170. },
  171. hasAdReady: function (placementId) {
  172. if (undefined != platformBridge && platformBridge != null) {
  173. return platformBridge.hasAdReady(placementId);
  174. } else {
  175. log("You must run on Android or iOS.");
  176. }
  177. return false;
  178. },
  179. checkAdStatus: function (placementId) {
  180. if (undefined != platformBridge && platformBridge != null) {
  181. return platformBridge.checkAdStatus(placementId);
  182. } else {
  183. log("You must run on Android or iOS.");
  184. }
  185. return "";
  186. },
  187. showAd: function (placementId) {
  188. if (undefined != platformBridge && platformBridge != null) {
  189. platformBridge.showAd(placementId);
  190. } else {
  191. log("You must run on Android or iOS.");
  192. }
  193. },
  194. showAdInScenario: function (placementId, scenario = "") {
  195. if (undefined != platformBridge && platformBridge != null) {
  196. platformBridge.showAdInScenario(placementId, scenario);
  197. } else {
  198. log("You must run on Android or iOS.");
  199. }
  200. },
  201. entryAdScenario: function (placementId, scenario = "") {
  202. if (undefined != platformBridge && platformBridge != null) {
  203. platformBridge.entryAdScenario(placementId, scenario);
  204. } else {
  205. log("You must run on Android or iOS.");
  206. }
  207. },
  208. testMethod : function(){
  209. log("testing You must run on Android or iOS.");
  210. }
  211. };
  212. const LoadedCallbackKey = "RewardedVideoLoaded";
  213. const LoadFailCallbackKey = "RewardedVideoLoadFail";
  214. const PlayStartCallbackKey = "RewardedVideoPlayStart";
  215. const PlayEndCallbackKey = "RewardedVideoPlayEnd";
  216. const PlayFailCallbackKey = "RewardedVideoPlayFail";
  217. const CloseCallbackKey = "RewardedVideoClose";
  218. const ClickCallbackKey = "RewardedVideoClick";
  219. const RewardCallbackKey = "RewardedVideoReward";
  220. const BiddingAttempt = "RewardedVideoBiddingAttempt";
  221. const BiddingFilled = "RewardedVideoBiddingFilled";
  222. const BiddingFail = "RewardedVideoBiddingFail";
  223. const Attemp = "RewardedVideoAttemp";
  224. const LoadFilled = "RewardedVideoLoadFilled";
  225. const LoadFail = "RewardedVideoLoadFail";
  226. const AgainPlayStartCallbackKey = "RewardedVideoAgainPlayStart";
  227. const AgainPlayEndCallbackKey = "RewardedVideoAgainPlayEnd";
  228. const AgainPlayFailCallbackKey = "RewardedVideoAgainPlayFail";
  229. const AgainClickCallbackKey = "RewardedVideoAgainClick";
  230. const AgainRewardCallbackKey = "RewardedVideoAgainReward";
  231. window["ATRewardedVideoSDK"] = ATRewardedVideoSDK;
  232. export default ATRewardedVideoSDK;