Skip to content

Commit

Permalink
Fix event listener registration (bind this) and removal in web-hid-wr…
Browse files Browse the repository at this point in the history
…apper.ts
  • Loading branch information
loucadufault authored Jul 29, 2024
1 parent 838adff commit 0d44da7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/webhid/src/web-hid-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ export class WebHIDDevice extends EventEmitter implements CoreHIDDevice {

public async close(): Promise<void> {
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)
}
}

0 comments on commit 0d44da7

Please sign in to comment.