Update Streamer class

This commit is contained in:
Christer Warén 2021-09-11 23:19:49 +03:00
parent ffa9c8abb0
commit 7d479b4c5f

View File

@ -29,7 +29,7 @@ module.exports = class {
let streamers = this.map.keys(); let streamers = this.map.keys();
streamers.forEach(streamer => { streamers.forEach(streamer => {
if(client.stations.findIndex(station => station.name == streamer)) return; if(client.stations.findIndex(station => station.name == streamer)) return;
this.map.delete(streamer); this.stop(streamer);
}); });
} }
@ -56,6 +56,12 @@ module.exports = class {
return audioPlayer; return audioPlayer;
} }
stop(station){
let audioPlayer = this.map.get(station.name);
audioPlayer?.stop();
this.map.delete(station.name);
}
listen(station) { listen(station) {
let audioPlayer = this.map.get(station.name); let audioPlayer = this.map.get(station.name);
if(!audioPlayer){ if(!audioPlayer){
@ -68,9 +74,7 @@ module.exports = class {
if(!client.stations) return; if(!client.stations) return;
client.stations.forEach(station => { client.stations.forEach(station => {
let streamer = this.map.get(station.name); this.stop(station);
streamer?.stop();
this.map.delete(station.name);
}); });
} }
}; };