If videoData is destroyed, remove its eventBus from pageInfo's downstream buses

This commit is contained in:
Tamius Han 2022-05-06 00:28:13 +02:00
parent 5a04c2eeee
commit 9648d30aa2
2 changed files with 16 additions and 0 deletions

View File

@ -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];

View File

@ -332,6 +332,7 @@ class VideoData {
this.disable();
this.destroyed = true;
this.eventBus?.unsetUpstreamBus();
try {
this.arDetector.halt();
this.arDetector.destroy();