From 612b59c43cb0886688de7e9b9b8ca69499981a88 Mon Sep 17 00:00:00 2001 From: Alex Robsahm Date: Thu, 12 Jan 2017 14:37:56 +0100 Subject: [PATCH] Replaced config with getConfig --- index.js | 18 ++++++++++++------ package.json | 1 + 2 files changed, 13 insertions(+), 6 deletions(-) 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" } }