Index: lams_tool_leader/web/pages/learning/leaderselection.jsp =================================================================== diff -u -r7d739cafc6626a1145073e5b85f5ed42d0f72dd0 -r7cb18d1521c69062337439737a624a60a27013d4 --- lams_tool_leader/web/pages/learning/leaderselection.jsp (.../leaderselection.jsp) (revision 7d739cafc6626a1145073e5b85f5ed42d0f72dd0) +++ lams_tool_leader/web/pages/learning/leaderselection.jsp (.../leaderselection.jsp) (revision 7cb18d1521c69062337439737a624a60a27013d4) @@ -28,16 +28,37 @@ //init the connection with server using server URL but with different protocol var leaderWebsocket = new WebSocket(''.replace('http', 'ws') - + 'learningWebsocket?toolSessionID=' + ${toolSessionID}); + + 'learningWebsocket?toolSessionID=' + ${toolSessionID}), + leaderWebsocketPingTimeout = null, + leaderWebsocketPingFunc = null; + + leaderWebsocketPingFunc = function(skipPing){ + if (leaderWebsocket.readyState == leaderWebsocket.CLOSING + || leaderWebsocket.readyState == leaderWebsocket.CLOSED){ + location.reload(); + } + + // check and ping every 3 minutes + leaderWebsocketPingTimeout = setTimeout(leaderWebsocketPingFunc, 3*60*1000); + // initial set up does not send ping + if (!skipPing) { + leaderWebsocket.send("ping"); + } + }; + // set up timer for the first time + leaderWebsocketPingFunc(true); leaderWebsocket.onclose = function(e){ + // react only on abnormal close if (e.code === 1006) { location.reload(); } }; // run when the leader has just been selected leaderWebsocket.onmessage = function(e) { + // no need to reset ping timer as the only possible message is page refresh + // create JSON object var input = JSON.parse(e.data);