Closed sailei1 closed 3 years ago
var worker_script = ''; worker_script += 'var aaa = 0;'; worker_script += 'function timedCount()'; worker_script += '{'; worker_script += ' aaa=aaa+1;'; worker_script += ' postMessage(aaa);'; // worker_script += " var time = new Date();"; // worker_script += " console.log(\"[heartbeat time:\" + time.toLocaleTimeString() + \"] \");"; worker_script += ' setTimeout("timedCount()",20000);'; worker_script += '}'; worker_script += 'timedCount();'; var worker_blob = new Blob([worker_script], { type: 'text/javascript', }); var worker_src = URL.createObjectURL(worker_blob); if (typeof Worker !== 'undefined') { if (typeof w == 'undefined') { w = new Worker(worker_src); } w.onmessage = function (event) { // console.log("支持 Web Workers..."); self.__send({ class: 'general', method: 'heartbeat', params: null }); var time = new Date(); // console.log("[heartbeat time:" + time.toLocaleTimeString() + ",state-" + self.agent_state + "] "); }; } else { // console.log("抱歉,你的浏览器不支持 Web Workers..."); ... }