Skip to content

Commit 9dd7d2d

Browse files
committed
Merge branch 'master' of https://github.com/photonstorm/phaser
2 parents f111335 + 06c6b28 commit 9dd7d2d

3 files changed

Lines changed: 86 additions & 31 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
* `Leaderboard.getPlayerScore` now only populates the `playerScore` property if the entry isn't `null`.
1111
* If the `setScore` or `getPlayerScore` calls fail, it will return `null` as the score instance, instead of causing a run-time error.
1212
* You can now pass an object or a string to `setScore` and objects will be automatically stringified.
13+
* The `preloadAds` method will now only create an AdInstance object if the interstitial `loadSync` promise resolves.
14+
* The `preloadVideoAds` method will now only create an AdInstance object if the interstitial `loadSync` promise resolves.
15+
* The `preloadAds` method will now emit the `adsnofill` event, if there are no ads in the inventory to load.
16+
* The `preloadVideoAds` method will now emit the `adsnofill` event, if there are no ads in the inventory to load.
17+
* The `showAd` method will now emit the `adsnotloaded` event, if there are no ads loaded matching the given Placement ID.
18+
* The `showVideo` method will now emit the `adsnotloaded` event, if there are no ads loaded matching the given Placement ID.
19+
* Showing an ad will emit the `adfinished` event when the ad is closed, previously this event was called `showad` but the new name better reflects what has happened.
1320

1421
### Keyboard Input - New Features
1522

plugins/fbinstant/src/AdInstance.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
* @property {boolean} video - Is this a video ad?
1414
*/
1515

