3

Edit: The answer is to use firebase realtime database.

I wrote a library for the next person.

https://github.com/flipflopapp/turnbased-games-with-firebase

-- Question --

I am implementing two player chess game (www.halfchess.com) and am considering using firebase messaging (instead of using sockets to create rooms and two player matches). The game would involve sending 60-100 chess moves as messages between two devices in two to three minutes (that can be android or iOS). My nodejs server would have code that enables device to device messaging (receiving from one player and sending to other).

I cannot use Google Game Services because I don't have google login implemented in my app (I only plan to keep facebook login). The advantages of using firebase (compared to sockets) is that I will have to write much lesser code (reconnections, etc) and it would take care of scalability issues.

My questions are :-

(1) Will there be problems when the users playing against each other are on two iOS devices (instead of android's)? (such as higher latency)

(2) If a user is changing location physically and a message that contains a chess move is undelivered, when will it be retried?

(3) For a fast game of chess, will the latency be manageable? This is like 8-10 times the speed of normal chatting.

While I read more on the topic, perhaps someone who has already experimented can comment.

navalsaini
  • 522
  • 6
  • 20

4 Answers4

1

Firebase Cloud Messaging is not meant for kind of usage, and in addition to a non guaranteed delivery time (some researches from 2013 - 2014 shows more than 1 seconds per message on avarage), FCM will probably imply throttling in such a use case.

See also this SO post

Community
  • 1
  • 1
Yoni Gross
  • 816
  • 8
  • 16
  • Thanks. I realized I should be looking at Firebase realtime database (if atall I want to use firebase). - Link: http://stackoverflow.com/questions/36119776/is-firebase-realtime-json-database-suitable-for-data-broadcasting – navalsaini Jan 25 '17 at 02:59
  • Also I am sure GCM messaging better than it used to be. I think they started using firebase for GCM messaging since last year. That should improve upon the older problems mentioned in blogs dating (say, 2014) and before – navalsaini Jan 25 '17 at 03:01
  • I have no doubt FCM/GCM is better than it was in 2014. Yet, it's not meant for this purpose and may interfere with gameplay. I think that websockets is probably your best option, and using libraries like OkHttp, integration shouldn't be harder than FCM, and since you'll know when the connection got disconnected, you can reflect that on UI. – Yoni Gross Jan 25 '17 at 10:11
1

I'm sure the answers above will work but, I was having a tough time getting them to function. This is what eventually worked for me and my firebase chat app!

Hopefully, this will help some folks out there.

I was able to add a chess game to my firebase chat app and, all I used was an iframe! However, it didn't work the first time because, all I did was add the iframe coding to my app.

This is how I got my iframe to work in a firebase app...

First, change directory (cd) into your chat app's "public" folder (where you would typically run the "firebase deploy" command) and, add your iframe to the "index.html" document located there. Use this address for your iframe's source URL (src)...

src="chess/index.html"

  • It wont work right if you do not include the "index.html" page name!

Next, I created a new folder named "chess" in the same public directory and I added the chess game's "index.html" doc and dependanciess to it (js,css,images...etc).

And last, but not lease, open a terminal in the same "public" folder and run "firebase deploy" to upload the whole thing to your firebase account and console.

Done!

I'm pretty sure that including your chess app docs inside of your firebase app is what made the iframe finally work. I also wrapped the iframe with a couple of 'div' tags but, I'm not sure if that made any difference.

  • Please, feel free to come and take a look but, you'll have to sign in with Google to gain entry!

  • After that, just right-click anywhere on the page and select "view source" to see the code. Cheers!

https://friendly-chat-b2d6a.firebaseapp.com/

Eric Payne
  • 11
  • 3
0

Instead of having the other player send a message to the client, why not just have the client display a message based on whats happening in the game? It seems like an easier solution for you, as the only thing that needs to be sent is the actual move, and you can piggyback off of that if you need to.

Lauren Hinch
  • 340
  • 1
  • 11
  • The message (firebase terminology) and the move (chess terminology) are the same. I also tried to draw an analogy between a chat app and a chess app because firebase has mostly been tried with the former and there are some similarities. – navalsaini Jan 24 '17 at 19:29
  • Do you already have the main game in place? If so, you're already sending a message via moving the chess piece, and you can just get that on the client's side and display a message. – Lauren Hinch Jan 24 '17 at 19:31
  • I don't get it Vivan. This is a question about Firebase v/s Socket.io v/s other turn based real time gaming solutions. Thanks. – navalsaini Jan 24 '17 at 19:38
  • I understand that, I'm saying that you seem to be making extra work for yourself. If the gameplay of the game is already created, then why not just have the messages be entirely client-sided? You don't need the other player to send the move message, just have something like this (pseudo-code, of course) `if (pieceMoves) { get where the piece moved to, print it }` – Lauren Hinch Jan 24 '17 at 21:39
0

I realized I should be looking at Firebase Realtime database (and not messaging).

Useful links:

Community
  • 1
  • 1
navalsaini
  • 522
  • 6
  • 20