Skip to content

Commit

Permalink
Replaced config with getConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Robsahm committed Jan 12, 2017
1 parent ca97bbf commit 612b59c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
18 changes: 12 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"author": "Alex Robsahm",
"license": "ISC",
"dependencies": {
"ramda": "^0.23.0",
"ws": "^1.1.1"
}
}

0 comments on commit 612b59c

Please sign in to comment.