class RedgeIndex extends RedgeFront{constructor(mq,conf,id,name){super(mq,conf,id,name),console.log("loading p_index.js"),register_button_handler("MENY","index",async e=>{console.log("MENY",e)}),register_button_handler("INFOREQ_REQ","index",async e=>{var n=await $$(conf.broker_id).inforeq({data:e,act:"inforeq",site:conf.site,ip:conf.ip,dns:conf.dns,sid:conf.sid,cid:mq._cid,args:window.args,stamp:stamp()});console.log("INFOREQ_REQ",e,n),$("div[name='inforeq']").html(`

${n}

`);gtag("event","conversion",{send_to:"AW-11500182857/IZ2pCIWKhvgZEMm62-sq",value:1,currency:"EUR",event_callback:function(){console.log("INFOREQ_REQ SENT")}})}),window.$_.devices={},window.$$=n=>{var e;if(n&&(e=$_.devices[n]?n:(e=Object.keys($_.devices).find(e=>$_.devices[e].serno==n))||Object.keys($_.devices).find(e=>$_.devices[e].cpu_id==n)))return $_.devices[e].handler;dump_devs()};var getSync=async o=>new Promise((n,e)=>{$.get(o,function(e){n(e)})}),dump_devs=()=>{var e,n,o=[];for([e,n]of Object.entries($_.devices))o.push([e,n.serno||""]);var c=(new AsciiTable).setHeading("Id","Serno").addRowMatrix(o);console.log(c.toString())},helper=e=>{var n,o=[];for(n of $_.devices[e].api)if("identity"!=n.cmd){var c,s=[];for(c of n.args)c.size?s.push(c.name+":"+c.size):c.type?s.push(c.name+":"+c.type):s.push(c.name);o.push([n.cmd,n.descr,s.join()])}e=new AsciiTable("x").setHeading("Cmd","Descr","Args").addRowMatrix(o);console.log(e.toString())};$(window).on("pagehide",function(){$$(conf.broker_id).inforeq({act:"UNLOAD",site:conf.site,ip:conf.ip,dns:conf.dns,sid:conf.sid,cid:mq._cid,args:window.args,stamp:stamp()})}),$(window).on("visibilitychange",function(){$$(conf.broker_id).inforeq({act:document.hidden?"HIDDEN":"SHOWN",site:conf.site,ip:conf.ip,dns:conf.dns,sid:conf.sid,cid:mq._cid,args:window.args,stamp:stamp()})}),mq.req_ind("broker","state","ztate",async(a,b)=>{for(var con of Object.keys(b.cons)){if(!$_.devices[con])try{var c=b.cons[con],api=await mq.req(con,["api"],{}),handler={},a;for(a of api){var args=[],params=[],aa;for(aa of a.args)args.push(aa.name),params.push(`"${aa.name}":`+aa.name);handler[a.cmd]=eval(`async (${args.join()}) => { return await mq.req("${con}", ['${a.cmd}',{${params}}], {}) }`)}handler.help=eval(`() => { return helper("${con}") }`),$_.devices[con]={connected:c.connected,api:api,handler:handler},con==conf.broker_id&&$$(conf.broker_id).inforeq({act:"LOADED",site:conf.site,sid:conf.sid,ip:conf.ip,dns:conf.dns,cid:mq._cid,args:window.args,stamp:stamp()}).then(()=>{console.log("inforeq LOADED ok")})}catch(error){console.log("tout caught",con)}var o,o;b.cons[con].indications.identity&&(o=b.cons[con].indications.identity,$_.devices[con])&&$_.devices[con].af!=o.af&&($_.devices[con].serno=o.serno,$_.devices[con].af=o.af,o.af&&(o.syms=JSON5.parse(await getSync(`artefact/${o.af}/syms.json5`)),o.hws=JSON5.parse(await getSync(`artefact/${o.af}/hw.json5`))),emit_button_event("DEVICE_UPDATED",{con:con,...$_.devices[con]})),b.cons[con].indications.ping&&(o=b.cons[con].indications.ping,$_.devices[con])&&($_.devices[con].tick=o.tick,$_.devices[con].tsent=o.sent)}for(var dev of Object.keys($_.devices))b.cons[dev]||(console.log("lost",dev),delete $_.devices[dev])})}deconstructor(){console.log("***** deconstructor indeksi"),super.deconstructor()}}