Skip to content

Commit

Permalink
Ping server to keep connection alive
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Robsahm committed Dec 21, 2016
1 parent 6e5ee7a commit b1196eb
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const requestConfig = (webSocket, environment) => {
};

const initializeConfigUpdate = (conf) => {
let ping;
let retryNumOfTimes = 0;

const connect = (resolve, reject) => {
Expand All @@ -16,6 +17,7 @@ const initializeConfigUpdate = (conf) => {
webSocket.on("open", () => {
retryNumOfTimes = 0;
requestConfig(webSocket, conf.environment);
ping = setInterval(ws.ping(), 15000);
});

webSocket.on("message", (message) => {
Expand All @@ -33,6 +35,7 @@ const initializeConfigUpdate = (conf) => {
});

webSocket.on("close", () => {
clearInterval(ping);
setTimeout(connect, Math.ceil(Math.pow(Math.E, retryNumOfTimes)) * 100, resolve, reject);
retryNumOfTimes += 1;
});
Expand Down

0 comments on commit b1196eb

Please sign in to comment.