Currently, I am in the process of developing an application that requires users to perform certain actions within a specified countdown period.
The website's countdown must stay synchronized with TradingView's candle countdown.
https://i.sstatic.net/841Hc.png
- Initially, I attempted using
new Date()
, but found that it does not work properly if the browser time is adjusted. Even a slight 10-second difference between Tradingview time and Application time can have critical implications. In another attempt, I retrieved server time from the application API and incremented that value using a simple
setInterval()
method. However, there were instances where it lagged by 10-20 seconds.let timestamp = await getServerTime() setInterval(() => { timestamp++; this.currentTimestamp = timestamp }, 1000);
As a final resort, I experimented with utilizing a
service-worker
for the samesetInterval()
method and updating the component with the new value. Unfortunately, this approach also fell victim to lags after prolonged use.
Despite researching various solutions, none have effectively resolved this issue. Do you have any suggestions for accurately incorporating server-side time without encountering delays?
Thank you in advance!