{"version":3,"file":"media_refresher.min.js","sources":["../src/media_refresher.js"],"sourcesContent":["/* jshint ignore:start */\ndefine(['jquery', 'core/log'], function ($, log) {\n\n    \"use strict\"; // jshint ;_;\n\n    log.debug('Media refresher: initialising');\n\n    return {\n\n        placeholderduration: null,\n        mediaduration: null, //audio or video tag\n        alertconverted: null,\n\n        //for making multiple instances\n        clone: function () {\n            return $.extend(true, {}, this);\n        },\n\n        //pass in config, the jquery video/audio object, and a function to be called when conversion has finshed\n        init: function (filename, placeholderduration, mediaduration, alertconverted) {\n            //debugger;\n            this.placeholderduration = placeholderduration;\n            this.mediaduration = mediaduration;\n            this.alertconverted = alertconverted;\n            this.check_updates(filename, 'firstpass');\n        },\n\n        should_be_checked: function (filename) {\n            //check this is an unconverted recording that we need to track\n\n            log.debug('mediaduration: ' + this.mediaduration);\n            log.debug('placeholderduration: ' + this.placeholderduration);\n            log.debug('fixed to one mediaduration: ' + parseFloat(this.mediaduration).toFixed(1));\n            log.debug('fixed to one placeholderduration: ' + parseFloat(this.placeholderduration).toFixed(1));\n\n            //if any of these numbers is not numeric we kill it\n            if (!$.isNumeric(this.placeholderduration)) {\n                return false;\n            }\n            if (!$.isNumeric(this.mediaduration)) {\n                return false;\n            }\n            //if the two numbers are equivalent to one decimal place we credit it\n            //firefox calcs mp3 size diff to chrome, but they seem same to 1 place ... now anyway\n            if (parseFloat(this.mediaduration).toFixed(1) != parseFloat(this.placeholderduration).toFixed(1)) {\n                return false;\n            }\n            //this is a bogus check.\n            //later we only want to check filenames that look like poodll recorded ones\n            if (filename == '') {\n                return false;\n            }\n            return true;\n        },\n\n        check_updates: function (filename, checktype) {\n            //checktype:firstpass - if have a task then we keep checking till there is no task\n            //then we know its finished. Those checks are the 'secondpass'\n            this.should_be_checked(filename);\n            //check this is a recording that we need to track\n            if (checktype == 'firstpass' && !this.should_be_checked(filename)) {\n                return;\n            }\n\n            //set up our ajax request\n            var xhr = new XMLHttpRequest();\n            var that = this;\n\n            //set up our handler for the response\n            xhr.onreadystatechange = function (e) {\n                if (this.readyState === 4) {\n                    if (xhr.status == 200) {\n\n                        //get a yes or forgetit or tryagain\n                        var payload = xhr.responseText;\n                        var payloadobject = JSON.parse(payload);\n                        if (payloadobject) {\n                            switch (payloadobject.code) {\n\n                                case 'mediaready':\n                                    that.alertconverted();\n                                    break;\n                                case 'stillwaiting':\n                                    setTimeout(function () {\n                                        that.check_updates(filename, 'secondpass')\n                                    }, 15000);\n                                    break;\n                                case 'notask':\n                                    if (checktype == 'secondpass') {\n                                        that.alertconverted();\n                                    }\n                                    break;\n                                case 'notloggedin':\n                                default:\n                                //just stop trying in this case\n                                //the task is long ago processed or its not a rec. or something\n                            }\n                        }\n                    } else {\n                        log.debug('Not 200 response:' + xhr.status);\n                    }\n                }\n            };\n\n            //log.debug(params);\n            var params = \"filename=\" + filename;\n            xhr.open(\"POST\", M.cfg.wwwroot + '/filter/poodll/ajaxmediaquery.php', true);\n            xhr.setRequestHeader(\"Content-Type\", \"application/x-www-form-urlencoded\");\n            xhr.setRequestHeader(\"Cache-Control\", \"no-cache\");\n            xhr.send(params);\n        }\n    };//end of returned object\n});//total end\n"],"names":["define","$","log","debug","placeholderduration","mediaduration","alertconverted","clone","extend","this","init","filename","check_updates","should_be_checked","parseFloat","toFixed","isNumeric","checktype","xhr","XMLHttpRequest","that","onreadystatechange","e","readyState","status","payload","responseText","payloadobject","JSON","parse","code","setTimeout","params","open","M","cfg","wwwroot","setRequestHeader","send"],"mappings":"AACAA,uCAAO,CAAC,SAAU,aAAa,SAAUC,EAAGC,YAIxCA,IAAIC,MAAM,iCAEH,CAEHC,oBAAqB,KACrBC,cAAe,KACfC,eAAgB,KAGhBC,MAAO,kBACIN,EAAEO,QAAO,EAAM,GAAIC,OAI9BC,KAAM,SAAUC,SAAUP,oBAAqBC,cAAeC,qBAErDF,oBAAsBA,yBACtBC,cAAgBA,mBAChBC,eAAiBA,oBACjBM,cAAcD,SAAU,cAGjCE,kBAAmB,SAAUF,iBAGzBT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