diff --git a/index.js b/index.js index ab2835e..26e7bad 100644 --- a/index.js +++ b/index.js @@ -1,12 +1,9 @@ const ws = require("ws"); +const R = require("ramda"); const url = require("url"); let config = {}; -const requestConfig = (webSocket, environment) => { - webSocket.send(environment); -}; - const initializeConfigUpdate = (conf) => { let ping; let retryNumOfTimes = 0; @@ -16,7 +13,7 @@ const initializeConfigUpdate = (conf) => { webSocket.on("open", () => { retryNumOfTimes = 0; - requestConfig(webSocket, conf.environment); + webSocket.send(conf.environment); ping = setInterval(() => { webSocket.ping(); }, 15000); @@ -46,7 +43,16 @@ const initializeConfigUpdate = (conf) => { return new Promise(connect); }; +const getConfig = ([part, key], def) => { + const confValue = R.path(part + '.' + key, config) + if (confValue !== undefined) { + return confValue; + } + + return def; +}; + module.exports = { initializeConfigUpdate, - config, + getConfig }; diff --git a/package.json b/package.json index 0c7ea26..8089210 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "author": "Alex Robsahm", "license": "ISC", "dependencies": { + "ramda": "^0.23.0", "ws": "^1.1.1" } }