UNPKG

camstreamerlib

Version:

Helper library for CamStreamer ACAP applications.

47 lines (46 loc) 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const fs = require("fs/promises"); class ResourceManager { co; imgFileNames = {}; fontFileNames = {}; images = {}; fonts = {}; constructor(co) { this.co = co; } registerImage(moniker, fileName) { this.imgFileNames[moniker] = process.env.INSTALL_PATH + '/images/' + fileName; } registerFont(moniker, fileName) { this.fontFileNames[moniker] = process.env.INSTALL_PATH + '/fonts/' + fileName; } async image(moniker) { if (this.images[moniker] !== undefined) { return this.images[moniker]; } if (this.imgFileNames[moniker] !== undefined) { const imgData = await fs.readFile(this.imgFileNames[moniker]); this.images[moniker] = await this.co.uploadImageData(imgData); return this.images[moniker]; } throw new Error('Error! Unknown image requested!'); } async font(moniker) { if (this.fonts[moniker] !== undefined) { return this.fonts[moniker]; } if (this.fontFileNames[moniker] !== undefined) { const fontData = await fs.readFile(this.fontFileNames[moniker]); this.fonts[moniker] = await this.co.uploadFontData(fontData); return this.fonts[moniker]; } throw new Error('Error! Unknown font requested!'); } clear() { this.images = {}; this.fonts = {}; } } exports.default = ResourceManager;