Skip to content

Commit

Permalink
create a ws keep alive dummy message
Browse files Browse the repository at this point in the history
  • Loading branch information
dshuffma-ibm committed May 15, 2018
1 parent 140d626 commit 971dba8
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions public/js/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var pendingTxDrawing = [];
// =================================================================================
function connect_to_server() {
var connected = false;
var ws_keep_alive = null;
connect();

function connect() {
Expand All @@ -36,9 +37,16 @@ function connect_to_server() {
console.log(wsTxt + ' CONNECTED');
addshow_notification(build_notification(false, 'Connected to Marbles application'), false);
connected = true;

clearInterval(ws_keep_alive);
ws_keep_alive = setInterval(function () {
ws.send(JSON.stringify({ type: 'ping' }));
console.log(wsTxt + ' ping sent'); // send a keep alive faster than 2 minutes
}, 90 * 1000);
}

function onClose(evt) {
clearInterval(ws_keep_alive);
setTimeout(() => {
console.log(wsTxt + ' DISCONNECTED', evt);
connected = false;
Expand Down

0 comments on commit 971dba8

Please sign in to comment.