var benchconnection; var benchconnnected = false; var timerID = 0; var wasconnected; var activetab = true; var trackingalready = false; $( document ).ready(function() { console.log( "ready!" ); startTracking(); }); //function connecttb() { // var tabID = sessionStorage.tabID && sessionStorage.closedLastTab !== '2' ? sessionStorage.tabID : sessionStorage.tabID = Math.random(); // sessionStorage.closedLastTab = '2'; // $(window).on('unload beforeunload', function() { // sessionStorage.closedLastTab = '1'; // }); // // var protocol = location.protocol; // var channelinfo = jQuery(".chatterbox").data("channel"); // if (protocol === "https:") { // benchconnection = new WebSocket("wss://" +location.host + "/entermedia/services/websocket/org/netevolved/websocket/BenchConnection?sessionid=" + tabID + "&channel=" + channelinfo); // } else{ // benchconnection = new WebSocket("ws://" +location.host + "/entermedia/services/websocket/org/netevolved/websocket/BenchConnection?sessionid=" + tabID + "&channel=" + channelinfo); // } // benchconnection.onmessage = function(event) { // console.log("Start"); // var app = jQuery("#application"); // var apphome = app.data("home") + app.data("apphome"); // var message = JSON.parse(event.data); // var command = message.command; // console.log("Command received: " + command); // if("slidechange" === command){ // jQuery(".slidechange").each(function () { // var ajaxpath = jQuery(this).data("ajaxpath"); // jQuery("#currentslide").load(ajaxpath); // console.log("slidechange detected " + ajaxpath); // }); // } // if("reload" === command){ // location.reload(); // } // // if(activetab){ // if("notify" === command){ // $.notify(message.content); // } // // }else{ // $.notify(message.content); // // // } // // // // }; // //} $(window).on("blur focus", function(e) { var prevType = $(this).data("prevType"); if (prevType != e.type) { // reduce double fire issues switch (e.type) { case "blur": activetab = false; console.log("user went to another tab/window"); break; case "focus": activetab = true; console.log("user showed window again"); break; } } $(this).data("prevType", e.type); }) function startTracking() { console.log("checking vote"); var timeout = 20000; var connectioninfo = jQuery("#application").data(); var app = jQuery("#application"); var apphome = app.data("home") + app.data("apphome"); var classid = app.data("classid"); if(classid){ var urls = apphome + "/classes/" + classid + "/livetest/vote.html?oemaxlevel=1"; $.ajax({ type: 'GET', url: urls, dataType: 'html', success: function(data) { var something = jQuery(data); var currentslide = something.data("currentnode"); var onscreen = jQuery("#slidechange").data("currentnode"); if(currentslide != onscreen){ jQuery("#currentslide").html(data); } }, async: false }); } timerId = setTimeout(startTracking, timeout); } function cancelKeepAlive() { if (timerId) { clearTimeout(timerId); } } function testPathEvent(){ var data ='{"runpath":"/bootstrapfrontend/index.html","catalogid":"bootstrapfrontend/system"}'; if(benchconnection.readyState === benchconnection.CLOSED ){ connecttb(); // IF we do a reconnect render the whole page } benchconnection.send(data); } function desktopNotify(message) { if (!window.Notification) { console.log('Browser does not support notifications.'); } else { // check if permission is already granted if (Notification.permission === 'granted') { // show notification here var notify = new Notification(message, { body: message, icon: 'https://bit.ly/2DYqRrh', }); } else { // request permission from user Notification.requestPermission().then(function (p) { if (p === 'granted') { // show notification here var notify = new Notification(message, { body: message, icon: 'https://bit.ly/2DYqRrh', }); } else { console.log('User blocked notifications.'); } }).catch(function (err) { console.error(err); }); } } } function validateSlide(){ }