cordova-admob-tomitank 1.1.7 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,18 +17,15 @@ class AMBRewarded: AMBAdBase, FullScreenContentDelegate {
17
17
  RewardedAd.load(with: adUnitId, request: adRequest, completionHandler: { ad, error in
18
18
  if error != nil {
19
19
  self.emit(AMBEvents.adLoadFail, error!)
20
- self.emit(AMBEvents.rewardedLoadFail, error!)
21
-
22
20
  ctx.reject(error!)
23
21
  return
24
22
  }
25
23
 
26
- self.mAd = ad
24
+ self.mAd = ads
27
25
  ad?.fullScreenContentDelegate = self
28
26
  ad?.serverSideVerificationOptions = ctx.optServerSideVerificationOptions()
29
27
 
30
28
  self.emit(AMBEvents.adLoad)
31
- self.emit(AMBEvents.rewardedLoad)
32
29
 
33
30
  ctx.resolve()
34
31
  })
@@ -38,31 +35,26 @@ class AMBRewarded: AMBAdBase, FullScreenContentDelegate {
38
35
  mAd?.present(from: plugin.viewController, userDidEarnRewardHandler: {
39
36
  let reward = self.mAd!.adReward
40
37
  self.emit(AMBEvents.adReward, reward)
41
- self.emit(AMBEvents.rewardedReward, reward)
42
38
  })
43
39
  ctx.resolve()
44
40
  }
45
41
 
46
42
  func adDidRecordImpression(_ ad: FullScreenPresentingAd) {
47
43
  self.emit(AMBEvents.adImpression)
48
- self.emit(AMBEvents.rewardedImpression)
49
44
  }
50
45
 
51
46
  func ad(_ ad: FullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
52
47
  clear()
53
48
  self.emit(AMBEvents.adShowFail, error)
54
- self.emit(AMBEvents.rewardedShowFail, error)
55
49
  }
56
50
 
57
51
  func adWillPresentFullScreenContent(_ ad: FullScreenPresentingAd) {
58
52
  self.emit(AMBEvents.adShow)
59
- self.emit(AMBEvents.rewardedShow)
60
53
  }
61
54
 
62
55
  func adDidDismissFullScreenContent(_ ad: FullScreenPresentingAd) {
63
56
  clear()
64
57
  self.emit(AMBEvents.adDismiss)
65
- self.emit(AMBEvents.rewardedDismiss)
66
58
  }
67
59
 
68
60
  private func clear() {
@@ -17,8 +17,6 @@ class AMBRewardedInterstitial: AMBAdBase, FullScreenContentDelegate {
17
17
  RewardedInterstitialAd.load(with: adUnitId, request: adRequest, completionHandler: { ad, error in
18
18
  if error != nil {
19
19
  self.emit(AMBEvents.adLoadFail, error!)
20
- self.emit(AMBEvents.rewardedInterstitialLoadFail, error!)
21
-
22
20
  ctx.reject(error!)
23
21
  return
24
22
  }
@@ -28,7 +26,6 @@ class AMBRewardedInterstitial: AMBAdBase, FullScreenContentDelegate {
28
26
  ad?.serverSideVerificationOptions = ctx.optServerSideVerificationOptions()
29
27
 
30
28
  self.emit(AMBEvents.adLoad)
31
- self.emit(AMBEvents.rewardedInterstitialLoad)
32
29
 
33
30
  ctx.resolve()
34
31
  })
@@ -38,31 +35,26 @@ class AMBRewardedInterstitial: AMBAdBase, FullScreenContentDelegate {
38
35
  mAd?.present(from: plugin.viewController, userDidEarnRewardHandler: {
39
36
  let reward = self.mAd!.adReward
40
37
  self.emit(AMBEvents.adReward, reward)
41
- self.emit(AMBEvents.rewardedInterstitialReward, reward)
42
38
  })
43
39
  ctx.resolve()
44
40
  }
45
41
 
46
42
  func adDidRecordImpression(_ ad: FullScreenPresentingAd) {
47
43
  self.emit(AMBEvents.adImpression)
48
- self.emit(AMBEvents.rewardedInterstitialImpression)
49
44
  }
50
45
 
51
46
  func ad(_ ad: FullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
52
47
  clear()
53
48
  self.emit(AMBEvents.adShowFail, error)
54
- self.emit(AMBEvents.rewardedInterstitialShowFail, error)
55
49
  }
56
50
 
57
51
  func adWillPresentFullScreenContent(_ ad: FullScreenPresentingAd) {
58
52
  self.emit(AMBEvents.adShow)
59
- self.emit(AMBEvents.rewardedInterstitialShow)
60
53
  }
61
54
 
62
55
  func adDidDismissFullScreenContent(_ ad: FullScreenPresentingAd) {
63
56
  clear()
64
57
  self.emit(AMBEvents.adDismiss)
65
- self.emit(AMBEvents.rewardedInterstitialDismiss)
66
58
  }
67
59
 
68
60
  private func clear() {
package/src/www/admob.ts CHANGED
@@ -1,26 +1,26 @@
1
- import * as cordova from 'cordova'
2
- import channel from 'cordova/channel'
3
- import exec from 'cordova/exec'
4
- import { AdMob } from '.'
5
- import { MobileAd, NativeActions } from './shared'
1
+ import { AdMob } from '.';
2
+ import exec from 'cordova/exec';
3
+ import * as cordova from 'cordova';
4
+ import channel from 'cordova/channel';
5
+ import { MobileAd, NativeActions } from './shared';
6
6
 
7
- const admob = new AdMob()
7
+ const admob = new AdMob();
8
8
 
9
9
  function onMessageFromNative(event: any) {
10
- const { data } = event
10
+ const { data } = event;
11
11
  if (data && data.adId) {
12
- data.ad = MobileAd.getAdById(data.adId)
12
+ data.ad = MobileAd.getAdById(data.adId);
13
13
  }
14
- cordova.fireDocumentEvent(event.type, data)
14
+ cordova.fireDocumentEvent(event.type, data);
15
15
  }
16
16
 
17
- const feature = 'onAdMobPlusReady'
18
- channel.createSticky(feature)
19
- channel.waitForInitialization(feature)
17
+ const feature = 'onAdMobPlusReady';
18
+ channel.createSticky(feature);
19
+ channel.waitForInitialization(feature);
20
20
 
21
21
  channel.onCordovaReady.subscribe(() => {
22
- exec(onMessageFromNative, console.error, 'AdMob', NativeActions.ready, [])
23
- channel.initializationComplete(feature)
24
- })
22
+ exec(onMessageFromNative, console.error, 'AdMob', NativeActions.ready, []);
23
+ channel.initializationComplete(feature);
24
+ });
25
25
 
26
- export default admob
26
+ export default admob;
package/src/www/api.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { execAsync, NativeActions } from './generated'
2
-
3
- export { execAsync, AdSizeType, Events, NativeActions } from './generated'
1
+ import BannerAd from './banner';
2
+ import { execAsync, Events, NativeActions } from './generated';
3
+ export { execAsync, AdSizeType, Events, NativeActions } from './generated';
4
4
 
5
5
  /** @internal */
6
6
  export type MobileAdOptions = {
@@ -9,104 +9,108 @@ export type MobileAdOptions = {
9
9
  contentUrl?: string
10
10
  keywords?: string[]
11
11
  npa?: '1'
12
- }
12
+ };
13
+
14
+ let started = false;
15
+ let startPromise: Promise<{ version: string }> | null = null;
16
+ type AdEventNames = Exclude<keyof typeof Events, 'ready'> extends infer K
17
+ ? K extends keyof typeof Events
18
+ ? typeof Events[K] extends `admob.${string}.${infer EventName}`
19
+ ? EventName
20
+ : never
21
+ : never
22
+ : never;
13
23
 
14
- let started = false
15
- let startPromise: Promise<{ version: string }> | null = null
24
+ // Size and dimension currently only apply to the banner
25
+ type AdEventNamesByType<T extends MobileAd<any>> = T extends BannerAd ? Omit<AdEventNames, 'size'|'sizechange'> : AdEventNames;
16
26
 
17
27
  /** @internal */
18
28
  export async function start() {
19
- startPromise = execAsync(NativeActions.start) as Promise<{ version: string }>
20
- const result = await startPromise
21
- started = true
22
- return result
29
+ startPromise = execAsync(NativeActions.start) as Promise<{ version: string }>;
30
+ const result = await startPromise;
31
+ started = true;
32
+ return result;
23
33
  }
24
34
 
25
35
  /** @internal */
26
36
  export class MobileAd<T extends MobileAdOptions = MobileAdOptions> {
27
- public static readonly type: string = ''
28
-
29
- private static allAds: { [s: string]: MobileAd } = {}
30
- private static idCounter = 0
31
-
32
- public readonly id: string
33
-
34
- protected readonly opts: T
35
- private _created = false
36
- private _init: Promise<any> | null = null
37
+ public static readonly type: string = '';
38
+ private static allAds: { [s: string]: MobileAd } = {};
39
+ public readonly id: string;
40
+ protected readonly opts: T;
41
+ private _created = false;
42
+ private _init: Promise<any> | null = null;
37
43
 
38
44
  constructor(opts: T) {
39
- this.opts = opts
40
-
45
+ this.opts = opts;
41
46
  this.id = opts.id ?? opts.adUnitId;
42
- MobileAd.allAds[this.id] = this
47
+ MobileAd.allAds[this.id] = this;
43
48
  }
44
49
 
45
50
  public static getAdById(id: string) {
46
- return this.allAds[id]
51
+ return this.allAds[id];
47
52
  }
48
53
 
49
54
  public get adUnitId() {
50
- return this.opts.adUnitId
55
+ return this.opts.adUnitId;
51
56
  }
52
57
 
53
- public on(...args: Parameters<typeof document.addEventListener>): () => void {
54
- const [eventName, cb, ...rest] = args
55
- const type = `admob.ad.${eventName.toLowerCase()}`
56
- const listener = (evt: any) => {
58
+ public on<EventNames extends AdEventNamesByType<this>>(eventName: EventNames, callback: (ev: Event) => any, useCapture?: boolean): () => void {
59
+ const type = `admob.ad.${eventName.toLowerCase()}`;
60
+ const listener = (evt: Event & { ad?: MobileAd }) => {
57
61
  if (evt.ad === this) {
58
- cb(evt)
62
+ callback(evt);
59
63
  }
60
- }
61
- document.addEventListener(type, listener, ...rest)
64
+ };
65
+ document.addEventListener(type, listener, useCapture);
62
66
 
63
67
  return () => {
64
- document.removeEventListener(type, listener, ...rest)
65
- }
68
+ document.removeEventListener(type, listener, useCapture);
69
+ };
66
70
  }
67
71
 
68
72
  protected async isLoaded() {
69
- await this.init()
73
+ await this.init();
70
74
  return execAsync(NativeActions.adIsLoaded, [
71
75
  { id: this.id },
72
- ]) as Promise<boolean>
76
+ ]) as Promise<boolean>;
73
77
  }
74
78
 
75
79
  protected async load() {
76
80
  await this.init()
77
81
  // TODO read `opts` in native code?
78
- await execAsync(NativeActions.adLoad, [{ ...this.opts, id: this.id }])
82
+ await execAsync(NativeActions.adLoad, [{ ...this.opts, id: this.id }]);
79
83
  }
80
84
 
81
85
  protected async show(opts?: Record<string, any>) {
82
86
  await this.init()
83
- return execAsync(NativeActions.adShow, [{ ...opts, id: this.id }])
87
+ return execAsync(NativeActions.adShow, [{ ...opts, id: this.id }]);
84
88
  }
85
89
 
86
90
  protected async hide() {
87
- return execAsync(NativeActions.adHide, [{ id: this.id }])
91
+ return execAsync(NativeActions.adHide, [{ id: this.id }]);
88
92
  }
89
93
 
90
94
  protected async init() {
91
- if (this._created) return
95
+ if (this._created) return;
92
96
 
93
97
  if (!started) {
94
- if (startPromise === null) start()
95
- await startPromise
98
+ if (startPromise === null) start();
99
+ await startPromise;
96
100
  }
97
101
 
98
102
  if (this._init === null) {
99
103
  const cls =
100
104
  (this.constructor as unknown as { cls?: string }).cls ??
101
- this.constructor.name
105
+ this.constructor.name;
102
106
 
103
107
  this._init = execAsync(NativeActions.adCreate, [
104
108
  { ...this.opts, id: this.id, cls },
105
- ])
109
+ ]);
106
110
  }
107
111
 
108
- await this._init
109
- this._created = true
112
+ await this._init;
113
+ this._created = true;
110
114
  }
