Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dummy API #6

Open
subsoap opened this issue Mar 20, 2018 · 5 comments
Open

Dummy API #6

subsoap opened this issue Mar 20, 2018 · 5 comments
Labels
improvement Improvement of existing feature

Comments

@subsoap
Copy link
Contributor

subsoap commented Mar 20, 2018

There's a version of the API which returns dummy results, not require connection to Facebook for testing, may be useful to support somehow

@britzl
Copy link
Contributor

britzl commented Mar 20, 2018

Do you have some more information about this?

@britzl britzl added the more info More information is needed before work can begin label Mar 20, 2018
@subsoap
Copy link
Contributor Author

subsoap commented Mar 20, 2018

There is a "mock" api included in the example https://origincache.facebook.com/developers/resources/?id=tic-tac-toe.zip
fbinstant.6.0.mock.js.txt

It returns dummy values to all function calls. Could detect if the domain is localhost, and then load the dummy api instead. That way building Instant Game apps with Defold would be easier doing Project -> Build HTML in the editor.

@britzl
Copy link
Contributor

britzl commented Mar 21, 2018

Ah, I see. Ok, so that mocks the fbinstant js api. That might be useful.

I actually also provide a mock version of the fbinstant.* namespace for rapid testing on desktop, without the need to build/bundle to HTML5. It's a pure-Lua implementation of the fbinstant.* functions with static responses (no backend or anything like that involved). I'm not sure if I want to document it since I'm not sure of its usefulness yet. The mock version is in fbinstant.utils.mock.lua. require() it in a main/loader script before calling any fbinstant functions and give it some dummy data about the player(s) and context:

-- mock fbinstant.* to test your game without the need to build/bundle for HTML5
require "fbinstant.utils.mock"
-- this will be true on non HTML5 builds
if fbinstant.mock then
	-- this is the logged in player
	fbinstant.PLAYER = {
		name = "Player 1",
		id = "100000000001fake",
		photo = "http://i.pravatar.cc/200?u=123",
		locale = "en_US",
	}

	-- these are the players in the current context (fbinstant.get_players())
	fbinstant.PLAYERS = {
		fbinstant.PLAYER,
		{
			name = "Player 2",
			id = "100000000002fake",
			photo = "http://i.pravatar.cc/200?u=456",
			locale = "en_US",
		}
	}

	-- the current context
	fbinstant.CONTEXT = {
		id = "123456fake",
		type = fbinstant.CONTEXT_THREAD,
		size = 2,
	}
end

@britzl britzl added improvement Improvement of existing feature and removed more info More information is needed before work can begin labels Mar 21, 2018
@subsoap
Copy link
Contributor Author

subsoap commented Mar 21, 2018

Desktop builds are faster than HTML5 so it would be useful too. The problem I see is needing to update so many things as the API changes.

I'm going to go all in on making some big Facebook Instant Games (and port some in progress projects to it) so anything to help productivity will be useful and I bet others will appreciate it too!

Another thing which may be useful would be a chrome extension or js include which can detect new builds somehow and autoreload the web page... I've used something like that with other tools before. Another way to do it would be to make the build script open a fresh page but have a for example Chrome extension auto close other tabs of the specified name...

@britzl
Copy link
Contributor

britzl commented Mar 21, 2018

I can't imagine that Facebook would make many API changes now that the API is public. Sure, they may deprecate functions and add new ones, but the ones that are documented now are not likely to change.

It would be quite useful if Facebook provided this mock API somewhere more accessible, instead of hidden away inside a zip. Or if they provided an API definition in a parsable format so that something like my mock.lua file could be autogenerated much in the same way as Amazon provides API definitions for the AWS SDK.

@britzl britzl added this to To do in FBInstant development Apr 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improvement of existing feature
Projects
Development

No branches or pull requests

2 participants