Skip to main content
Glama
heartbeat.ts1.1 kB
// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors // SPDX-License-Identifier: Apache-2.0 import { TypedEventTarget } from '@medplum/core'; import type { MedplumServerConfig } from './config/types'; export type HeartbeatEventMap = { heartbeat: { type: 'heartbeat' }; }; export const heartbeat = new TypedEventTarget<HeartbeatEventMap>(); export const DEFAULT_HEARTBEAT_MS = 10 * 1000; let heartbeatTimer: NodeJS.Timeout | undefined; /** * Initializes heartbeat timers for WebSocket connections. * @param config - Medplum server config. */ export function initHeartbeat(config: MedplumServerConfig): void { if (!(config.heartbeatEnabled ?? true)) { return; } if (!heartbeatTimer) { heartbeatTimer = setInterval( () => heartbeat.dispatchEvent({ type: 'heartbeat' }), config.heartbeatMilliseconds ?? DEFAULT_HEARTBEAT_MS ); } } /** * Cleans up heartbeat timers for WebSocket connections. */ export function cleanupHeartbeat(): void { if (heartbeatTimer) { clearInterval(heartbeatTimer); heartbeatTimer = undefined; } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/medplum/medplum'

If you have feedback or need assistance with the MCP directory API, please join our Discord server