From 584d7374df5647a4fef47df6af91e4aaf71f00b9 Mon Sep 17 00:00:00 2001 From: Cryptkeeper Date: Sat, 6 Feb 2016 18:36:51 -0600 Subject: [PATCH] Fix missing servers when refreshing too early --- app.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index 0021a8b..9cb6228 100644 --- a/app.js +++ b/app.js @@ -170,8 +170,27 @@ function startServices() { networkHistoryKeys.sort(); // Send each individually, this should look cleaner than waiting for one big array to transfer. - for (var i = 0; i < networkHistoryKeys.length; i++) { - client.emit('add', [networkHistory[networkHistoryKeys[i]]]); + for (var i = 0; i < servers.length; i++) { + var server = servers[i]; + + if (!(server.name in networkHistory) || networkHistory[server.name].length < 1) { + // This server hasn't been ping'd yet. Send a hacky placeholder. + client.emit('add', [[{ + error: { + description: 'Waiting' + }, + result: null, + timestamp: util.getCurrentTimeMs(), + info: { + ip: server.ip, + port: server.port, + type: server.type, + name: server.name + } + }]]); + } else { + client.emit('add', [networkHistory[networkHistoryKeys[i]]]); + } } }); });