AdAgentGoogleWeb.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import AdAgent from "./AdAgent";
  2. import { BannerLocation } from "./YZ_Constant";
  3. export default class AdAgentGoogleWeb extends AdAgent {
  4. googleAd: any = null;
  5. public Init(): void {
  6. console.log("[init googleWebAd]");
  7. //@ts-ignore
  8. this.googleAd = window.googleApi
  9. }
  10. public ShowBanner(location: BannerLocation = null) {
  11. console.log("[YouzhiAd ShowBanner] :" + location);
  12. this.googleAd && this.googleAd.showBanner();
  13. }
  14. public ShowInterstitial() {
  15. console.log("[YouzhiAd ShowInterstitial]");
  16. this.googleAd && this.googleAd.ShowInterstitial();
  17. }
  18. public HideBanner(location: BannerLocation = null) {
  19. console.log("[YouzhiAd HideBanner]");
  20. this.googleAd && this.googleAd.hideBanner();
  21. }
  22. _videoIsPlay: boolean = false;
  23. public ShowVideo(callback: Function) {
  24. console.log("[YouzhiAd ShowVideo]");
  25. if (this._videoIsPlay) {
  26. console.warn("[YouzhiAd Video Ad is Loading]");
  27. return;
  28. }
  29. this._videoIsPlay = true;
  30. //@ts-ignore
  31. let videoAdSuccess = () => {
  32. this._videoIsPlay = false;
  33. callback(true, "视频播放成功!");
  34. }
  35. //@ts-ignore
  36. let videoAdFail = (msg) => {
  37. this._videoIsPlay = false;
  38. callback(false, msg ? msg : "视频播放失败!");
  39. }
  40. this.googleAd && this.googleAd.showVideo(videoAdSuccess, videoAdFail);
  41. }
  42. }
  43. // var googleApi = new Object();
  44. // googleApi.showBanner = () => {
  45. // console.log("=====google showBanner=====");
  46. // }
  47. // googleApi.ShowInterstitial = () => {
  48. // console.log("=====google ShowInterstitial=====");
  49. // }
  50. // googleApi.hideBanner = () => {
  51. // console.log("=====google hideBanner=====");
  52. // }
  53. // googleApi.showVideo = (successFunc, failFunc) => {
  54. // console.log("=====google ShowVideo=====");
  55. // successFunc();
  56. // }
  57. // window.googleApi = googleApi;