T
T
Tabuncov2022-02-18 13:20:43
JavaScript
Tabuncov, 2022-02-18 13:20:43

How to fix local clock deviation in js?

I create timers through moment.js for certain user actions. If the timer has expired, the conditional button disappears. But if the time on the device, for example, is behind, then it seems to the user that he did the action on time, but in reality the time has already passed, and an error is returned to him. This breeds misunderstanding.
You can, for example, get the exact current time with ajax from a server at intervals. (but the request also takes time, it will run out of sync)

Maybe there is a more reliable and elegant way to solve this problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Korotenko, 2022-02-18
@firedragon

reliable way to distrust the client.
That is, the start time is calculated as a delta between the sent server and the local one, the server time is in priority. And in general, everyone now has ntp

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question