Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] java – Start a countdown on several connected devices at the same time – Firebase Android

Posted on November 14, 2022

Solution 1 :

One of the factors affecting the client-side countdown timers is going to be the latency between each client and the server. A client with a faster connection will get the updated value sooner, and hence start the countdown timer sooner.

Firebase estimates this latency when the client first connects, and makes it available in the .info/serverTimeOffset node in the client. You can use this value to (partially) correct for the latency. For more on this, and sample code, see the documentation on clock skew.

Problem :

I’m creating an Android application, in which players are connected to Firebase Realtime Database (2 to 4 players per room). If I summarize what my code should do: players can click on a button each in turn. When a player clicks and it’s his turn, the app will write (with runTransaction) on the server an int type (for example “clicked:2” means that player 2 just clicked). When the “clicked” key is visible on the server (with addValueEventListener), all players connected to this room perform (at the same time and the execution is done on the client side) a 3 seconds CountDownTimer. During this countdown, all players (without exception) can click on their buttons, and if this is the case only the first one to click will be taken into account (because runTransaction) and will be written on the server. So everyone will see on his device that a player has clicked on his button during the countdown, and then we start all over again (i.e. it’s up to the next player to start the countdown etc).
Theoretically, this is fine, but a problem arise after testing (with an old and a new – and therefore faster – smartphone):

READ  [ANSWERED] Login from Android with Amplify and Login with Amazon
Powered by Inline Related Posts

Some devices are faster than others, and in most cases the countdown doesn’t start at the same time for different players. So I was thinking, for example (but others are possible, don’t hesitate to say so !), to write on the server at what time (in ms) the player clicked, and take this time + 500 ms (or other) to start the countdown. But for that you would need to have Firebase time (TimeStamp I think) and I don’t know how… (preferably only in Java, I don’t like to touch json too much)

Comments

Comment posted by Frank van Puffelen

I answered what I could before moving on to helping others. If you have more questions, I recommend opening a new question with a reduced scope.

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress