diff --git a/CHANGELOG.md b/CHANGELOG.md index 80cadd19c..d73947f26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Facebook Instant Games Plugin * Calling `showAd` or `showVideoAd` will now check to see if the ad has already been displayed, and skip it when iterating the ads array, allowing you to display an ad with the same Placement ID without preloading it again. Fix #4728 (thanks @NokFrt) +* Calling `gameStarted` in a game that doesn't load any assets would cause the error `{code: "INVALID_OPERATION", message: "Can not perform this operation before game start."}`. The plugin will now has a new internal method `gameStartedHandler` and will redirect the flow accordingly based on asset loading. Fix #4550 (thanks @bchee) ### New Features diff --git a/plugins/fbinstant/src/FacebookInstantGamesPlugin.js b/plugins/fbinstant/src/FacebookInstantGamesPlugin.js index ce6755cb9..476f41105 100644 --- a/plugins/fbinstant/src/FacebookInstantGamesPlugin.js +++ b/plugins/fbinstant/src/FacebookInstantGamesPlugin.js @@ -387,7 +387,7 @@ var FacebookInstantGamesPlugin = new Class({ { this.hasLoaded = true; - FBInstant.startGameAsync().then(this.gameStarted.bind(this)); + FBInstant.startGameAsync().then(this.gameStartedHandler.bind(this)); } }, this); @@ -408,6 +408,27 @@ var FacebookInstantGamesPlugin = new Class({ * @since 3.13.0 */ gameStarted: function () + { + if (!this.hasLoaded) + { + this.hasLoaded = true; + + FBInstant.startGameAsync().then(this.gameStartedHandler.bind(this)); + } + else + { + this.gameStartedHandler(); + } + }, + + /** + * The internal gameStarted handler. + * + * @method Phaser.FacebookInstantGamesPlugin#gameStartedHandler + * @private + * @since 3.20.0 + */ + gameStartedHandler: function () { var APIs = FBInstant.getSupportedAPIs();