/** * Offset between this machine's clock and the server's, in milliseconds. * * Activity timestamps (a Spotify track's start and end, for instance) are * computed on the server and rendered here. A machine whose clock is a minute * off would draw the progress bar a minute out of place — or past the end of * the track — with nothing obviously wrong on screen. */ let offsetMs = 0; /** Called on every `ready`: the round trip is short enough to ignore. */ export function setServerTime(serverTime: number): void { offsetMs = Date.now() - serverTime; } /** `Date.now()` as the server would report it. */ export function serverNow(): number { return Date.now() - offsetMs; }