Index: lams_admin/web/WEB-INF/tags/Page.tag =================================================================== diff -u -r9496ff3ffe5e98272f7939a2cf4e8c6dbb2901f7 -r876e644c066e81c2721ffa085fd12f386e2f3bb6 --- lams_admin/web/WEB-INF/tags/Page.tag (.../Page.tag) (revision 9496ff3ffe5e98272f7939a2cf4e8c6dbb2901f7) +++ lams_admin/web/WEB-INF/tags/Page.tag (.../Page.tag) (revision 876e644c066e81c2721ffa085fd12f386e2f3bb6) @@ -231,51 +231,47 @@ }); } - let commandWebsocket = initWebsocket('commandWebsocket', LEARNING_URL.replace('http', 'ws') - + 'commandWebsocket?lessonID=' + lessonId); - - if (commandWebsocket) { - // when the server pushes new inputs - commandWebsocket.onmessage = function (e) { - // read JSON object - var command = JSON.parse(e.data); - if (command.message) { - // some tools implement autosave feature - // if it is such a tool, trigger it - if (command.message === 'autosave') { - // the name of this function is same in all tools - if (typeof learnerAutosave == 'function') { - learnerAutosave(true); + initWebsocket('commandWebsocket', LEARNING_URL.replace('http', 'ws') + + 'commandWebsocket?lessonID=' + lessonId, + function (e) { + // read JSON object + var command = JSON.parse(e.data); + if (command.message) { + // some tools implement autosave feature + // if it is such a tool, trigger it + if (command.message === 'autosave') { + // the name of this function is same in all tools + if (typeof learnerAutosave == 'function') { + learnerAutosave(true); + } + } else { + alert(command.message); } - } else { - alert(command.message); } - } - // if learner's currently displayed page has hookTrigger same as in the JSON - // then a function also defined on that page will run - if (command.hookTrigger && command.hookTrigger == commandWebsocketHookTrigger - && typeof commandWebsocketHook === 'function') { - commandWebsocketHook(command.hookParams); - } + // if learner's currently displayed page has hookTrigger same as in the JSON + // then a function also defined on that page will run + if (command.hookTrigger && command.hookTrigger == commandWebsocketHookTrigger + && typeof commandWebsocketHook === 'function') { + commandWebsocketHook(command.hookParams); + } - if (command.redirectURL) { - window.location.href = command.redirectURL; - } + if (command.redirectURL) { + window.location.href = command.redirectURL; + } - if (command.discussion) { - var discussionCommand = $('#discussion-sentiment-command'); - if (discussionCommand.length === 0) { - discussionCommand = $('
').attr('id', 'discussion-sentiment-command').appendTo('body'); + if (command.discussion) { + var discussionCommand = $('#discussion-sentiment-command'); + if (discussionCommand.length === 0) { + discussionCommand = $('
').attr('id', 'discussion-sentiment-command').appendTo('body'); + } + discussionCommand.load(LEARNING_URL + "discussionSentiment/" + command.discussion + ".do", { + lessonId : lessonId + }); } - discussionCommand.load(LEARNING_URL + "discussionSentiment/" + command.discussion + ".do", { - lessonId : lessonId - }); - } - // reset ping timer - websocketPing('commandWebsocket', true); - }; - } + // reset ping timer + websocketPing('commandWebsocket', true); + }); } }); } Index: lams_admin/web/WEB-INF/tags/Page5.tag =================================================================== diff -u -r9496ff3ffe5e98272f7939a2cf4e8c6dbb2901f7 -r876e644c066e81c2721ffa085fd12f386e2f3bb6 --- lams_admin/web/WEB-INF/tags/Page5.tag (.../Page5.tag) (revision 9496ff3ffe5e98272f7939a2cf4e8c6dbb2901f7) +++ lams_admin/web/WEB-INF/tags/Page5.tag (.../Page5.tag) (revision 876e644c066e81c2721ffa085fd12f386e2f3bb6) @@ -233,51 +233,47 @@ }); } - let commandWebsocket = initWebsocket('commandWebsocket', LEARNING_URL.replace('http', 'ws') - + 'commandWebsocket?lessonID=' + lessonId); - - if (commandWebsocket) { - // when the server pushes new inputs - commandWebsocket.onmessage = function (e) { - // read JSON object - var command = JSON.parse(e.data); - if (command.message) { - // some tools implement autosave feature - // if it is such a tool, trigger it - if (command.message === 'autosave') { - // the name of this function is same in all tools - if (typeof learnerAutosave == 'function') { - learnerAutosave(true); + initWebsocket('commandWebsocket', LEARNING_URL.replace('http', 'ws') + + 'commandWebsocket?lessonID=' + lessonId, + function (e) { + // read JSON object + var command = JSON.parse(e.data); + if (command.message) { + // some tools implement autosave feature + // if it is such a tool, trigger it + if (command.message === 'autosave') { + // the name of this function is same in all tools + if (typeof learnerAutosave == 'function') { + learnerAutosave(true); + } + } else { + alert(command.message); } - } else { - alert(command.message); } - } - // if learner's currently displayed page has hookTrigger same as in the JSON - // then a function also defined on that page will run - if (command.hookTrigger && command.hookTrigger == commandWebsocketHookTrigger - && typeof commandWebsocketHook === 'function') { - commandWebsocketHook(command.hookParams); - } + // if learner's currently displayed page has hookTrigger same as in the JSON + // then a function also defined on that page will run + if (command.hookTrigger && command.hookTrigger == commandWebsocketHookTrigger + && typeof commandWebsocketHook === 'function') { + commandWebsocketHook(command.hookParams); + } - if (command.redirectURL) { - window.location.href = command.redirectURL; - } + if (command.redirectURL) { + window.location.href = command.redirectURL; + } - if (command.discussion) { - var discussionCommand = $('#discussion-sentiment-command'); - if (discussionCommand.length === 0) { - discussionCommand = $('
').attr('id', 'discussion-sentiment-command').appendTo('body'); + if (command.discussion) { + var discussionCommand = $('#discussion-sentiment-command'); + if (discussionCommand.length === 0) { + discussionCommand = $('
').attr('id', 'discussion-sentiment-command').appendTo('body'); + } + discussionCommand.load(LEARNING_URL + "discussionSentiment/" + command.discussion + ".do", { + lessonId : lessonId + }); } - discussionCommand.load(LEARNING_URL + "discussionSentiment/" + command.discussion + ".do", { - lessonId : lessonId - }); - } - // reset ping timer - websocketPing('commandWebsocket', true); - }; - } + // reset ping timer + websocketPing('commandWebsocket', true); + }); } }); } Index: lams_central/web/WEB-INF/tags/Page.tag =================================================================== diff -u -r9496ff3ffe5e98272f7939a2cf4e8c6dbb2901f7 -r876e644c066e81c2721ffa085fd12f386e2f3bb6 --- lams_central/web/WEB-INF/tags/Page.tag (.../Page.tag) (revision 9496ff3ffe5e98272f7939a2cf4e8c6dbb2901f7) +++ lams_central/web/WEB-INF/tags/Page.tag (.../Page.tag) (revision 876e644c066e81c2721ffa085fd12f386e2f3bb6) @@ -231,51 +231,47 @@ }); } - let commandWebsocket = initWebsocket('commandWebsocket', LEARNING_URL.replace('http', 'ws') - + 'commandWebsocket?lessonID=' + lessonId); - - if (commandWebsocket) { - // when the server pushes new inputs - commandWebsocket.onmessage = function (e) { - // read JSON object - var command = JSON.parse(e.data); - if (command.message) { - // some tools implement autosave feature - // if it is such a tool, trigger it - if (command.message === 'autosave') { - // the name of this function is same in all tools - if (typeof learnerAutosave == 'function') { - learnerAutosave(true); + initWebsocket('commandWebsocket', LEARNING_URL.replace('http', 'ws') + + 'commandWebsocket?lessonID=' + lessonId, + function (e) { + // read JSON object + var command = JSON.parse(e.data); + if (command.message) { + // some tools implement autosave feature + // if it is such a tool, trigger it + if (command.message === 'autosave') { + // the name of this function is same in all tools + if (typeof learnerAutosave == 'function') { + learnerAutosave(true); + } + } else { + alert(command.message); } - } else { - alert(command.message); } - } - // if learner's currently displayed page has hookTrigger same as in the JSON - // then a function also defined on that page will run - if (command.hookTrigger && command.hookTrigger == commandWebsocketHookTrigger - && typeof commandWebsocketHook === 'function') { - commandWebsocketHook(command.hookParams); - } + // if learner's currently displayed page has hookTrigger same as in the JSON + // then a function also defined on that page will run + if (command.hookTrigger && command.hookTrigger == commandWebsocketHookTrigger + && typeof commandWebsocketHook === 'function') { + commandWebsocketHook(command.hookParams); + } - if (command.redirectURL) { - window.location.href = command.redirectURL; - } + if (command.redirectURL) { + window.location.href = command.redirectURL; + } - if (command.discussion) { - var discussionCommand = $('#discussion-sentiment-command'); - if (discussionCommand.length === 0) { - discussionCommand = $('
').attr('id', 'discussion-sentiment-command').appendTo('body'); + if (command.discussion) { + var discussionCommand = $('#discussion-sentiment-command'); + if (discussionCommand.length === 0) { + discussionCommand = $('
').attr('id', 'discussion-sentiment-command').appendTo('body'); + } + discussionCommand.load(LEARNING_URL + "discussionSentiment/" + command.discussion + ".do", { + lessonId : lessonId + }); } - discussionCommand.load(LEARNING_URL + "discussionSentiment/" + command.discussion + ".do", { - lessonId : lessonId - }); - } - // reset ping timer - websocketPing('commandWebsocket', true); - }; - } + // reset ping timer + websocketPing('commandWebsocket', true); + }); } }); } Index: lams_central/web/WEB-INF/tags/Page5.tag =================================================================== diff -u -r9496ff3ffe5e98272f7939a2cf4e8c6dbb2901f7 -r876e644c066e81c2721ffa085fd12f386e2f3bb6 --- lams_central/web/WEB-INF/tags/Page5.tag (.../Page5.tag) (revision 9496ff3ffe5e98272f7939a2cf4e8c6dbb2901f7) +++ lams_central/web/WEB-INF/tags/Page5.tag (.../Page5.tag) (revision 876e644c066e81c2721ffa085fd12f386e2f3bb6) @@ -233,51 +233,47 @@ }); } - let commandWebsocket = initWebsocket('commandWebsocket', LEARNING_URL.replace('http', 'ws') - + 'commandWebsocket?lessonID=' + lessonId); - - if (commandWebsocket) { - // when the server pushes new inputs - commandWebsocket.onmessage = function (e) { - // read JSON object - var command = JSON.parse(e.data); - if (command.message) { - // some tools implement autosave feature - // if it is such a tool, trigger it - if (command.message === 'autosave') { - // the name of this function is same in all tools - if (typeof learnerAutosave == 'function') { - learnerAutosave(true); + initWebsocket('commandWebsocket', LEARNING_URL.replace('http', 'ws') + + 'commandWebsocket?lessonID=' + lessonId, + function (e) { + // read JSON object + var command = JSON.parse(e.data); + if (command.message) { + // some tools implement autosave feature + // if it is such a tool, trigger it + if (command.message === 'autosave') { + // the name of this function is same in all tools + if (typeof learnerAutosave == 'function') { + learnerAutosave(true); + } + } else { + alert(command.message); } - } else { - alert(command.message); } - } - // if learner's currently displayed page has hookTrigger same as in the JSON - // then a function also defined on that page will run - if (command.hookTrigger && command.hookTrigger == commandWebsocketHookTrigger - && typeof commandWebsocketHook === 'function') { - commandWebsocketHook(command.hookParams); - } + // if learner's currently displayed page has hookTrigger same as in the JSON + // then a function also defined on that page will run + if (command.hookTrigger && command.hookTrigger == commandWebsocketHookTrigger + && typeof commandWebsocketHook === 'function') { + commandWebsocketHook(command.hookParams); + } - if (command.redirectURL) { - window.location.href = command.redirectURL; - } + if (command.redirectURL) { + window.location.href = command.redirectURL; + } - if (command.discussion) { - var discussionCommand = $('#discussion-sentiment-command'); - if (discussionCommand.length === 0) { - discussionCommand = $('
').attr('id', 'discussion-sentiment-command').appendTo('body'); + if (command.discussion) { + var discussionCommand = $('#discussion-sentiment-command'); + if (discussionCommand.length === 0) { + discussionCommand = $('
').attr('id', 'discussion-sentiment-command').appendTo('body'); + } + discussionCommand.load(LEARNING_URL + "discussionSentiment/" + command.discussion + ".do", { + lessonId : lessonId + }); } - discussionCommand.load(LEARNING_URL + "discussionSentiment/" + command.discussion + ".do", { - lessonId : lessonId - }); - } - // reset ping timer - websocketPing('commandWebsocket', true); - }; - } + // reset ping timer + websocketPing('commandWebsocket', true); + }); } }); } Index: lams_central/web/includes/javascript/websocket.js =================================================================== diff -u -r9496ff3ffe5e98272f7939a2cf4e8c6dbb2901f7 -r876e644c066e81c2721ffa085fd12f386e2f3bb6 --- lams_central/web/includes/javascript/websocket.js (.../websocket.js) (revision 9496ff3ffe5e98272f7939a2cf4e8c6dbb2901f7) +++ lams_central/web/includes/javascript/websocket.js (.../websocket.js) (revision 876e644c066e81c2721ffa085fd12f386e2f3bb6) @@ -60,7 +60,7 @@ } }; -function initWebsocket(instanceName, url){ +function initWebsocket(instanceName, url, onMessageFunction){ let websocket = lamsWebsockets[instanceName]; if (!websocket) { websocket = { @@ -72,6 +72,9 @@ }; lamsWebsockets[instanceName] = websocket; } else if (websocket.instance) { + if (!onMessageFunction) { + onMessageFunction = websocket.instance.onmessage; + } try { websocket.instance.close(1000); } catch (e) { @@ -99,9 +102,26 @@ websocketReconnect(instanceName); } }; + if (onMessageFunction) { + websocket.instance.onmessage = onMessageFunction; + } // set up timer for the first time websocketPing(instanceName, true); return websocket.instance; +} + +function sendToWebsocket(instanceName, message) { + let websocket = lamsWebsockets[instanceName]; + if (!websocket) { + console.error("Websocket not initialized: " + instanceName); + return; + } + if (websocket.instance.readyState == WebSocket.CLOSING + || websocket.instance.readyState == WebSocket.CLOSED){ + websocketReconnect(instanceName); + return; + } + websocket.instance.send(message); } \ No newline at end of file Index: lams_gradebook/web/WEB-INF/tags/Page.tag =================================================================== diff -u -r9496ff3ffe5e98272f7939a2cf4e8c6dbb2901f7 -r876e644c066e81c2721ffa085fd12f386e2f3bb6 --- lams_gradebook/web/WEB-INF/tags/Page.tag (.../Page.tag) (revision 9496ff3ffe5e98272f7939a2cf4e8c6dbb2901f7) +++ lams_gradebook/web/WEB-INF/tags/Page.tag (.../Page.tag) (revision 876e644c066e81c2721ffa085fd12f386e2f3bb6) @@ -231,51 +231,47 @@ }); } - let commandWebsocket = initWebsocket('commandWebsocket', LEARNING_URL.replace('http', 'ws') - + 'commandWebsocket?lessonID=' + lessonId); - - if (commandWebsocket) { - // when the server pushes new inputs - commandWebsocket.onmessage = function (e) { - // read JSON object - var command = JSON.parse(e.data); - if (command.message) { - // some tools implement autosave feature - // if it is such a tool, trigger it - if (command.message === 'autosave') { - // the name of this function is same in all tools - if (typeof learnerAutosave == 'function') { - learnerAutosave(true); + initWebsocket('commandWebsocket', LEARNING_URL.replace('http', 'ws') + + 'commandWebsocket?lessonID=' + lessonId, + function (e) { + // read JSON object + var command = JSON.parse(e.data); + if (command.message) { + // some tools implement autosave feature + // if it is such a tool, trigger it + if (command.message === 'autosave') { + // the name of this function is same in all tools + if (typeof learnerAutosave == 'function') { + learnerAutosave(true); + } + } else { + alert(command.message); } - } else { - alert(command.message); } - } - // if learner's currently displayed page has hookTrigger same as in the JSON - // then a function also defined on that page will run - if (command.hookTrigger && command.hookTrigger == commandWebsocketHookTrigger - && typeof commandWebsocketHook === 'function') { - commandWebsocketHook(command.hookParams); - } + // if learner's currently displayed page has hookTrigger same as in the JSON + // then a function also defined on that page will run + if (command.hookTrigger && command.hookTrigger == commandWebsocketHookTrigger + && typeof commandWebsocketHook === 'function') { + commandWebsocketHook(command.hookParams); + } - if (command.redirectURL) { - window.location.href = command.redirectURL; - } + if (command.redirectURL) { + window.location.href = command.redirectURL; + } - if (command.discussion) { - var discussionCommand = $('#discussion-sentiment-command'); - if (discussionCommand.length === 0) { - discussionCommand = $('
').attr('id', 'discussion-sentiment-command').appendTo('body'); + if (command.discussion) { + var discussionCommand = $('#discussion-sentiment-command'); + if (discussionCommand.length === 0) { + discussionCommand = $('
').attr('id', 'discussion-sentiment-command').appendTo('body'); + } + discussionCommand.load(LEARNING_URL + "discussionSentiment/" + command.discussion + ".do", { + lessonId : lessonId + }); } - discussionCommand.load(LEARNING_URL + "discussionSentiment/" + command.discussion + ".do", { - lessonId : lessonId - }); - } - // reset ping timer - websocketPing('commandWebsocket', true); - }; - } + // reset ping timer + websocketPing('commandWebsocket', true); + }); } }); } Index: lams_gradebook/web/WEB-INF/tags/Page5.tag =================================================================== diff -u -r9496ff3ffe5e98272f7939a2cf4e8c6dbb2901f7 -r876e644c066e81c2721ffa085fd12f386e2f3bb6 --- lams_gradebook/web/WEB-INF/tags/Page5.tag (.../Page5.tag) (revision 9496ff3ffe5e98272f7939a2cf4e8c6dbb2901f7) +++ lams_gradebook/web/WEB-INF/tags/Page5.tag (.../Page5.tag) (revision 876e644c066e81c2721ffa085fd12f386e2f3bb6) @@ -233,51 +233,47 @@ }); } - let commandWebsocket = initWebsocket('commandWebsocket', LEARNING_URL.replace('http', 'ws') - + 'commandWebsocket?lessonID=' + lessonId); - - if (commandWebsocket) { - // when the server pushes new inputs - commandWebsocket.onmessage = function (e) { - // read JSON object - var command = JSON.parse(e.data); - if (command.message) { - // some tools implement autosave feature - // if it is such a tool, trigger it - if (command.message === 'autosave') { - // the name of this function is same in all tools - if (typeof learnerAutosave == 'function') { - learnerAutosave(true); + initWebsocket('commandWebsocket', LEARNING_URL.replace('http', 'ws') + + 'commandWebsocket?lessonID=' + lessonId, + function (e) { + // read JSON object + var command = JSON.parse(e.data); + if (command.message) { + // some tools implement autosave feature + // if it is such a tool, trigger it + if (command.message === 'autosave') { + // the name of this function is same in all tools + if (typeof learnerAutosave == 'function') { + learnerAutosave(true); + } + } else { + alert(command.message); } - } else { - alert(command.message); } - } - // if learner's currently displayed page has hookTrigger same as in the JSON - // then a function also defined on that page will run - if (command.hookTrigger && command.hookTrigger == commandWebsocketHookTrigger - && typeof commandWebsocketHook === 'function') { - commandWebsocketHook(command.hookParams); - } + // if learner's currently displayed page has hookTrigger same as in the JSON + // then a function also defined on that page will run + if (command.hookTrigger && command.hookTrigger == commandWebsocketHookTrigger + && typeof commandWebsocketHook === 'function') { + commandWebsocketHook(command.hookParams); + } - if (command.redirectURL) { - window.location.href = command.redirectURL; - } + if (command.redirectURL) { + window.location.href = command.redirectURL; + } - if (command.discussion) { - var discussionCommand = $('#discussion-sentiment-command'); - if (discussionCommand.length === 0) { - discussionCommand = $('
').attr('id', 'discussion-sentiment-command').appendTo('body'); + if (command.discussion) { + var discussionCommand = $('#discussion-sentiment-command'); + if (discussionCommand.length === 0) { + discussionCommand = $('
').attr('id', 'discussion-sentiment-command').appendTo('body'); + } + discussionCommand.load(LEARNING_URL + "discussionSentiment/" + command.discussion + ".do", { + lessonId : lessonId + }); } - discussionCommand.load(LEARNING_URL + "discussionSentiment/" + command.discussion + ".do", { - lessonId : lessonId - }); - } - // reset ping timer - websocketPing('commandWebsocket', true); - }; - } + // reset ping timer + websocketPing('commandWebsocket', true); + }); } }); } Index: lams_learning/web/WEB-INF/tags/Page.tag =================================================================== diff -u -r9496ff3ffe5e98272f7939a2cf4e8c6dbb2901f7 -r876e644c066e81c2721ffa085fd12f386e2f3bb6 --- lams_learning/web/WEB-INF/tags/Page.tag (.../Page.tag) (revision 9496ff3ffe5e98272f7939a2cf4e8c6dbb2901f7) +++ lams_learning/web/WEB-INF/tags/Page.tag (.../Page.tag) (revision 876e644c066e81c2721ffa085fd12f386e2f3bb6) @@ -231,51 +231,47 @@ }); } - let commandWebsocket = initWebsocket('commandWebsocket', LEARNING_URL.replace('http', 'ws') - + 'commandWebsocket?lessonID=' + lessonId); - - if (commandWebsocket) { - // when the server pushes new inputs - commandWebsocket.onmessage = function (e) { - // read JSON object - var command = JSON.parse(e.data); - if (command.message) { - // some tools implement autosave feature - // if it is such a tool, trigger it - if (command.message === 'autosave') { - // the name of this function is same in all tools - if (typeof learnerAutosave == 'function') { - learnerAutosave(true); + initWebsocket('commandWebsocket', LEARNING_URL.replace('http', 'ws') + + 'commandWebsocket?lessonID=' + lessonId, + function (e) { + // read JSON object + var command = JSON.parse(e.data); + if (command.message) { + // some tools implement autosave feature + // if it is such a tool, trigger it + if (command.message === 'autosave') { + // the name of this function is same in all tools + if (typeof learnerAutosave == 'function') { + learnerAutosave(true); + } + } else { + alert(command.message); } - } else { - alert(command.message); } - } - // if learner's currently displayed page has hookTrigger same as in the JSON - // then a function also defined on that page will run - if (command.hookTrigger && command.hookTrigger == commandWebsocketHookTrigger - && typeof commandWebsocketHook === 'function') { - commandWebsocketHook(command.hookParams); - } + // if learner's currently displayed page has hookTrigger same as in the JSON + // then a function also defined on that page will run + if (command.hookTrigger && command.hookTrigger == commandWebsocketHookTrigger + && typeof commandWebsocketHook === 'function') { + commandWebsocketHook(command.hookParams); + } - if (command.redirectURL) { - window.location.href = command.redirectURL; - } + if (command.redirectURL) { + window.location.href = command.redirectURL; + } - if (command.discussion) { - var discussionCommand = $('#discussion-sentiment-command'); - if (discussionCommand.length === 0) { - discussionCommand = $('
').attr('id', 'discussion-sentiment-command').appendTo('body'); + if (command.discussion) { + var discussionCommand = $('#discussion-sentiment-command'); + if (discussionCommand.length === 0) { + discussionCommand = $('
').attr('id', 'discussion-sentiment-command').appendTo('body'); + } + discussionCommand.load(LEARNING_URL + "discussionSentiment/" + command.discussion + ".do", { + lessonId : lessonId + }); } - discussionCommand.load(LEARNING_URL + "discussionSentiment/" + command.discussion + ".do", { - lessonId : lessonId - }); - } - // reset ping timer - websocketPing('commandWebsocket', true); - }; - } + // reset ping timer + websocketPing('commandWebsocket', true); + }); } }); } Index: lams_learning/web/WEB-INF/tags/Page5.tag =================================================================== diff -u -r9496ff3ffe5e98272f7939a2cf4e8c6dbb2901f7 -r876e644c066e81c2721ffa085fd12f386e2f3bb6 --- lams_learning/web/WEB-INF/tags/Page5.tag (.../Page5.tag) (revision 9496ff3ffe5e98272f7939a2cf4e8c6dbb2901f7) +++ lams_learning/web/WEB-INF/tags/Page5.tag (.../Page5.tag) (revision 876e644c066e81c2721ffa085fd12f386e2f3bb6) @@ -233,51 +233,47 @@ }); } - let commandWebsocket = initWebsocket('commandWebsocket', LEARNING_URL.replace('http', 'ws') - + 'commandWebsocket?lessonID=' + lessonId); - - if (commandWebsocket) { - // when the server pushes new inputs - commandWebsocket.onmessage = function (e) { - // read JSON object - var command = JSON.parse(e.data); - if (command.message) { - // some tools implement autosave feature - // if it is such a tool, trigger it - if (command.message === 'autosave') { - // the name of this function is same in all tools - if (typeof learnerAutosave == 'function') { - learnerAutosave(true); + initWebsocket('commandWebsocket', LEARNING_URL.replace('http', 'ws') + + 'commandWebsocket?lessonID=' + lessonId, + function (e) { + // read JSON object + var command = JSON.parse(e.data); + if (command.message) { + // some tools implement autosave feature + // if it is such a tool, trigger it + if (command.message === 'autosave') { + // the name of this function is same in all tools + if (typeof learnerAutosave == 'function') { + learnerAutosave(true); + } + } else { + alert(command.message); } - } else { - alert(command.message); } - } - // if learner's currently displayed page has hookTrigger same as in the JSON - // then a function also defined on that page will run - if (command.hookTrigger && command.hookTrigger == commandWebsocketHookTrigger - && typeof commandWebsocketHook === 'function') { - commandWebsocketHook(command.hookParams); - } + // if learner's currently displayed page has hookTrigger same as in the JSON + // then a function also defined on that page will run + if (command.hookTrigger && command.hookTrigger == commandWebsocketHookTrigger + && typeof commandWebsocketHook === 'function') { + commandWebsocketHook(command.hookParams); + } - if (command.redirectURL) { - window.location.href = command.redirectURL; - } + if (command.redirectURL) { + window.location.href = command.redirectURL; + } - if (command.discussion) { - var discussionCommand = $('#discussion-sentiment-command'); - if (discussionCommand.length === 0) { - discussionCommand = $('
').attr('id', 'discussion-sentiment-command').appendTo('body'); + if (command.discussion) { + var discussionCommand = $('#discussion-sentiment-command'); + if (discussionCommand.length === 0) { + discussionCommand = $('
').attr('id', 'discussion-sentiment-command').appendTo('body'); + } + discussionCommand.load(LEARNING_URL + "discussionSentiment/" + command.discussion + ".do", { + lessonId : lessonId + }); } - discussionCommand.load(LEARNING_URL + "discussionSentiment/" + command.discussion + ".do", { - lessonId : lessonId - }); - } - // reset ping timer - websocketPing('commandWebsocket', true); - }; - } + // reset ping timer + websocketPing('commandWebsocket', true); + }); } }); } Index: lams_learning/web/includes/javascript/kumalive.js =================================================================== diff -u -r9496ff3ffe5e98272f7939a2cf4e8c6dbb2901f7 -r876e644c066e81c2721ffa085fd12f386e2f3bb6 --- lams_learning/web/includes/javascript/kumalive.js (.../kumalive.js) (revision 9496ff3ffe5e98272f7939a2cf4e8c6dbb2901f7) +++ lams_learning/web/includes/javascript/kumalive.js (.../kumalive.js) (revision 876e644c066e81c2721ffa085fd12f386e2f3bb6) @@ -26,8 +26,92 @@ ANIMATION_DURATION = 1000, websocket = initWebsocket('kumalive' + orgId, LEARNING_URL.replace('http', 'ws') - + 'kumaliveWebsocket?organisationID=' + orgId + '&role=' + role); + + 'kumaliveWebsocket?organisationID=' + orgId + '&role=' + role, + function (e) { + // read JSON object + var message = JSON.parse(e.data), + type = message.type; + // check what is this message about + switch(type) { + case 'start' : { + // user tried to join a Kumalive which is not started yet + // try to start it, if user is a teacher + // otherwise just wait for a teacher + this.send(JSON.stringify({ + 'type' : 'start', + 'role' : role + })); + } + break; + case 'create' : { + // user is a teacher and will now create a new Kumalive + // hide splash screen + $('#initDiv').hide(); + // show name input + var createDiv = $('#createKumaliveDiv'), + rubricsDiv = $('#rubrics .panel-body', createDiv); + if (message.rubrics) { + $.each(message.rubrics, function(){ + if (this) { + var checkbox = $('
').addClass('checkbox').appendTo(rubricsDiv), + label = $('