UNPKG

@ntrip/caster

Version:
83 lines (82 loc) 4.54 kB
"use strict"; /* * This file is part of the @ntrip/caster distribution (https://github.com/node-ntrip/caster). * Copyright (c) 2020 Nebojsa Cvetkovic. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SimpleLogger = void 0; const chalk_1 = __importDefault(require("chalk")); class SimpleLogger { constructor(caster) { this.registeredListeners = []; // Mountpoint created this.listen(caster, 'mountpoint', mountpoint => { // Mountpoint created console.log(chalk_1.default `/{red ${mountpoint.name}} ++ Mountpoint created`); // Mountpoint closed this.listen(mountpoint, 'close', () => { console.log(chalk_1.default `/{red ${mountpoint.name}} {grey --} Mountpoint closed`); }); // Client connected this.listen(mountpoint, 'client', client => { console.log(chalk_1.default `/{red ${mountpoint.name}} => {italic ${client.transport.description}}://{green ${client.source}} - Client connected to mountpoint`); // Client disconnected this.listen(client, 'close', () => { console.log(chalk_1.default `/{red ${mountpoint.name}} {grey =!} {italic ${client.transport.description}}://{green ${client.source}} - Client disconnected from mountpoint`); }); }); // Server connected this.listen(mountpoint, 'server', server => { console.log(chalk_1.default `/{red ${mountpoint.name}} <= {italic ${server.transport.description}}://{blue ${server.source}} - Server connected to mountpoint`); // Server disconnected this.listen(server, 'close', () => { console.log(chalk_1.default `/{red ${mountpoint.name}} {grey !=} {italic ${server.transport.description}}://{blue ${server.source}} - Server disconnected from mountpoint`); }); }); // Server silence this.listen(mountpoint, 'silence', () => { var _a, _b; console.log(chalk_1.default `/{red ${mountpoint.name}} {yellow ?=} {italic ${(_a = mountpoint.server) === null || _a === void 0 ? void 0 : _a.transport.description}}://{blue ${(_b = mountpoint.server) === null || _b === void 0 ? void 0 : _b.source}} - Server has not sent any data for {bold ${mountpoint.options.silenceWarningTimeout / 1000} seconds}, may be disconnected due to inactivity`); }); // Server inactivity this.listen(mountpoint, 'inactivity', () => { var _a, _b; console.log(chalk_1.default `/{red ${mountpoint.name}} {red !=} {italic ${(_a = mountpoint.server) === null || _a === void 0 ? void 0 : _a.transport.description}}://{blue ${(_b = mountpoint.server) === null || _b === void 0 ? void 0 : _b.source}} - Server disconnected due to inactivity for {bold ${mountpoint.options.silenceTimeout / 1000} seconds}`); }); // Server connection timeout this.listen(mountpoint, 'inactivity', () => { console.log(chalk_1.default `/{red ${mountpoint.name}} - Closed due to no server connection for {bold ${mountpoint.options.connectionTimeout / 1000} seconds}`); }); }); } listen(emitter, event, listener) { emitter.on(event, listener); this.registeredListeners.push({ emitter: emitter, event: event, listener: listener }); } disable() { for (let listener of this.registeredListeners) { listener.emitter.off(listener.event, listener.listener); } } } exports.SimpleLogger = SimpleLogger;