Index: lams_tool_chat/web/includes/javascript/learning.js =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/web/includes/javascript/learning.js,v diff -u -r1.15.2.2 -r1.15.2.3 --- lams_tool_chat/web/includes/javascript/learning.js 7 Nov 2016 13:21:04 -0000 1.15.2.2 +++ lams_tool_chat/web/includes/javascript/learning.js 5 Dec 2016 06:35:19 -0000 1.15.2.3 @@ -15,15 +15,31 @@ }); }); - - // for chat users to be indetified by different colours +// for chat users to be indetified by different colours var PALETTE = ["#008CD2", "#DF7C08", "#83B532", "#E0BE40", "#AE8124", "#5F0704", "#004272", "#CD322B", "#254806"], // only Monitor can send a personal message 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.onmessage = function(e){ + + //if messageDiv has been already initialized in $(document).ready(..) simply invoke onmessageHandler, otherwise run it with a timeout + if (typeof messageDiv == 'undefined') { + setTimeout(function() { + onmessageHandler(e); + }, 500); + } else { + onmessageHandler(e); + } + +} + +chatToolWebsocket.onerror = function(e){ + alert("Error estabilishing connection to server: " + e.data); +} + +function onmessageHandler(e) { // create JSON object var input = JSON.parse(e.data); // clear old messages @@ -65,10 +81,6 @@ }); } -chatToolWebsocket.onerror = function(e){ - alert("Error estabilishing connection to server: " + e.data); -} - function userSelected(userDiv) { var userDivContent = userDiv.html(); // is Monitor clicked the already selectedd user, desect him and make message go to everyone