Skip to content

Commit

Permalink
API upgrades and fixes (#24)
Browse files Browse the repository at this point in the history
* Added API Tester app/example
* Added on_pause function
* Changed to 6.1 and moved index.html to within the extension
* Finally got interstitial ads working
  • Loading branch information
britzl authored Mar 25, 2018
1 parent eaed06f commit d87aff4
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 11 deletions.
39 changes: 28 additions & 11 deletions fbinstant/lib/js-web/library_fbinstant.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,27 @@ var FBInstantLibrary = {
},
},

$Interstitials: {
ads: [],
$Ads: {
instances: [],
remove: function(placementId) {
for(var i=0; i<Ads.instances.length; i++) {
var instance = Ads.instances[i];
if (instance.placementId == placementId) {
Ads.instances.splice(i, 1);
return instance.ad;
}
}
return null;
},
insert: function(placementId, ad) {
console.log("Ads.insert()");
console.log("Ads.insert() " + placementId.toString() + " " + ad.toString());
Ads.instances.push({
placementId: placementId,
ad: ad,
});
console.log("Ads.insert() done");
}
},


Expand Down Expand Up @@ -400,7 +419,6 @@ var FBInstantLibrary = {
FBInstant_PlatformShareAsync: function(callback, cpayloadJson) {
var payloadJson = Pointer_stringify(cpayloadJson);
var payload = JSON.parse(payloadJson);
console.log("FBInstant_PlatformShareAsync - payload", payload);
FBInstant.shareAsync(payload).then(function() {
Runtime.dynCall("vi", callback, [1]);
}).catch(function(err) {
Expand Down Expand Up @@ -556,14 +574,14 @@ var FBInstantLibrary = {
});
},



FBInstant_PlatformLoadInterstitialAdAsync: function(callback, cplacementId) {
var placementId = Pointer_stringify(cplacementId);
var adInstance;
FBInstant.getInterstitialAdAsync(placementId).then(function(interstitial) {
Interstitials.ads.push(interstitial);
adInstance = interstitial;
return interstitial.loadAsync();
}).then(function() {
Ads.insert(placementId, adInstance);
Runtime.dynCall("vi", callback, [1]);
}).catch(function(err) {
console.log("FBInstant_PlatformLoadInterstitialAdAsync - error", err);
Expand All @@ -572,12 +590,11 @@ var FBInstantLibrary = {
},
FBInstant_PlatformShowInterstitialAdAsync: function(callback, cplacementId) {
var placementId = Pointer_stringify(cplacementId);
var interstitial = Interstitials.ads.find(function(ad) { return ad.getPlacementID() == placementId; });
if (interstitial) {
interstitial.showAsync().then(function() {
var ad = Ads.remove(placementId);
if (ad) {
ad.showAsync().then(function() {
Runtime.dynCall("vi", callback, [1]);
}).catch(function(err) {
console.log("FBInstant_PlatformShowInterstitialAdAsync - error", err);
Runtime.dynCall("vi", callback, [0]);
});
}
Expand All @@ -590,6 +607,6 @@ var FBInstantLibrary = {

autoAddDeps(FBInstantLibrary, "$Context");
autoAddDeps(FBInstantLibrary, "$Utils");
autoAddDeps(FBInstantLibrary, "$Interstitials");
autoAddDeps(FBInstantLibrary, "$Ads");

mergeInto(LibraryManager.library, FBInstantLibrary);
14 changes: 14 additions & 0 deletions fbinstant/utils/mock.lua
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,17 @@ function fbinstant.increment_store_data(store_name, data_json, cb)
cb(get_self(), rxijson.encode(result))
end
end

--------------------------------
--------------- ADS
--------------------------------

function fbinstant.load_interstitial_ad(placement, cb)
print("load_interstitial_ad")
cb(get_self(), true)
end

function fbinstant.show_interstitial_ad(placement, cb)
print("show_interstitial_ad")
cb(get_self(), true)
end
11 changes: 11 additions & 0 deletions tictactoe/start/start.gui_script
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ function init(self)
else
show_select_opponent_button(self)
end

local placement = "130801227620858_156771488357165"
fbinstant.load_interstitial_ad(placement, function(self, success)
print("loaded interstitial", success)
if not success then
return
end
fbinstant.show_interstitial_ad(placement, function(self, success)
print("showed interstitial", success)
end)
end)
end


Expand Down

0 comments on commit d87aff4

Please sign in to comment.