{"version":3,"sources":["jsdelivr-header.js","/npm/connectivity-events@1.0.3/index.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,ACNA,MAAM,GAAK,QAAQ,OACb,aAAE,cAAiB,QAAQ,UAE3B,SAAW,IAEjB,MAAM,4BAA4B,aAChC,WAAA,CAAa,EAAO,CAAC,GACnB,QAEA,KAAK,UAAY,EAAK,UANT,IAOb,KAAK,UAAY,EACjB,KAAK,WAAa,GAElB,KAAK,OAAS,aAAY,KACxB,MAAM,EAAc,KAAK,MACnB,EAAe,WAGrB,GADoB,EAAc,KAAK,UAAa,IAIlD,OAFA,KAAK,UAAY,OACjB,KAAK,WAAa,KAIM,WAAW,EAAc,KAAK,aAClC,KAAK,KAAK,UAEhC,KAAK,UAAY,EACjB,KAAK,WAAa,IACjB,KAAK,YACa,IAAjB,EAAK,SAAkB,KAAK,OAAO,OACzC,CAEA,OAAA,GACM,KAAK,QAAQ,cAAc,KAAK,QACpC,KAAK,OAAS,IAChB,EAKF,SAAS,WACP,MAAM,EAAM,GACN,EAAQ,GAAG,oBACjB,IAAK,MAAM,KAAQ,OAAO,KAAK,GAC7B,IAAK,MAAM,KAAK,EAAM,GACf,EAAE,UAAU,EAAI,KAAK,EAAE,MAGhC,OAAO,CACT,CAEA,SAAS,WAAY,EAAG,GACtB,GAAI,EAAE,SAAW,EAAE,OAAQ,OAAO,EAClC,IAAK,IAAI,EAAI,EAAG,EAAI,EAAE,OAAQ,IAC5B,GAAI,EAAE,KAAO,EAAE,GAAI,OAAO,EAE5B,OAAO,CACT,CAEA,GArBA,OAAO,QAAU,oBAqBb,QAAQ,OAAS,OAAQ,CAC3B,MAAM,EAAU,IAAI,oBAAoB,CAAE,SAAU,IAAM,SAAS,IACnE,EAAQ,GAAG,UAAU,KAAQ,QAAQ,IAAI,uBAAsB,IAC/D,QAAQ,GAAG,UAAU,IAAM,EAAQ,WACrC","file":"/npm/connectivity-events@1.0.3/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/connectivity-events@1.0.3/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const os = require('os')\nconst { EventEmitter } = require('events')\n\nconst INTERVAL = 1000 * 10\n\nclass ConnectivityMonitor extends EventEmitter {\n  constructor (opts = {}) {\n    super()\n\n    this._interval = opts.interval || INTERVAL\n    this._lastPoll = 0\n    this._lastState = []\n\n    this._timer = setInterval(() => {\n      const currentTime = Date.now()\n      const currentState = getCidrs()\n\n      const isWakingUp = (currentTime - this._lastPoll) > INTERVAL * 2\n      if (isWakingUp) {\n        this._lastPoll = currentTime\n        this._lastState = []\n        return\n      }\n\n      const isDifferentState = !equalArray(currentState, this._lastState)\n      if (isDifferentState) this.emit('change')\n\n      this._lastPoll = currentTime\n      this._lastState = currentState\n    }, this._interval)\n    if (opts.noUnref !== true) this._timer.unref()\n  }\n  \n  destroy () {\n    if (this._timer) clearInterval(this._timer)\n    this._timer = null\n  }\n}\n\nmodule.exports = ConnectivityMonitor\n\nfunction getCidrs () {\n  const all = []\n  const faces = os.networkInterfaces()\n  for (const name of Object.keys(faces)) {\n    for (const i of faces[name]) {\n      if (!i.internal) all.push(i.cidr)\n    }\n  }\n  return all\n}\n\nfunction equalArray (a, b) {\n  if (a.length !== b.length) return false\n  for (let i = 0; i < a.length; i++) {\n    if (a[i] !== b[i]) return false\n  }\n  return true\n}\n\nif (require.main === module) {\n  const monitor = new ConnectivityMonitor({ interval: 1000, noUnref: true })\n  monitor.on('change', () => { console.log('connectivity changed') })\n  process.on('SIGINT', () => monitor.destroy())\n}\n"]}