From d10bccccc4adc89323675e707b7617bf0d4ce0b1 Mon Sep 17 00:00:00 2001 From: Fabian Bormann Date: Fri, 24 Mar 2023 15:54:46 +0100 Subject: [PATCH] fix: remove local storage from logger to allow meerkat to run in an environment without local storage --- logger.ts | 13 +++++-------- meerkat.ts | 7 +------ 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/logger.ts b/logger.ts index 3998b20..3af487d 100644 --- a/logger.ts +++ b/logger.ts @@ -3,6 +3,7 @@ import { LogLevel } from './types'; export default class Logger { logLevel: LogLevel = 'info'; private scope: string; + private enabled: boolean = true; constructor({ scope, @@ -19,20 +20,16 @@ export default class Logger { } if (typeof enabled === 'boolean') { - if (enabled) { - localStorage.setItem('Meerkat-Logging', 'true'); - } else { - localStorage.setItem('Meerkat-Logging', 'false'); - } + this.enabled = enabled; } } disable() { - localStorage.setItem('Meerkat-Logging', 'false'); + this.enabled = false; } enable() { - localStorage.setItem('Meerkat-Logging', 'true'); + this.enabled = true; } private formatMessage(logLevel: LogLevel, message: string): string { @@ -94,7 +91,7 @@ export default class Logger { font-weight: bold'; `; - if (localStorage.getItem('Meerkat-Logging') === 'true') { + if (this.enabled) { if (logLevel === 'debug' || logLevel === 'info') { console.log( this.formatMessage(logLevel, message), diff --git a/meerkat.ts b/meerkat.ts index 5eff331..4a048d0 100644 --- a/meerkat.ts +++ b/meerkat.ts @@ -413,12 +413,7 @@ export default class Meerkat extends EventEmitter { connections() { if (this.torrent.wires.length != this.lastwirecount) { this.lastwirecount = this.torrent.wires.length; - this.emit( - 'connections', - this.torrent.wires.map( - (wire: any) => wire.extendedHandshake?.identifier - ) - ); + this.emit('connections', this.torrent.wires.length); } return this.lastwirecount; }