16-
var AdInstance = function (instance, video)
16+
var AdInstance = function (placementID, instance, video)
1717
{
1818
return {
1919
instance: instance,
20-
placementID: instance.getPlacementID(),
20+
placementID: placementID,
2121
shown: false,
2222
video: video
2323
};

plugins/fbinstant/src/FacebookInstantGamesPlugin.js

Lines changed: 77 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,6 +1870,10 @@ var FacebookInstantGamesPlugin = new Class({
18701870
* Attempt to create an instance of an interstitial ad.
18711871
*
18721872
* If the instance is created successfully then the ad is preloaded ready for display in-game via the method `showAd()`.
1873+
*
1874+
* If the ad loads it will emit the `adloaded` event, passing the AdInstance as the only parameter.
1875+
*
1876+
* If the ad cannot be displayed because there was no inventory to fill it, it will emit the `adsnofill` event.
18731877
*
18741878
* @method Phaser.FacebookInstantGamesPlugin#preloadAds
18751879
* @since 3.13.0
@@ -1912,28 +1916,50 @@ var FacebookInstantGamesPlugin = new Class({
19121916
for (i = 0; i < placementID.length; i++)
19131917
{
19141918
var id = placementID[i];
1919+
var data;
19151920

1916-
FBInstant.getInterstitialAdAsync(id).then(function (data)
1921+
FBInstant.getInterstitialAdAsync(id).then(function (interstitial)
19171922
{
1918-
var ad = AdInstance(data, true);
1919-
1923+
data = interstitial;
1924+
1925+
return interstitial.loadAsync();
1926+
1927+
}).then(function ()
1928+
{
1929+
var ad = AdInstance(id, data, false);
1930+
19201931
_this.ads.push(ad);
1921-
1922-
return ad.loadAsync();
1923-
1932+
1933+
_this.emit('adloaded', ad);
1934+
19241935
}).catch(function (e)
19251936
{
1926-
console.warn(e);
1937+
if (e.code === 'ADS_NO_FILL')
1938+
{
1939+
_this.emit('adsnofill', id);
1940+
}
1941+
else if (e.code === 'ADS_FREQUENT_LOAD')
1942+
{
1943+
_this.emit('adsfrequentload', id);
1944+
}
1945+
else
1946+
{
1947+
console.warn(e);
1948+
}
19271949
});
19281950
}
19291951

19301952
return this;
19311953
},
19321954

19331955
/**
1934-
* Attempt to create an instance of an interstitial video ad.
1956+
* Attempt to create an instance of an rewarded video ad.
19351957
*
19361958
* If the instance is created successfully then the ad is preloaded ready for display in-game via the method `showVideo()`.
1959+
*
1960+
* If the ad loads it will emit the `adloaded` event, passing the AdInstance as the only parameter.
1961+
*
1962+
* If the ad cannot be displayed because there was no inventory to fill it, it will emit the `adsnofill` event.
19371963
*
19381964
* @method Phaser.FacebookInstantGamesPlugin#preloadVideoAds
19391965
* @since 3.13.0
@@ -1976,18 +2002,36 @@ var FacebookInstantGamesPlugin = new Class({
19762002
for (i = 0; i < placementID.length; i++)
19772003
{
19782004
var id = placementID[i];
2005+
var data;
19792006

1980-
FBInstant.getRewardedVideoAsync(id).then(function (data)
2007+
FBInstant.getRewardedVideoAsync(id).then(function (reward)
19812008
{
1982-
var ad = AdInstance(data, true);
1983-
2009+
data = reward;
2010+
2011+
return reward.loadAsync();
2012+
2013+
}).then(function ()
2014+
{
2015+
var ad = AdInstance(id, data, true);
2016+
19842017
_this.ads.push(ad);
1985-
1986-
return ad.loadAsync();
1987-
2018+
2019+
_this.emit('adloaded', ad);
2020+
19882021
}).catch(function (e)
19892022
{
1990-
console.warn(e);
2023+
if (e.code === 'ADS_NO_FILL')
2024+
{
2025+
_this.emit('adsnofill', id);
2026+
}
2027+
else if (e.code === 'ADS_FREQUENT_LOAD')
2028+
{
2029+
_this.emit('adsfrequentload', id);
2030+
}
2031+
else
2032+
{
2033+
console.warn(e);
2034+
}
19912035
});
19922036
}
19932037

@@ -1997,9 +2041,9 @@ var FacebookInstantGamesPlugin = new Class({
19972041
/**
19982042
* Displays a previously loaded interstitial ad.
19992043
*
2000-
* If the ad is successfully displayed this plugin will emit the `showad` event, with the AdInstance object as its parameter.
2044+
* If the ad is successfully displayed this plugin will emit the `adfinished` event, with the AdInstance object as its parameter.
20012045
*
2002-
* If the ad cannot be displayed because there was no inventory to fill it, it will emit the `adsnofill` event.
2046+
* If the ad cannot be displayed, it will emit the `adsnotloaded` event.
20032047
*
20042048
* @method Phaser.FacebookInstantGamesPlugin#showAd
20052049
* @since 3.13.0
@@ -2022,18 +2066,20 @@ var FacebookInstantGamesPlugin = new Class({
20222066
{
20232067
ad.shown = true;
20242068

2025-
_this.emit('showad', ad);
2069+
_this.emit('adfinished', ad);
20262070

20272071
}).catch(function (e)
20282072
{
2029-
if (e.code === 'ADS_NO_FILL')
2073+
if (e.code === 'ADS_NOT_LOADED')
20302074
{
2031-
_this.emit('adsnofill');
2075+
_this.emit('adsnotloaded', ad);
20322076
}
2033-
else
2077+
else if (e.code === 'RATE_LIMITED')
20342078
{
2035-
console.warn(e);
2079+
_this.emit('adratelimited', ad);
20362080
}
2081+
2082+
_this.emit('adshowerror', e, ad);
20372083
});
20382084
}
20392085
}
@@ -2044,9 +2090,9 @@ var FacebookInstantGamesPlugin = new Class({
20442090
/**
20452091
* Displays a previously loaded interstitial video ad.
20462092
*
2047-
* If the ad is successfully displayed this plugin will emit the `showad` event, with the AdInstance object as its parameter.
2093+
* If the ad is successfully displayed this plugin will emit the `adfinished` event, with the AdInstance object as its parameter.
20482094
*
2049-
* If the ad cannot be displayed because there was no inventory to fill it, it will emit the `adsnofill` event.
2095+
* If the ad cannot be displayed, it will emit the `adsnotloaded` event.
20502096
*
20512097
* @method Phaser.FacebookInstantGamesPlugin#showVideo
20522098
* @since 3.13.0
@@ -2069,18 +2115,20 @@ var FacebookInstantGamesPlugin = new Class({
20692115
{
20702116
ad.shown = true;
20712117

2072-
_this.emit('showad', ad);
2118+
_this.emit('adfinished', ad);
20732119

20742120
}).catch(function (e)
20752121
{
2076-
if (e.code === 'ADS_NO_FILL')
2122+
if (e.code === 'ADS_NOT_LOADED')
20772123
{
2078-
_this.emit('adsnofill');
2124+
_this.emit('adsnotloaded', ad);
20792125
}
2080-
else
2126+
else if (e.code === 'RATE_LIMITED')
20812127
{
2082-
console.warn(e);
2128+
_this.emit('adratelimited', ad);
20832129
}
2130+
2131+
_this.emit('adshowerror', e, ad);
20842132
});
20852133
}
20862134
}

0 commit comments

Comments
 (0)