Index: lams_learning/web/includes/javascript/kumalive.js =================================================================== diff -u -r62aaf160878735888d077bf28fac3c1989bb8fbd -r89279cb44b252167269043889b3c3c0a4164e0bb --- lams_learning/web/includes/javascript/kumalive.js (.../kumalive.js) (revision 62aaf160878735888d077bf28fac3c1989bb8fbd) +++ lams_learning/web/includes/javascript/kumalive.js (.../kumalive.js) (revision 89279cb44b252167269043889b3c3c0a4164e0bb) @@ -1,1073 +1,1073 @@ -"use strict" - -var kumaliveWebsocket = new WebSocket(LEARNING_URL.replace('http', 'ws') - + 'kumaliveWebsocket?organisationID=' + orgId + '&role=' +role), - kumaliveWebsocketPingTimeout = null, - kumaliveWebsocketPingFunc = null, - // is the user a learenr or a teacher - roleTeacher = false, - // was the initial set up run - initialised = false, - // is a refresh already running, so next messages need to wait - refreshing = false, - // refresh message awaiting processing - queuedMessage = null, - // is there a learner speaking right now - speakerId = null, - // rubrics to evaluate speaker - rubrics = null, - // is a poll running now and what ID - pollId = null, - // answers will be numbered - pollAnswerBullets = 'abcdefghij', - // index of user icon colour currently used - learnerColorIndex = 1, - // template of a HTML structure of a learner - learnerDivTemplate = $('
').addClass('learner changing') - .append($('
').addClass('profilePicture profilePictureHidden')) - .append($('
').addClass('name')), - REFRESH_DELAY = 1000, - ANIMATION_DURATION = 1000, - PING_DELAY = 3*60*1000; - -kumaliveWebsocketPingFunc = function(skipPing){ - if (kumaliveWebsocket.readyState == kumaliveWebsocket.CLOSING - || kumaliveWebsocket.readyState == kumaliveWebsocket.CLOSED){ - location.reload(); - } - - // check and ping every few minutes - kumaliveWebsocketPingTimeout = setTimeout(kumaliveWebsocketPingFunc, PING_DELAY); - // initial set up does not send ping - if (!skipPing) { - kumaliveWebsocket.send("ping"); - } -}; -// set up timer for the first time -kumaliveWebsocketPingFunc(true); - -kumaliveWebsocket.onclose = function(e){ - // react only on abnormal close - if (e.code === 1006) { - location.reload(); - } -}; -// when the server pushes new messages and roster to the learner's browser - - -/** - * Fetches existing Kumalive session - */ -kumaliveWebsocket.onopen = function(e) { - kumaliveWebsocket.send(JSON.stringify({ - 'type' : 'start' - })); -}; - -/** - * Display information to an user when he gets disconnected - */ -kumaliveWebsocket.onclose = function(e){ - $('body > *').hide(); - $('#closedDiv').show(); -}; - -/** - * Process a message from server. - */ -kumaliveWebsocket.onmessage = function(e){ - // reset ping timer - clearTimeout(kumaliveWebsocketPingTimeout); - kumaliveWebsocketPingFunc(true); - - // 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 - kumaliveWebsocket.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 = $('