// This Source Code Form is subject to the terms of the Mozilla Public
// License, v2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/
import { Logger } from "./logger";
const logger = Logger.getLogger();
const MAX_FRAME_AGE_MS = 5000; // Maximum age of a frame in milliseconds (5 seconds)
// Singleton class which provides last rendered frame for each topic
export class FrameStore {
    static #instance = null;
    #topicFrameMap = new Map();
    constructor() { }
    static getInstance() {
        if (!FrameStore.#instance) {
            FrameStore.#instance = new FrameStore();
        }
        return FrameStore.#instance;
    }
    registerFrame(topic, frame) {
        this.#topicFrameMap.set(topic, { ...frame, storedAt: performance.now() });
    }
    getFrame(topic) {
        const frameFromStorage = this.#topicFrameMap.get(topic);
        if (frameFromStorage && performance.now() - frameFromStorage.storedAt > MAX_FRAME_AGE_MS) {
            logger.warn("Skipping frame for topic", topic, "due to age");
            return undefined;
        }
        return frameFromStorage;
    }
}
//# sourceMappingURL=frame-store.js.map