From 0d44da7e3ea2e409320dc3c75ccddced929c1b4b Mon Sep 17 00:00:00 2001 From: loucadufault <40028187+loucadufault@users.noreply.github.com> Date: Mon, 29 Jul 2024 10:41:48 -0400 Subject: [PATCH] Fix event listener registration (bind this) and removal in web-hid-wrapper.ts --- packages/webhid/src/web-hid-wrapper.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/webhid/src/web-hid-wrapper.ts b/packages/webhid/src/web-hid-wrapper.ts index 806ef67..567c23e 100644 --- a/packages/webhid/src/web-hid-wrapper.ts +++ b/packages/webhid/src/web-hid-wrapper.ts @@ -36,13 +36,14 @@ export class WebHIDDevice extends EventEmitter implements CoreHIDDevice { public async close(): Promise { await this.device.close() - this.device.removeEventListener('inputreport', this._handleInputreport.bind(this)) + this.device.removeEventListener('inputreport', this._handleInputreport) + this.device.removeEventListener('error', this._handleError) } - private _handleInputreport(event: HIDInputReportEvent) { + private _handleInputreport = (event: HIDInputReportEvent) => { const buf = WebBuffer.from(event.data.buffer) this.emit('data', buf) } - private _handleError(error: any) { + private _handleError = (error: any) => { this.emit('error', error) } }