Index: lams_tool_doku/web/WEB-INF/tags/Page.tag =================================================================== RCS file: /usr/local/cvsroot/lams_tool_doku/web/WEB-INF/tags/Page.tag,v diff -u -r1.2 -r1.3 --- lams_tool_doku/web/WEB-INF/tags/Page.tag 24 Mar 2017 01:13:11 -0000 1.2 +++ lams_tool_doku/web/WEB-INF/tags/Page.tag 13 May 2017 06:28:38 -0000 1.3 @@ -147,6 +147,31 @@ $('#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(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; + } + }; + } + $(document).ready(function() { var showControlBar = 1; // 0/1/2 none/full/keep space var showIM = true; @@ -203,19 +228,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(); } }); }