feat: time sync

closes #75
This commit is contained in:
2023-11-14 15:27:35 +00:00
parent 27cf614048
commit 080955532c
2 changed files with 15 additions and 0 deletions

View File

@ -24,6 +24,7 @@ import { register } from "serviceWorker";
import { IntlProvider } from "intl";
import { WidgetsPage } from "pages/widgets";
import { AlertsPage } from "pages/alerts";
import { unixNowMs } from "@snort/shared";
export enum StreamState {
Live = "live",
@ -45,12 +46,23 @@ Object.entries(defaultRelays).forEach(params => {
System.ConnectToRelay(relay, settings);
});
export let TimeSync = 0;
const router = createBrowserRouter([
{
element: <LayoutPage />,
loader: async () => {
db.ready = await db.isAvailable();
await System.Init();
try {
const req = await fetch("https://api.zap.stream/api/time");
const nowAtServer = (await req.json()).time as number;
const now = unixNowMs();
TimeSync = now - nowAtServer;
console.debug("Time clock sync", TimeSync);
} catch {
// ignore
}
return null;
},
children: [