From 9648d30aa25cda674aaa860074bab766b5631205 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Fri, 6 May 2022 00:28:13 +0200 Subject: [PATCH] If videoData is destroyed, remove its eventBus from pageInfo's downstream buses --- src/ext/lib/EventBus.ts | 15 +++++++++++++++ src/ext/lib/video-data/VideoData.ts | 1 + 2 files changed, 16 insertions(+) diff --git a/src/ext/lib/EventBus.ts b/src/ext/lib/EventBus.ts index 4c2da13..5b049f7 100644 --- a/src/ext/lib/EventBus.ts +++ b/src/ext/lib/EventBus.ts @@ -16,6 +16,14 @@ export default class EventBus { this.upstreamBus.addDownstreamBus(this, true); } } + + unsetUpstreamBus(stopRecursing: boolean = false) { + if (!stopRecursing) { + this.upstreamBus.removeDownstreamBus(this, false); + } + this.upstreamBus = undefined; + } + addDownstreamBus(eventBus: EventBus, stopRecursing: boolean = false) { if (!this.downstreamBuses.includes(eventBus)) { this.downstreamBuses.push(eventBus); @@ -26,6 +34,13 @@ export default class EventBus { } } + removeDownstreamBus(eventBus: EventBus, stopRecursing: boolean = false) { + this.downstreamBuses = this.downstreamBuses.filter(x => x !== eventBus); + if (!stopRecursing) { + eventBus.unsetUpstreamBus(true); + } + } + subscribe(commandString: string, command: EventBusCommand) { if (!this.commands[commandString]) { this.commands[commandString] = [command]; diff --git a/src/ext/lib/video-data/VideoData.ts b/src/ext/lib/video-data/VideoData.ts index c99f11a..b060a14 100644 --- a/src/ext/lib/video-data/VideoData.ts +++ b/src/ext/lib/video-data/VideoData.ts @@ -332,6 +332,7 @@ class VideoData { this.disable(); this.destroyed = true; + this.eventBus?.unsetUpstreamBus(); try { this.arDetector.halt(); this.arDetector.destroy();