111
115
  }
112
116
 
@@ -119,12 +123,12 @@ export enum MaxAdContentRating {
119
123
  }
120
124
 
121
125
  export type RequestConfig = {
122
- maxAdContentRating?: MaxAdContentRating
123
- sameAppKey?: boolean,
124
- tagForChildDirectedTreatment?: boolean | null
125
- tagForUnderAgeOfConsent?: boolean | null
126
- testDeviceIds?: string[]
127
- }
126
+ maxAdContentRating?: MaxAdContentRating;
127
+ publisherFirstPartyIDEnabled?: boolean;
128
+ tagForChildDirectedTreatment?: boolean | null;
129
+ tagForUnderAgeOfConsent?: boolean | null;
130
+ testDeviceIds?: string[];
131
+ };
128
132
 
129
133
  export const enum Platforms {
130
134
  android = 'android',
@@ -141,4 +145,4 @@ export enum TrackingAuthorizationStatus {
141
145
  export type AdMobConfig = {
142
146
  appMuted?: boolean
143
147
  appVolume?: number
144
- } & RequestConfig
148
+ } & RequestConfig;
@@ -1,70 +1,32 @@
1
1
  // THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2
2
  export enum NativeActions {
3
- adCreate = 'adCreate',
4
- adHide = 'adHide',
5
- adIsLoaded = 'adIsLoaded',
3
+ ready = 'ready',
4
+ start = 'start',
6
5
  adLoad = 'adLoad',
7
6
  adShow = 'adShow',
8
- bannerConfig = 'bannerConfig',
9
- bannerHide = 'bannerHide',
10
- bannerLoad = 'bannerLoad',
11
- bannerShow = 'bannerShow',
12
- configRequest = 'configRequest',
7
+ adHide = 'adHide',
8
+ adCreate = 'adCreate',
13
9
  configure = 'configure',
14
- interstitialIsLoaded = 'interstitialIsLoaded',
15
- interstitialLoad = 'interstitialLoad',
16
- interstitialShow = 'interstitialShow',
17
- ready = 'ready',
18
- requestTrackingAuthorization = 'requestTrackingAuthorization',
19
- rewardedInterstitialIsLoaded = 'rewardedInterstitialIsLoaded',
20
- rewardedInterstitialLoad = 'rewardedInterstitialLoad',
21
- rewardedInterstitialShow = 'rewardedInterstitialShow',
22
- rewardedIsLoaded = 'rewardedIsLoaded',
23
- rewardedLoad = 'rewardedLoad',
24
- rewardedShow = 'rewardedShow',
10
+ adIsLoaded = 'adIsLoaded',
25
11
  setAppMuted = 'setAppMuted',
26
12
  setAppVolume = 'setAppVolume',
27
- start = 'start',
13
+ bannerConfig = 'bannerConfig',
14
+ configRequest = 'configRequest',
15
+ requestTrackingAuthorization = 'requestTrackingAuthorization'
28
16
  }
29
17
 
30
18
  export enum Events {
31
- adClick = 'admob.ad.click',
32
- adDismiss = 'admob.ad.dismiss',
33
- adImpression = 'admob.ad.impression',
34
- adLoad = 'admob.ad.load',
35
- adLoadFail = 'admob.ad.loadfail',
36
- adReward = 'admob.ad.reward',
37
- adShow = 'admob.ad.show',
38
- adShowFail = 'admob.ad.showfail',
39
- bannerClick = 'admob.banner.click',
40
- bannerClose = 'admob.banner.close',
41
- bannerImpression = 'admob.banner.impression',
42
- bannerLoad = 'admob.banner.load',
43
- bannerLoadFail = 'admob.banner.loadfail',
44
- bannerOpen = 'admob.banner.open',
45
- bannerSize = 'admob.banner.size',
46
- bannerSizeChange = 'admob.banner.sizechange',
47
- interstitialDismiss = 'admob.interstitial.dismiss',
48
- interstitialImpression = 'admob.interstitial.impression',
49
- interstitialLoad = 'admob.interstitial.load',
50
- interstitialLoadFail = 'admob.interstitial.loadfail',
51
- interstitialShow = 'admob.interstitial.show',
52
- interstitialShowFail = 'admob.interstitial.showfail',
53
- ready = 'admob.ready',
54
- rewardedDismiss = 'admob.rewarded.dismiss',
55
- rewardedImpression = 'admob.rewarded.impression',
56
- rewardedInterstitialDismiss = 'admob.rewardedi.dismiss',
57
- rewardedInterstitialImpression = 'admob.rewardedi.impression',
58
- rewardedInterstitialLoad = 'admob.rewardedi.load',
59
- rewardedInterstitialLoadFail = 'admob.rewardedi.loadfail',
60
- rewardedInterstitialReward = 'admob.rewardedi.reward',
61
- rewardedInterstitialShow = 'admob.rewardedi.show',
62
- rewardedInterstitialShowFail = 'admob.rewardedi.showfail',
63
- rewardedLoad = 'admob.rewarded.load',
64
- rewardedLoadFail = 'admob.rewarded.loadfail',
65
- rewardedReward = 'admob.rewarded.reward',
66
- rewardedShow = 'admob.rewarded.show',
67
- rewardedShowFail = 'admob.rewarded.showfail',
19
+ ready = "admob.ready",
20
+ adLoad = "admob.ad.load",
21
+ adShow = "admob.ad.show",
22
+ adClick = "admob.ad.click",
23
+ adReward = "admob.ad.reward",
24
+ adDismiss = "admob.ad.dismiss",
25
+ adLoadFail = "admob.ad.loadfail",
26
+ adShowFail = "admob.ad.showfail",
27
+ adImpression = "admob.ad.impression",
28
+ bannerSizeChange = "admob.ad.sizechange", // use same path
29
+ bannerSize = "admob.ad.size" // use same path
68
30
  }
69
31
 
70
32
  export enum AdSizeType {
package/src/www/index.ts CHANGED
@@ -1,14 +1,14 @@
1
- import AppOpenAd from './app-open'
2
- import BannerAd, { BannerAdOptions } from './banner'
3
- import InterstitialAd from './interstitial'
4
- import NativeAd, { NativeAdOptions } from './native'
1
+ import AppOpenAd from './app-open';
2
+ import InterstitialAd from './interstitial';
3
+ import BannerAd, { BannerAdOptions } from './banner';
4
+ import NativeAd, { NativeAdOptions } from './native';
5
5
  import RewardedAd, {
6
6
  RewardedAdOptions,
7
7
  ServerSideVerificationOptions,
8
- } from './rewarded'
8
+ } from './rewarded';
9
9
  import RewardedInterstitialAd, {
10
10
  RewardedInterstitialAdOptions,
11
- } from './rewarded-interstitial'
11
+ } from './rewarded-interstitial';
12
12
  import {
13
13
  AdMobConfig,
14
14
  Events,
@@ -19,9 +19,9 @@ import {
19
19
  start,
20
20
  AdSizeType,
21
21
  TrackingAuthorizationStatus,
22
- } from './shared'
22
+ } from './shared';
23
23
 
