diff --git a/lib/airsonos.js b/lib/airsonos.js index 61ca1b3..3299fd3 100644 --- a/lib/airsonos.js +++ b/lib/airsonos.js @@ -50,7 +50,11 @@ class AirSonos { } stop() { - return Promise.all(this.tunnels.map(tunnel.stop)); + var promises = [] + for (let id in this.tunnels) { + promises.push(this.tunnels[id].stop()) + } + return Promise.all(promises); } } diff --git a/lib/tunnel.js b/lib/tunnel.js index a855eff..4bd1dbe 100644 --- a/lib/tunnel.js +++ b/lib/tunnel.js @@ -96,8 +96,8 @@ class DeviceTunnel extends events.EventEmitter { } stop() { - this.airplayServer.stop(); - this.icecastServer.stop(); + if (this.airplayServer) this.airplayServer.stop(); + if (this.icecastServer) this.icecastServer.stop(); } }