{"version":3,"sources":["https:\/\/dpielts.lk\/lib\/amd\/src\/network.js"],"names":["define","$","Ajax","Config","Notification","Str","started","warningDisplayed","keepAliveFrequency","requestTimeout","keepAliveMessage","sessionTimeout","checkFrequency","Math","min","sessiontimeout","warningLimit","sessiontimeoutwarning","firstWait","timeoutSessionExpired","modal","closeModal","displaySessionExpired","destroy","call","methodname","args","then","timeremaining","get_strings","key","component","strings","confirm","location","reload","catch","exception","touchSession","setTimeout","alert","checkSession","userid","start","isMoodleIframe","window","parent","parentUrl","href","e","startsWith","M","cfg","wwwroot","init","console","log","keepalive","freq","timeout","message","warn"],"mappings":"AAsBAA,OAAM,gBAAC,CAAC,QAAD,CAAW,WAAX,CAAwB,aAAxB,CAAuC,mBAAvC,CAA4D,UAA5D,CAAD,CACE,SAASC,CAAT,CAAYC,CAAZ,CAAkBC,CAAlB,CAA0BC,CAA1B,CAAwCC,CAAxC,CAA6C,IAE7CC,CAAAA,CAAO,GAFsC,CAG7CC,CAAgB,GAH6B,CAI7CC,CAAkB,CAAG,CAJwB,CAK7CC,CAAc,CAAG,CAL4B,CAM7CC,CAAgB,GAN6B,CAO7CC,CAAc,GAP+B,CAS7CC,CAAc,CAAiD,GAA9C,CAAAC,IAAI,CAACC,GAAL,CAAUX,CAAM,CAACY,cAAP,CAAwB,EAAlC,CAAuC,GAAvC,CAT4B,CAW7CC,CAAY,CAAmC,CAA\/B,CAAAb,CAAM,CAACc,qBAAR,CAAqE,GAA\/B,CAAAd,CAAM,CAACc,qBAA7C,CAA+F,CAAjB,CAAAL,CAXhD,CAa7CM,CAAS,CAAmC,CAA\/B,CAAAf,CAAM,CAACc,qBAAR,CACZJ,IAAI,CAACC,GAAL,CAAkE,GAAzD,EAACX,CAAM,CAACY,cAAP,CAAwBZ,CAAM,CAACc,qBAAhC,CAAT,CAAyF,CAAjB,CAAAL,CAAxE,CADY,CACmG,CAAjB,CAAAA,CAdjD,CAmB7CO,CAAqB,CAAG,SAASC,CAAT,CAAgB,CACxCT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CAAc,EAAlB,CAAsB,CAClBC,MAAM,CAACU,OAAP,CAAeC,GAAf,CAAmB,6DAAnB,EACA,MACH,CAEDX,MAAM,CAACU,OAAP,CAAeC,GAAf,CAAmB,0CAAnB,EAEAb,CAAK,EACR,CAhNgD,CAyN7Cc,CAAS,CAAG,SAASC,CAAT,CAAeC,CAAf,CAAwBC,CAAxB,CAAiC,CAE7C,GAAItD,CAAJ,CAAa,CACTuC,MAAM,CAACU,OAAP,CAAeM,IAAf,CAAoB,+EAApB,EACA,MACH,CACDvD,CAAO,GAAP,CAEA,GAAIsC,CAAc,EAAlB,CAAsB,CAClBC,MAAM,CAACU,OAAP,CAAeM,IAAf,CAAoB,wEAApB,EACA,MACH,CAEDhB,MAAM,CAACU,OAAP,CAAeC,GAAf,CAAmB,qCAAnB,EAEAhD,CAAkB,CAAU,GAAP,CAAAkD,CAArB,CACAhD,CAAgB,CAAGkD,CAAnB,CACAnD,CAAc,CAAa,GAAV,CAAAkD,CAAjB,CACAhB,CAAK,EACR,CA5OgD,CA8OjD,MAAO,CACHc,SAAS,CAAEA,CADR,CAEHH,IAAI,CAAEA,CAFH,CAIV,CAnPK,CAAN","sourcesContent":["\/\/ This file is part of Moodle - http:\/\/moodle.org\/\n\/\/\n\/\/ Moodle is free software: you can redistribute it and\/or modify\n\/\/ it under the terms of the GNU General Public License as published by\n\/\/ the Free Software Foundation, either version 3 of the License, or\n\/\/ (at your option) any later version.\n\/\/\n\/\/ Moodle is distributed in the hope that it will be useful,\n\/\/ but WITHOUT ANY WARRANTY; without even the implied warranty of\n\/\/ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\/\/ GNU General Public License for more details.\n\/\/\n\/\/ You should have received a copy of the GNU General Public License\n\/\/ along with Moodle. If not, see .\n\n\/**\n * Poll the server to keep the session alive.\n *\n * @module core\/network\n * @copyright 2019 Damyon Wiese\n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n *\/\ndefine(['jquery', 'core\/ajax', 'core\/config', 'core\/notification', 'core\/str'],\n function($, Ajax, Config, Notification, Str) {\n\n var started = false;\n var warningDisplayed = false;\n var keepAliveFrequency = 0;\n var requestTimeout = 0;\n var keepAliveMessage = false;\n var sessionTimeout = false;\n \/\/ 1\/10 of session timeout, max of 10 minutes.\n var checkFrequency = Math.min((Config.sessiontimeout \/ 10), 600) * 1000;\n \/\/ Check if sessiontimeoutwarning is set or double the checkFrequency.\n var warningLimit = (Config.sessiontimeoutwarning > 0) ? (Config.sessiontimeoutwarning * 1000) : (checkFrequency * 2);\n \/\/ First wait is minimum of remaining time or half of the session timeout.\n var firstWait = (Config.sessiontimeoutwarning > 0) ?\n Math.min((Config.sessiontimeout - Config.sessiontimeoutwarning) * 1000, checkFrequency * 5) : checkFrequency * 5;\n \/**\n * The session time has expired - we can't extend it now.\n * @param {Modal} modal\n *\/\n var timeoutSessionExpired = function(modal) {\n sessionTimeout = true;\n warningDisplayed = false;\n closeModal(modal);\n displaySessionExpired();\n };\n\n \/**\n * Close modal - this relies on modal object passed from Notification.confirm.\n *\n * @param {Modal} modal\n *\/\n var closeModal = function(modal) {\n modal.destroy();\n };\n\n \/**\n * The session time has expired - we can't extend it now.\n * @return {Promise}\n *\/\n var displaySessionExpired = function() {\n \/\/ Check again if its already extended before displaying session expired popup in case multiple tabs are open.\n var request = {\n methodname: 'core_session_time_remaining',\n args: { }\n };\n\n return Ajax.call([request], true, true, true)[0].then(function(args) {\n if (args.timeremaining * 1000 > warningLimit) {\n return false;\n } else {\n return Str.get_strings([\n {key: 'sessionexpired', component: 'error'},\n {key: 'sessionerroruser', component: 'error'},\n {key: 'loginagain', component: 'moodle'},\n {key: 'cancel', component: 'moodle'}\n ]).then(function(strings) {\n Notification.confirm(\n strings[0], \/\/ Title.\n strings[1], \/\/ Message.\n strings[2], \/\/ Login Again.\n strings[3], \/\/ Cancel.\n function() {\n location.reload();\n return true;\n }\n );\n return true;\n }).catch(Notification.exception);\n }\n });\n };\n\n \/**\n * Ping the server to keep the session alive.\n *\n * @return {Promise}\n *\/\n var touchSession = function() {\n var request = {\n methodname: 'core_session_touch',\n args: { }\n };\n\n if (sessionTimeout) {\n \/\/ We timed out before we extended the session.\n return displaySessionExpired();\n } else {\n return Ajax.call([request], true, true, false, requestTimeout)[0].then(function() {\n if (keepAliveFrequency > 0) {\n setTimeout(touchSession, keepAliveFrequency);\n }\n return true;\n }).catch(function() {\n Notification.alert('', keepAliveMessage);\n });\n }\n };\n\n \/**\n * Ask the server how much time is remaining in this session and\n * show confirm\/cancel notifications if the session is about to run out.\n *\n * @return {Promise}\n *\/\n var checkSession = function() {\n var request = {\n methodname: 'core_session_time_remaining',\n args: { }\n };\n sessionTimeout = false;\n return Ajax.call([request], true, true, true)[0].then(function(args) {\n if (args.userid <= 0) {\n return false;\n }\n if (args.timeremaining <= 0) {\n return displaySessionExpired();\n } else if (args.timeremaining * 1000 <= warningLimit && !warningDisplayed) {\n warningDisplayed = true;\n Str.get_strings([\n {key: 'norecentactivity', component: 'moodle'},\n {key: 'sessiontimeoutsoon', component: 'moodle'},\n {key: 'extendsession', component: 'moodle'},\n {key: 'cancel', component: 'moodle'}\n ]).then(function(strings) {\n return Notification.confirm(\n strings[0], \/\/ Title.\n strings[1], \/\/ Message.\n strings[2], \/\/ Extend session.\n strings[3], \/\/ Cancel.\n function() {\n touchSession();\n warningDisplayed = false;\n \/\/ First wait is minimum of remaining time or half of the session timeout.\n setTimeout(checkSession, firstWait);\n return true;\n },\n function() {\n \/\/ User has cancelled notification.\n setTimeout(checkSession, checkFrequency);\n }\n );\n }).then(modal => {\n \/\/ If we don't extend the session before the timeout - warn.\n setTimeout(timeoutSessionExpired, args.timeremaining * 1000, modal);\n return;\n }).catch(Notification.exception);\n } else {\n setTimeout(checkSession, checkFrequency);\n }\n return true;\n });\n \/\/ We do not catch the fails from the above ajax call because they will fail when\n \/\/ we are not logged in - we don't need to take any action then.\n };\n\n \/**\n * Start calling a function to check if the session is still alive.\n *\/\n var start = function() {\n if (keepAliveFrequency > 0) {\n setTimeout(touchSession, keepAliveFrequency);\n } else {\n \/\/ First wait is minimum of remaining time or half of the session timeout.\n setTimeout(checkSession, firstWait);\n }\n };\n\n \/**\n * Are we in an iframe and the parent page is from the same Moodle site?\n *\n * @return {boolean} true if we are in an iframe in a page from this Moodle site.\n *\/\n const isMoodleIframe = function() {\n if (window.parent === window) {\n \/\/ Not in an iframe.\n return false;\n }\n\n \/\/ We are in an iframe. Is the parent from the same Moodle site?\n let parentUrl;\n try {\n parentUrl = window.parent.location.href;\n } catch (e) {\n \/\/ If we cannot access the URL of the parent page, it must be another site.\n return false;\n }\n\n return parentUrl.startsWith(M.cfg.wwwroot);\n };\n\n \/**\n * Don't allow more than one of these polling loops in a single page.\n *\/\n var init = function() {\n \/\/ We only allow one concurrent instance of this checker.\n if (started) {\n return;\n }\n started = true;\n\n if (isMoodleIframe()) {\n window.console.log('Not starting Moodle session timeout warning in this iframe.');\n return;\n }\n\n window.console.log('Starting Moodle session timeout warning.');\n\n start();\n };\n\n \/**\n * Start polling with more specific values for the frequency, timeout and message.\n *\n * @param {number} freq How ofter to poll the server.\n * @param {number} timeout The time to wait for each request to the server.\n * @param {string} message The message to display if the session is going to time out.\n *\/\n var keepalive = function(freq, timeout, message) {\n \/\/ We only allow one concurrent instance of this checker.\n if (started) {\n window.console.warn('Ignoring session keep-alive. The core\/network module was already initialised.');\n return;\n }\n started = true;\n\n if (isMoodleIframe()) {\n window.console.warn('Ignoring session keep-alive in this iframe inside another Moodle page.');\n return;\n }\n\n window.console.log('Starting Moodle session keep-alive.');\n\n keepAliveFrequency = freq * 1000;\n keepAliveMessage = message;\n requestTimeout = timeout * 1000;\n start();\n };\n\n return {\n keepalive: keepalive,\n init: init\n };\n});\n"],"file":"network.min.js"}