Skip to content

Commit

Permalink
LDEV-4332: Refresh page when a tool websocket gets closed. Re-init Co…
Browse files Browse the repository at this point in the history
…mmand websocket when it gets closed. Rename websockets in JS code to ensure name uniqueness within the page.
  • Loading branch information
MarcinCieslak committed May 4, 2017
1 parent 187836d commit 0ec58b4
Show file tree
Hide file tree
Showing 37 changed files with 676 additions and 469 deletions.
40 changes: 23 additions & 17 deletions lams_admin/web/WEB-INF/tags/Page.tag
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,28 @@
}
$('#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);
commandWebsocket.onclose = function(){
// 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;
}
};
}
$(document).ready(function() {
var showControlBar = 1; // 0/1/2 none/full/keep space
Expand Down Expand Up @@ -203,19 +225,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);
// 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 @@ -339,7 +349,3 @@
</div>
</c:otherwise>
</c:choose>




40 changes: 23 additions & 17 deletions lams_central/web/WEB-INF/tags/Page.tag
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,28 @@
}
$('#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);
commandWebsocket.onclose = function(){
// 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;
}
};
}
$(document).ready(function() {
var showControlBar = 1; // 0/1/2 none/full/keep space
Expand Down Expand Up @@ -203,19 +225,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);
// 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 @@ -339,7 +349,3 @@
</div>
</c:otherwise>
</c:choose>




6 changes: 6 additions & 0 deletions lams_gradebook/web/WEB-INF/tags/Page.tag
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@
// 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(){
// maybe iPad went into sleep mode?
// we need this websocket working, so reload
location.reload();
};
// when the server pushes new commands
commandWebsocket.onmessage = function(e){
// read JSON object
Expand Down
6 changes: 6 additions & 0 deletions lams_learning/web/WEB-INF/tags/Page.tag
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@
// 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(){
// maybe iPad went into sleep mode?
// we need this websocket working, so reload
location.reload();
};
// when the server pushes new commands
commandWebsocket.onmessage = function(e){
// read JSON object
Expand Down
1 change: 1 addition & 0 deletions lams_monitoring/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
<attribute name="javadoc_location" value="http://commons.apache.org/proper/commons-lang/javadocs/api-2.6/"/>
</attributes>
</classpathentry>
<classpathentry combineaccessrules="false" kind="src" path="/lams_gradebook"/>
<classpathentry kind="output" path="bin"/>
</classpath>
6 changes: 6 additions & 0 deletions lams_monitoring/web/WEB-INF/tags/Page.tag
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@
// 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(){
// maybe iPad went into sleep mode?
// we need this websocket working, so reload
location.reload();
};
// when the server pushes new commands
commandWebsocket.onmessage = function(e){
// read JSON object
Expand Down
40 changes: 23 additions & 17 deletions lams_tool_assessment/web/WEB-INF/tags/Page.tag
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,28 @@
}
$('#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);
commandWebsocket.onclose = function(){
// 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;
}
};
}
$(document).ready(function() {
var showControlBar = 1; // 0/1/2 none/full/keep space
Expand Down Expand Up @@ -203,19 +225,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);
// 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 @@ -339,7 +349,3 @@
</div>
</c:otherwise>
</c:choose>




40 changes: 23 additions & 17 deletions lams_tool_bbb/web/WEB-INF/tags/Page.tag
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,28 @@
}
$('#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);
commandWebsocket.onclose = function(){
// 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;
}
};
}
$(document).ready(function() {
var showControlBar = 1; // 0/1/2 none/full/keep space
Expand Down Expand Up @@ -203,19 +225,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);
// 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 @@ -339,7 +349,3 @@
</div>
</c:otherwise>
</c:choose>




6 changes: 6 additions & 0 deletions lams_tool_chat/web/WEB-INF/tags/Page.tag
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@
// 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(){
// maybe iPad went into sleep mode?
// we need this websocket working, so reload
location.reload();
};
// when the server pushes new commands
commandWebsocket.onmessage = function(e){
// read JSON object
Expand Down
5 changes: 4 additions & 1 deletion lams_tool_chat/web/includes/javascript/learning.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ $(document).ready(function() {
var selectedUser = null,
// init the connection with server using server URL but with different protocol
chatToolWebsocket = new WebSocket(APP_URL.replace('http', 'ws') + 'learningWebsocket?toolSessionID=' + TOOL_SESSION_ID);

chatToolWebsocket.onclose = function(){
location.reload();
};

chatToolWebsocket.onmessage = function(e){

// create JSON object
var input = JSON.parse(e.data);
// clear old messages
Expand Down
6 changes: 6 additions & 0 deletions lams_tool_daco/web/WEB-INF/tags/Page.tag
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@
// 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(){
// maybe iPad went into sleep mode?
// we need this websocket working, so reload
location.reload();
};
// when the server pushes new commands
commandWebsocket.onmessage = function(e){
// read JSON object
Expand Down
40 changes: 23 additions & 17 deletions lams_tool_forum/web/WEB-INF/tags/Page.tag
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,28 @@
}
$('#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);
commandWebsocket.onclose = function(){
// 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;
}
};
}
$(document).ready(function() {
var showControlBar = 1; // 0/1/2 none/full/keep space
Expand Down Expand Up @@ -203,19 +225,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);
// 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 @@ -339,7 +349,3 @@
</div>
</c:otherwise>
</c:choose>




Loading

0 comments on commit 0ec58b4

Please sign in to comment.