Skip to content

Commit

Permalink
LDEV-4332: Send websocket ping after 3 minutes of idleness so the con…
Browse files Browse the repository at this point in the history
…nection does not get cut because of idle timeout.
  • Loading branch information
MarcinCieslak committed May 24, 2017
1 parent a2ea0c0 commit 7cb18d1
Show file tree
Hide file tree
Showing 40 changed files with 1,225 additions and 357 deletions.
33 changes: 28 additions & 5 deletions lams_admin/web/WEB-INF/tags/Page.tag
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,30 @@
// it gets initialised along with progress bar
commandWebsocket = null,
commandWebsocketPingTimeout = null,
commandWebsocketPingFunc = null,
bars = {
'learnerMainBar' : {
'containerId' : 'progressBarDiv'
}
};
commandWebsocketPingFunc = function(skipPing){
if (commandWebsocket.readyState == commandWebsocket.CLOSING
|| commandWebsocket.readyState == commandWebsocket.CLOSED){
initCommandWebsocket();
return;
}
// check and ping every 3 minutes
commandWebsocketPingTimeout = setTimeout(commandWebsocketPingFunc, 3*60*1000);
// initial set up does not send ping
if (!skipPing) {
commandWebsocket.send("ping");
}
};
function restartLesson(){
if (confirm(restartLessonConfirmation)) {
window.location.href = LEARNING_URL + 'learner.do?method=restartLesson&lessonID=' + lessonId;
Expand Down Expand Up @@ -149,16 +166,18 @@
function initCommandWebsocket(){
// it is not an obvious place to init the websocket, but we need lesson ID
commandWebsocket = new WebSocket(LEARNING_URL.replace('http', 'ws') + 'commandWebsocket?lessonID=' + lessonId);
commandWebsocket = new WebSocket(LEARNING_URL.replace('http', 'ws')
+ 'commandWebsocket?lessonID=' + lessonId);
// set up timer for the first time
commandWebsocketPingFunc(true);
commandWebsocket.onclose = function(e){
if (e.code === 1006) {
// maybe iPad went into sleep mode?
// we need this websocket working, so init it again
initCommandWebsocket();
}
};
// when the server pushes new commands
commandWebsocket.onmessage = function(e){
// read JSON object
Expand All @@ -169,6 +188,10 @@
if (command.redirectURL) {
window.location.href = command.redirectURL;
}
// reset ping timer
clearTimeout(commandWebsocketPingTimeout);
commandWebsocketPingFunc(true);
};
}
Expand Down
32 changes: 28 additions & 4 deletions lams_central/web/WEB-INF/tags/Page.tag
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,30 @@
// it gets initialised along with progress bar
commandWebsocket = null,
commandWebsocketPingTimeout = null,
commandWebsocketPingFunc = null,
bars = {
'learnerMainBar' : {
'containerId' : 'progressBarDiv'
}
};
commandWebsocketPingFunc = function(skipPing){
if (commandWebsocket.readyState == commandWebsocket.CLOSING
|| commandWebsocket.readyState == commandWebsocket.CLOSED){
initCommandWebsocket();
return;
}
// check and ping every 3 minutes
commandWebsocketPingTimeout = setTimeout(commandWebsocketPingFunc, 3*60*1000);
// initial set up does not send ping
if (!skipPing) {
commandWebsocket.send("ping");
}
};
function restartLesson(){
if (confirm(restartLessonConfirmation)) {
window.location.href = LEARNING_URL + 'learner.do?method=restartLesson&lessonID=' + lessonId;
Expand Down Expand Up @@ -149,8 +166,11 @@
function initCommandWebsocket(){
// it is not an obvious place to init the websocket, but we need lesson ID
commandWebsocket = new WebSocket(LEARNING_URL.replace('http', 'ws') + 'commandWebsocket?lessonID=' + lessonId);
commandWebsocket = new WebSocket(LEARNING_URL.replace('http', 'ws')
+ 'commandWebsocket?lessonID=' + lessonId);
// set up timer for the first time
commandWebsocketPingFunc(true);
commandWebsocket.onclose = function(e){
if (e.code === 1006) {
// maybe iPad went into sleep mode?
Expand All @@ -168,6 +188,10 @@
if (command.redirectURL) {
window.location.href = command.redirectURL;
}
// reset ping timer
clearTimeout(commandWebsocketPingTimeout);
commandWebsocketPingFunc(true);
};
}
Expand Down
78 changes: 51 additions & 27 deletions lams_gradebook/web/WEB-INF/tags/Page.tag
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,30 @@
// it gets initialised along with progress bar
commandWebsocket = null,
commandWebsocketPingTimeout = null,
commandWebsocketPingFunc = null,
bars = {
'learnerMainBar' : {
'containerId' : 'progressBarDiv'
}
};
commandWebsocketPingFunc = function(skipPing){
if (commandWebsocket.readyState == commandWebsocket.CLOSING
|| commandWebsocket.readyState == commandWebsocket.CLOSED){
initCommandWebsocket();
return;
}
// check and ping every 3 minutes
commandWebsocketPingTimeout = setTimeout(commandWebsocketPingFunc, 3*60*1000);
// initial set up does not send ping
if (!skipPing) {
commandWebsocket.send("ping");
}
};
function restartLesson(){
if (confirm(restartLessonConfirmation)) {
window.location.href = LEARNING_URL + 'learner.do?method=restartLesson&lessonID=' + lessonId;
Expand Down Expand Up @@ -146,6 +163,37 @@
}
$('#sidebar').show();
}
function initCommandWebsocket(){
// it is not an obvious place to init the websocket, but we need lesson ID
commandWebsocket = new WebSocket(LEARNING_URL.replace('http', 'ws')
+ 'commandWebsocket?lessonID=' + lessonId);
// set up timer for the first time
commandWebsocketPingFunc(true);
commandWebsocket.onclose = function(e){
if (e.code === 1006) {
// maybe iPad went into sleep mode?
// we need this websocket working, so init it again
initCommandWebsocket();
}
};
// when the server pushes new commands
commandWebsocket.onmessage = function(e){
// read JSON object
var command = JSON.parse(e.data);
if (command.message) {
alert(command.message);
}
if (command.redirectURL) {
window.location.href = command.redirectURL;
}
// reset ping timer
clearTimeout(commandWebsocketPingTimeout);
commandWebsocketPingFunc(true);
};
}
$(document).ready(function() {
var showControlBar = 1; // 0/1/2 none/full/keep space
Expand Down Expand Up @@ -203,27 +251,7 @@
});
}
// it is not an obvious place to init the websocket, but we need lesson ID
commandWebsocket = new WebSocket(LEARNING_URL.replace('http', 'ws') + 'commandWebsocket?lessonID=' + lessonId);
commandWebsocket.onclose = function(e){
if (e.code === 1006) {
// maybe iPad went into sleep mode?
// we need this websocket working, so init it again
initCommandWebsocket();
}
};
// when the server pushes new commands
commandWebsocket.onmessage = function(e){
// read JSON object
var command = JSON.parse(e.data);
if (command.message) {
alert(command.message);
}
if (command.redirectURL) {
window.location.href = command.redirectURL;
}
};
initCommandWebsocket();
}
});
}
Expand Down Expand Up @@ -347,7 +375,3 @@
</div>
</c:otherwise>
</c:choose>




