From 76cd8292c5b80749ece1ab6558f3ed410a618f0d Mon Sep 17 00:00:00 2001 From: Jakob Stendahl Date: Sun, 10 Oct 2021 23:27:32 +0200 Subject: :hammer: Update some of the builtin scripts --- app.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'app.js') diff --git a/app.js b/app.js index 715108b..044f68a 100644 --- a/app.js +++ b/app.js @@ -78,16 +78,24 @@ function getNetworkAddress() { } return results[Object.keys(results)[0]][0] } +let http = require("http"); function tryBroadcastSelf() { if (neoModules.userData.config.DiscoveryServer.broadcastSelf) { + let address = neoModules.userData.config.DiscoveryServer.address; + let port = 443; + if (address.includes(":")) { + address = address.split(":"); + port = parseInt(address[1]); + address = address[0]; + } const data = JSON.stringify({ address: `https://${getNetworkAddress()}:${neoModules.userData.config.HTTP.port}`, name: neoModules.userData.config.instanceName, widgetaddr: "/#/widget" }) const options = { - hostname: `${neoModules.userData.config.DiscoveryServer.address}`, - port: 443, + hostname: address, + port: port, path: "/HEY", method: "POST", headers: { @@ -95,12 +103,11 @@ function tryBroadcastSelf() { "Content-length": data.length } }; - let req = https.request(options, res => { + let req = http.request(options, res => { if (res.statusCode != 200) { res.on("data", (d) => logger.warning(d.toString())); } else { - res.on("data", (d) => logger.info(d.toString())); - logger.info("Broadcasted self") + // res.on("data", (d) => logger.info(d.toString())); } }); req.on("error", (error) => logger.warning(error.toString())) @@ -108,7 +115,7 @@ function tryBroadcastSelf() { req.end(); } } -// setInterval(tryBroadcastSelf, 30000); -// tryBroadcastSelf(); +setInterval(tryBroadcastSelf, 30000); +tryBroadcastSelf(); // setInterval(() => { logger.notice("I feel FANTASTIC, an I'm still alive. Uptime: " + process.uptime()); }, 600000); -- cgit v1.2.3