{"version":3,"sources":["https:\/\/avenue.ca\/classroom\/lib\/amd\/src\/network.js"],"names":["define","$","Ajax","Config","Notification","Str","started","warningDisplayed","keepAliveFrequency","requestTimeout","keepAliveMessage","sessionTimeout","checkFrequency","Math","min","sessiontimeout","timeoutSessionExpired","touchSession","get_strings","key","component","then","strings","alert","fail","exception","call","methodname","args","setTimeout","checkSession","userid","timeremaining","confirm","start","isMoodleIframe","window","parent","parentUrl","location","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,CAgB7CC,CAAqB,CAAG,UAAW,CACnCL,CAAc,GACjB,CAlBgD,CAyB7CM,CAAY,CAAG,UAAW,CAM1B,GAAIN,CAAJ,CAAoB,CAEhB,MAAON,CAAAA,CAAG,CAACa,WAAJ,CAAgB,CACnB,CAACC,GAAG,CAAE,gBAAN,CAAwBC,SAAS,CAAE,OAAnC,CADmB,CAEnB,CAACD,GAAG,CAAE,kBAAN,CAA0BC,SAAS,CAAE,OAArC,CAFmB,CAAhB,EAGJC,IAHI,CAGC,SAASC,CAAT,CAAkB,CACtBlB,CAAY,CAACmB,KAAb,CACID,CAAO,CAAC,CAAD,CADX,CAEIA,CAAO,CAAC,CAAD,CAFX,EAIA,QACH,CATM,EASJE,I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B,CAE1B,QACH,CAGD,GAAIE,CAAAA,CAAJ,CACA,GAAI,CACAA,CAAS,CAAGF,MAAM,CAACC,MAAP,CAAcE,QAAd,CAAuBC,IACtC,CAAC,MAAOC,CAAP,CAAU,CAER,QACH,CAED,MAAOH,CAAAA,CAAS,CAACI,UAAV,CAAqBC,CAAC,CAACC,GAAF,CAAMC,OAA3B,CACV,CA3JgD,CAgK7CC,CAAI,CAAG,UAAW,CAElB,GAAIxC,CAAJ,CAAa,CACT,MACH,CACDA,CAAO,GAAP,CAEA,GAAI6B,CAAc,EAAlB,CAAsB,CAClBC,MAAM,CAACW,OAAP,CAAeC,GAAf,CAAmB,6DAAnB,EACA,MACH,CAEDZ,MAAM,CAACW,OAAP,CAAeC,GAAf,CAAmB,0CAAnB,EAEAd,CAAK,EACR,CA\/KgD,CAwL7Ce,CAAS,CAAG,SAASC,CAAT,CAAeC,CAAf,CAAwBC,CAAxB,CAAiC,CAE7C,GAAI9C,CAAJ,CAAa,CACT8B,MAAM,CAACW,OAAP,CAAeM,IAAf,CAAoB,+EAApB,EACA,MACH,CACD\/C,CAAO,GAAP,CAEA,GAAI6B,CAAc,EAAlB,CAAsB,CAClBC,MAAM,CAACW,OAAP,CAAeM,IAAf,CAAoB,wEAApB,EACA,MACH,CAEDjB,MAAM,CAACW,OAAP,CAAeC,GAAf,CAAmB,qCAAnB,EAEAxC,CAAkB,CAAU,GAAP,CAAA0C,CAArB,CACAxC,CAAgB,CAAG0C,CAAnB,CACA3C,CAAc,CAAa,GAAV,CAAA0C,CAAjB,CACAjB,CAAK,EACR,CA3MgD,CA6MjD,MAAO,CACHe,SAAS,CAAEA,CADR,CAEHH,IAAI,CAAEA,CAFH,CAIV,CAlNK,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 \/\/ 1\/5 of sessiontimeout.\n var warningLimit = checkFrequency * 2;\n\n \/**\n * The session time has expired - we can't extend it now.\n *\/\n var timeoutSessionExpired = function() {\n sessionTimeout = true;\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 Str.get_strings([\n {key: 'sessionexpired', component: 'error'},\n {key: 'sessionerroruser', component: 'error'}\n ]).then(function(strings) {\n Notification.alert(\n strings[0], \/\/ Title.\n strings[1] \/\/ Message.\n );\n return true;\n }).fail(Notification.exception);\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 }).fail(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\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 Str.get_strings([\n {key: 'sessionexpired', component: 'error'},\n {key: 'sessionerroruser', component: 'error'}\n ]).then(function(strings) {\n Notification.alert(\n strings[0], \/\/ Title.\n strings[1] \/\/ Message.\n );\n return true;\n }).fail(Notification.exception);\n\n } else if (args.timeremaining * 1000 < warningLimit && !warningDisplayed) {\n \/\/ If we don't extend the session before the timeout - warn.\n setTimeout(timeoutSessionExpired, args.timeremaining * 1000);\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 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 half the session timeout.\n setTimeout(checkSession, checkFrequency * 5);\n return true;\n },\n function() {\n warningDisplayed = false;\n setTimeout(checkSession, checkFrequency);\n }\n );\n return true;\n }).fail(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 half the session timeout.\n setTimeout(checkSession, checkFrequency * 5);\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"}