From ba8d04aeb2813979d64efff1dbb6905f3e86c14f Mon Sep 17 00:00:00 2001 From: "Jonathan Leibiusky @xetorthio" Date: Wed, 1 Nov 2017 14:56:22 -0300 Subject: [PATCH] Make sure instance exists before trying to do anything --- www/assets/app.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/www/assets/app.js b/www/assets/app.js index 523e983..4db6347 100644 --- a/www/assets/app.js +++ b/www/assets/app.js @@ -240,7 +240,9 @@ socket.on('instance terminal status', function(name, status) { var instance = $scope.idx[name]; - instance.status = status; + if (instance) { + instance.status = status; + } }); socket.on('session ready', function(ready) { @@ -253,6 +255,9 @@ socket.on('instance terminal out', function(name, data) { var instance = $scope.idx[name]; + if (!instance) { + return; + } if (!instance) { // instance is new and was created from another client, we should add it @@ -303,12 +308,18 @@ }); socket.on('instance stats', function(stats) { + if (! $scope.idx[stats.instance]) { + return + } $scope.idx[stats.instance].mem = stats.mem; $scope.idx[stats.instance].cpu = stats.cpu; $scope.$apply(); }); socket.on('instance docker swarm status', function(status) { + if (!$scope.idx[status.instance]) { + return + } if (status.is_manager) { $scope.idx[status.instance].isManager = true } else if (status.is_worker) { @@ -316,20 +327,23 @@ } else { $scope.idx[status.instance].isManager = null } - $scope.$apply(); + $scope.$apply(); }); socket.on('instance docker ports', function(status) { - if ($scope.idx[status.instance]) { - $scope.idx[status.instance].ports = status.ports; - $scope.$apply(); + if (!$scope.idx[status.instance]) { + return } + $scope.idx[status.instance].ports = status.ports; + $scope.$apply(); }); socket.on('instance docker swarm ports', function(status) { for(var i in status.instances) { var instance = status.instances[i]; - $scope.idxByHostname[instance].swarmPorts = status.ports; + if ($scope.idxByHostname[instance]) { + $scope.idxByHostname[instance].swarmPorts = status.ports; + } } $scope.$apply(); });