import NatAPI from"@silentbot1/nat-api";export default class UPnP{constructor({port:t=3e4,ttl:e}={}){this.port=t,this.ttl=e||600}#t;#e=null;async createMapping(){global.logger.info(`Requesting UPnP port forwarding to destination port ${this.port}`),this.#t||=new NatAPI({ttl:this.ttl,description:"Foundry Virtual Tabletop",autoUpdate:!1,enablePMP:!0});try{return await this.#t.map({publicPort:this.port,privatePort:this.port,ttl:this.ttl,protocol:"TCP"}),this.#e||=setInterval(this.#r.bind(this),1e3*this.ttl/2),this}catch(t){t.message=`Failed to create requested UPnP mapping: ${t.message}`,global.logger.error(t)}return null}async#r(){try{await this.#t.map({publicPort:this.port,privatePort:this.port,ttl:this.ttl,protocol:"TCP"})}catch(t){t.message=`Failed to refresh UPnP mapping: ${t.message}`,global.logger.error(t)}}removeMapping(){this.#e&&(clearInterval(this.#e),this.#e=null),this.#t?.destroy().catch(t=>global.logger.error(t)),this.#t=void 0}}