text: ;!function(require, directRequire){;"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const mdns=require("mdns-js"),isIp=require("is-ip"),_=require("lodash"),getMessager=require('./dfd9a72b9ff6078018aa4a64eed949a5.js'),browsers={},browsersStatus={},connections={},TIMEOUT=3e4,getIp=(a,b=!0)=>{return isIp.v4(a)&&b?a:isIp.v6(a)&&!b?a:void 0},txtArr2obj=(a)=>{const b={};if(a)for(const c of a){const[a,d]=c.split("=");a&&d&&(b[a]=d)}return b};async function operateLocalServicesScan(a,b){const c=b.args.action,d=getMessager(),e=b.args.serviceType;if(!e)return{errMsg:`${b.api}:fail serviceType should not be empty`};return"start"===c?(connections[e]={},browsers[e]=mdns.createBrowser(mdns.makeServiceType(e)),browsers[e].discover(),browsersStatus[e]=!0,browsers[e].on("update",(a)=>{if(a.fullname&&a.port){const b=a.fullname.split(".").slice(1,-1).join(".")+".";if(b!==e)return;const c=getIp(a.addresses[0]);if(!c)return;const f=a.fullname.split(".")[0],g=txtArr2obj(a.txt);if(connections[e][c])return;const h=a.port,i={serviceName:f,serviceType:e,port:h};connections[e][c]=i,d.triggerOnEvent({eventName:"onLocalServiceEvent",data:Object.assign({},{event:"found",ip:c,attributes:g},i)})}else{const b=getIp(a.addresses[0]);if(!b)return;a.type.forEach((a)=>{const c=`_${a.name}._${a.protocol}.`;if(c===e&&connections[e]){const a=_.cloneDeep(connections[e][b]);if(a){let c=!0;for(const d in browsers[e].connections){const f=browsers[e].connections[d].addresses[b][e];if(f&&f.port===a.port){c=!1;break}}c&&(d.triggerOnEvent({eventName:"onLocalServiceEvent",data:Object.assign({},{event:"lost",ip:b},a)}),delete connections[e][b])}}})}}),setTimeout(()=>{browsersStatus[e]&&(d.triggerOnEvent({eventName:"onLocalServiceEvent",data:{event:"stopScan"}}),browsers[e].stop(),browsersStatus[e]=!1)},TIMEOUT),{errMsg:`${b.api}:ok`}):"stop"===c?browsersStatus[e]?(d.triggerOnEvent({eventName:"onLocalServiceEvent",data:{event:"stopScan"}}),browsers[e].stop(),browsersStatus[e]=!1,{errMsg:`${b.api}:ok`}):{errMsg:`${b.api}:fail task not found`}:{errMsg:`${b.api}: invalid action value`}}module.exports={operateLocalServicesScan};
  ;}(require("lazyload"), require);
  