From ae8276e73e945fdc04589050d104c66990f713e8 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 28 Aug 2024 15:33:07 -0500 Subject: [PATCH 1/4] save messageCallback on this, and remove listener on it --- js/workflows/usb.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/js/workflows/usb.js b/js/workflows/usb.js index e150a76..d532b83 100644 --- a/js/workflows/usb.js +++ b/js/workflows/usb.js @@ -235,8 +235,10 @@ class USBWorkflow extends Workflow { // Workflow specific Functions async _switchToDevice(device) { - device.removeEventListener("message", this.onSerialReceive.bind(this)); - device.addEventListener("message", this.onSerialReceive.bind(this)); + + device.removeEventListener("message", this.messageCallback); + this.messageCallback = this.onSerialReceive.bind(this); + device.addEventListener("message", this.messageCallback); let onDisconnect = async (e) => { await this.onDisconnected(e, false); From 8b95e137c75dccd2a17f0c6193a431fb87499214 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 28 Aug 2024 16:33:47 -0500 Subject: [PATCH 2/4] make private field Co-authored-by: Melissa LeBlanc-Williams --- js/workflows/usb.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/workflows/usb.js b/js/workflows/usb.js index d532b83..5d7c113 100644 --- a/js/workflows/usb.js +++ b/js/workflows/usb.js @@ -237,8 +237,8 @@ class USBWorkflow extends Workflow { async _switchToDevice(device) { device.removeEventListener("message", this.messageCallback); - this.messageCallback = this.onSerialReceive.bind(this); - device.addEventListener("message", this.messageCallback); + this._messageCallback = this.onSerialReceive.bind(this); + device.addEventListener("message", this._messageCallback); let onDisconnect = async (e) => { await this.onDisconnected(e, false); From f83bb2a56cfb0d296ba90dafa36e2067196924fa Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 28 Aug 2024 16:34:52 -0500 Subject: [PATCH 3/4] add _messageCallback to constructor --- js/workflows/usb.js | 1 + 1 file changed, 1 insertion(+) diff --git a/js/workflows/usb.js b/js/workflows/usb.js index 5d7c113..8aac72f 100644 --- a/js/workflows/usb.js +++ b/js/workflows/usb.js @@ -21,6 +21,7 @@ class USBWorkflow extends Workflow { this._partialToken = null; this._uid = null; this._readLoopPromise = null; + this._messageCallback = null; } async init(params) { From dc21368c2ce3db2a6435084bdfa04fc8e72219c9 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 28 Aug 2024 16:38:11 -0500 Subject: [PATCH 4/4] private field for remove too --- js/workflows/usb.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/workflows/usb.js b/js/workflows/usb.js index 8aac72f..ff18846 100644 --- a/js/workflows/usb.js +++ b/js/workflows/usb.js @@ -237,7 +237,7 @@ class USBWorkflow extends Workflow { // Workflow specific Functions async _switchToDevice(device) { - device.removeEventListener("message", this.messageCallback); + device.removeEventListener("message", this._messageCallback); this._messageCallback = this.onSerialReceive.bind(this); device.addEventListener("message", this._messageCallback);