79 changes: 51 additions & 28 deletions lams_learning/web/WEB-INF/tags/Page.tag
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,30 @@
// it gets initialised along with progress bar
commandWebsocket = null,
commandWebsocketPingTimeout = null,
commandWebsocketPingFunc = null,
bars = {
'learnerMainBar' : {
'containerId' : 'progressBarDiv'
}
};
commandWebsocketPingFunc = function(skipPing){
if (commandWebsocket.readyState == commandWebsocket.CLOSING
|| commandWebsocket.readyState == commandWebsocket.CLOSED){
initCommandWebsocket();
return;
}
// check and ping every 3 minutes
commandWebsocketPingTimeout = setTimeout(commandWebsocketPingFunc, 3*60*1000);
// initial set up does not send ping
if (!skipPing) {
commandWebsocket.send("ping");
}
};
function restartLesson(){
if (confirm(restartLessonConfirmation)) {
window.location.href = LEARNING_URL + 'learner.do?method=restartLesson&lessonID=' + lessonId;
Expand Down Expand Up @@ -146,6 +163,37 @@
}
$('#sidebar').show();
}
function initCommandWebsocket(){
// it is not an obvious place to init the websocket, but we need lesson ID
commandWebsocket = new WebSocket(LEARNING_URL.replace('http', 'ws')
+ 'commandWebsocket?lessonID=' + lessonId);
// set up timer for the first time
commandWebsocketPingFunc(true);
commandWebsocket.onclose = function(e){
if (e.code === 1006) {
// maybe iPad went into sleep mode?
// we need this websocket working, so init it again
initCommandWebsocket();
}
};
// when the server pushes new commands
commandWebsocket.onmessage = function(e){
// read JSON object
var command = JSON.parse(e.data);
if (command.message) {
alert(command.message);
}
if (command.redirectURL) {
window.location.href = command.redirectURL;
}
// reset ping timer
clearTimeout(commandWebsocketPingTimeout);
commandWebsocketPingFunc(true);
};
}
$(document).ready(function() {
var showControlBar = 1; // 0/1/2 none/full/keep space
Expand Down Expand Up @@ -203,28 +251,7 @@
});
}
// it is not an obvious place to init the websocket, but we need lesson ID
commandWebsocket = new WebSocket(LEARNING_URL.replace('http', 'ws') + 'commandWebsocket?lessonID=' + lessonId);
commandWebsocket.onclose = function(e){
if (e.code === 1006) {
// maybe iPad went into sleep mode?
// we need this websocket working, so init it again
initCommandWebsocket();
}
};
// when the server pushes new commands
commandWebsocket.onmessage = function(e){
// read JSON object
var command = JSON.parse(e.data);
if (command.message) {
alert(command.message);
}
if (command.redirectURL) {
window.location.href = command.redirectURL;
}
};
initCommandWebsocket();
}
});
}
Expand Down Expand Up @@ -348,7 +375,3 @@
</div>
</c:otherwise>
</c:choose>




Loading

0 comments on commit 7cb18d1

Please sign in to comment.