Path: blob/master/src/packages/frontend/app/monitor-pings.ts
1496 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45// Monitor ping events from webapp_client and use them to set some6// ping state in the page store.78import { redux } from "../app-framework";9import { webapp_client } from "../webapp-client";1011export function init_ping(): void {12webapp_client.on("ping", (ping_time: number): void => {13let ping_time_smooth = redux.getStore("page").get("avgping") ?? ping_time;1415// reset outside 3x16if (ping_time > 3 * ping_time_smooth || ping_time_smooth > 3 * ping_time) {17ping_time_smooth = ping_time;18} else {19const decay = 1 - Math.exp(-1);20ping_time_smooth = decay * ping_time_smooth + (1 - decay) * ping_time;21}22redux.getActions("page").set_ping(ping_time, Math.round(ping_time_smooth));23});24}252627