mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-08-16 15:44:49 +00:00
fix: clean up on unmount
This commit is contained in:
parent
76acf1a0f2
commit
61ffe117b4
2 changed files with 13 additions and 7 deletions
|
|
@ -106,6 +106,7 @@ const App = () => {
|
|||
return () => {
|
||||
services.chromecast.stop();
|
||||
services.chromecast.off('stateChanged', onChromecastStateChange);
|
||||
services.discord.destroy();
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ type DiscordStatusData = {
|
|||
class Discord {
|
||||
private events: EventEmitter;
|
||||
private shell: any;
|
||||
private onDiscordStatus: ((data: DiscordStatusData) => void) | null = null;
|
||||
|
||||
constructor() {
|
||||
this.events = new EventEmitter();
|
||||
|
|
@ -19,18 +20,22 @@ class Discord {
|
|||
this.shell = shellService;
|
||||
|
||||
if (this.shell) {
|
||||
this.shell.on('stateChanged', () => {
|
||||
this.onDiscordStatus = (data: DiscordStatusData) => {
|
||||
this.events.emit('availabilityChanged', this.available);
|
||||
});
|
||||
}
|
||||
|
||||
if (this.shell) {
|
||||
this.shell.on('discord-status', (data: DiscordStatusData) => {
|
||||
this.events.emit('statusChanged', data.connected);
|
||||
});
|
||||
};
|
||||
this.shell.on('discord-status', this.onDiscordStatus);
|
||||
}
|
||||
}
|
||||
|
||||
destroy(): void {
|
||||
if (this.shell && this.onDiscordStatus) {
|
||||
this.shell.off('discord-status', this.onDiscordStatus);
|
||||
this.onDiscordStatus = null;
|
||||
}
|
||||
this.shell = null;
|
||||
}
|
||||
|
||||
connect(): void {
|
||||
if (this.shell && this.shell.active) {
|
||||
this.shell.send('discord-connect', {});
|
||||
|
|
|
|||
Loading…
Reference in a new issue