import type { ServerTimeResponse } from '../models/ServerTimeResponse';
import type { CancelablePromise } from '../core/CancelablePromise';
import type { BaseHttpRequest } from '../core/BaseHttpRequest';
export declare class TimesyncService {
readonly httpRequest: BaseHttpRequest;
constructor(httpRequest: BaseHttpRequest);
/**
* Get current server time.
* Provides the server time that you must use when calculating the client-server-offset (cs_offset), which is used when calculating a client-side-estimated-server-time (Tcest).
Client-server-offset
The client-server-offset (cs_offset) can be calculated the following way:
- Collect X server time (Ts) samples using this endpoint. A higher number of samples will results in longer estimation time but a more accurate result. A good sample size is 30 (X = 30).
- Track the round-trip-delay (RTD) for each sample by recording the request send time (Tsend) and response received time (Treceive). Calculate RTD = Treceive – Tsend.
- Calculate the estimated server time when the response is received (Ts_est) by adding half the RTD time to the received server time value (Ts). Ts_est = Ts + RTD/2.
- Calculate the offset between estimated server time (Ts_est) and client time (Tc). Upon receive Tc == Treceive => offset = Ts_est - Treceive.
- Add the offset to the aggregated offset value (offset_agg). offset_agg = offset_agg + offset.
- When all samples have been received calculate the average offset (cs_offset) by dividing aggregated offset (offset_agg) values by the number of samples (X). cs_offset = offset_agg / X
The process above gives you a good estimate of the client-server-offset (cs_offset).
Normally you calculate the cs_offset once, and use it whenever you need to calculate client-side-estimated-server-time (Tcest).
However, if the synchronization between device and the service (eg. video/script synchronization) is off (maybe due to changing network topology, clock drift, bad initial calculation, etc.), it might help to re-calculate the cs_offset. Client-side-estimated-server-time
The client-side-estimated-server-time (Tcest) value is required in some of the API endpoints (eg. /hssp/play).
The Tcest is calculated the following way:
Tcest = Tc + cs_offset
where Tc is the current client time and cs_offset is the client-server-offset.
* @returns ServerTimeResponse Current server time in UNIX/Epoch time.
* @throws ApiError
*/
getServerTime(): CancelablePromise;
}