From bb09f51ad91cf4d396f1ea5ea9aa8514d62453c0 Mon Sep 17 00:00:00 2001 From: Stefano Brilli Date: Thu, 2 Apr 2020 16:39:12 +0200 Subject: [PATCH] Setup a new logger This could help me to debug a few issues reported by some users using a rh1 --- src/index.tsx | 2 +- src/services/netmd.ts | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 36e4294..87bd3ba 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -15,7 +15,7 @@ import App from './components/app'; import './index.css'; import { FFMpegAudioExportService } from './services/audio-export'; -serviceRegistry.netmdService = new NetMDUSBService(); +serviceRegistry.netmdService = new NetMDUSBService({ debug: true }); // serviceRegistry.netmdService = new NetMDMockService(); // Uncomment to work without a device attached serviceRegistry.audioExportService = new FFMpegAudioExportService(); diff --git a/src/services/netmd.ts b/src/services/netmd.ts index bd6f4e6..a113fe0 100644 --- a/src/services/netmd.ts +++ b/src/services/netmd.ts @@ -1,5 +1,6 @@ import { openNewDevice, NetMDInterface, Disc, listContent, openPairedDevice, Wireformat, MDTrack, download } from 'netmd-js'; import { makeGetAsyncPacketIteratorOnWorkerThread } from 'netmd-js/dist/web-encrypt-worker'; +import { Logger, ConsoleLogger, Level } from 'netmd-js/dist/logger'; const Worker = require('worker-loader!netmd-js/dist/web-encrypt-worker.js'); // eslint-disable-line import/no-webpack-loader-syntax @@ -29,9 +30,28 @@ export interface NetMDService { export class NetMDUSBService implements NetMDService { private netmdInterface?: NetMDInterface; + private logger?: Logger; + + constructor({ debug = false }: { debug: boolean }) { + if (debug) { + // Logging a few methods that have been causing issues with some units + const _fn = (...args: any) => { + if (args && args[0] && args[0].method) { + console.log(...args); + } + }; + this.logger = { + debug: _fn, + info: _fn, + warn: _fn, + error: _fn, + child: () => this.logger!, + }; + } + } async pair() { - let iface = await openNewDevice(navigator.usb); + let iface = await openNewDevice(navigator.usb, this.logger); if (iface === null) { return false; } @@ -40,7 +60,7 @@ export class NetMDUSBService implements NetMDService { } async connect() { - let iface = await openPairedDevice(navigator.usb); + let iface = await openPairedDevice(navigator.usb, this.logger); if (iface === null) { return false; }