I'm new to Facebook Instant Game and now I don't know if it is possible to create a listener when context is updated? Specifically in my game, when the opponent completes their turn, the match will be updated and the context will be updated, at that time if I'm still in the game I want to make some changes to the UI . Of course I can check the data of the match every 5s and make changes but this is really a bad way. I hope to get help. Thanks!
Asked
Active
Viewed 88 times
0
-
This needs more information. Where are you storing context information? Unfortunately the SDK doesn't provide anywhere to store it today. – Chris Hawkins Aug 21 '19 at 22:18
-
Hi Chris, thanks for your reply. I use my server to store the match's data (using MongoDb), so when someone complete a turn I will update data in MongoDB and call update context (FB API). – copang Aug 22 '19 at 02:13
1 Answers
0
Thanks for the context. What you probably want to do here is poll for your data in your backend using a Timer in JavaScript combined with a fetch
request.
If you wanted it to be highly real-time, you could consider websockets, however websockets have many disadvantages on unreliable networks.

Chris Hawkins
- 764
- 4
- 15
-
So there is no way to create a listener to listen to context update events? And if so, I have to update the data after a period of time (eg 10 seconds), in this case, do you have any advice to optimize it? I think it will consume a lot of requests to the server. Thank you very much! – copang Aug 23 '19 at 04:39