24
- export * from './api'
24
+ export * from './api';
25
25
  export {
26
26
  AppOpenAd,
27
27
  BannerAd,
@@ -34,56 +34,56 @@ export {
34
34
  RewardedInterstitialAd,
35
35
  RewardedInterstitialAdOptions,
36
36
  ServerSideVerificationOptions,
37
- }
37
+ };
38
38
 
39
39
  export class AdMob {
40
- public readonly AppOpenAd = AppOpenAd
41
- public readonly BannerAd = BannerAd
42
- public readonly InterstitialAd = InterstitialAd
43
- public readonly NativeAd = NativeAd
44
- public readonly RewardedAd = RewardedAd
45
- public readonly RewardedInterstitialAd = RewardedInterstitialAd
46
- public readonly AdSizeType = AdSizeType
47
- public readonly Events = Events
48
- public readonly TrackingAuthorizationStatus = TrackingAuthorizationStatus
40
+ public readonly AppOpenAd = AppOpenAd;
41
+ public readonly BannerAd = BannerAd;
42
+ public readonly InterstitialAd = InterstitialAd;
43
+ public readonly NativeAd = NativeAd;
44
+ public readonly RewardedAd = RewardedAd;
45
+ public readonly RewardedInterstitialAd = RewardedInterstitialAd;
46
+ public readonly AdSizeType = AdSizeType;
47
+ public readonly Events = Events;
48
+ public readonly TrackingAuthorizationStatus = TrackingAuthorizationStatus;
49
49
 
50
- configure(config: AdMobConfig) {
51
- return execAsync(NativeActions.configure, [config])
50
+ public configure(config: AdMobConfig) {
51
+ return execAsync(NativeActions.configure, [config]);
52
52
  }
53
53
 
54
54
  public configRequest(requestConfig: RequestConfig) {
55
- return execAsync(NativeActions.configRequest, [requestConfig])
55
+ return execAsync(NativeActions.configRequest, [requestConfig]);
56
56
  }
57
57
 
58
58
  public setAppMuted(value: boolean) {
59
- return execAsync(NativeActions.setAppMuted, [value])
59
+ return execAsync(NativeActions.setAppMuted, [value]);
60
60
  }
61
61
 
62
62
  public setAppVolume(value: number) {
63
- return execAsync(NativeActions.setAppVolume, [value])
63
+ return execAsync(NativeActions.setAppVolume, [value]);
64
64
  }
65
65
 
66
66
  public start() {
67
- return start()
67
+ return start();
68
68
  }
69
69
 
70
70
  public async requestTrackingAuthorization(): Promise<
71
71
  TrackingAuthorizationStatus | false
72
72
  > {
73
73
  if (cordova.platformId === Platforms.ios) {
74
- const n = await execAsync(NativeActions.requestTrackingAuthorization)
74
+ const n = await execAsync(NativeActions.requestTrackingAuthorization);
75
75
  if (n !== false) {
76
76
  return TrackingAuthorizationStatus[
77
77
  TrackingAuthorizationStatus[n as number]
78
- ]
78
+ ];
79
79
  }
80
80
  }
81
- return false
81
+ return false;
82
82
  }
83
83
  }
84
84
 
85
85
  declare global {
86
- const admob: AdMob
86
+ const admob: AdMob;
87
87
  }
88
88
 
89
- export default AdMob
89
+ export default AdMob;