Files
2025-01-04 00:34:03 +01:00

1 line
793 B
JavaScript

import natupnp from"nat-upnp";export default class UPnP{constructor({port:t=3e4,ttl:e}={}){this.port=t,this.ttl=e||600}client=natupnp.createClient();#t;createMapping(){global.logger.info(`Requesting UPnP port forwarding to destination port ${this.port}`);try{this.#e()}catch(t){return t.message=`Failed to created requested UPnP mapping: ${t.message}`,global.logger.error(t),null}return this.#t=setInterval(this.#e.bind(this),1e3*this.ttl/2),this}#e(){config.options?.debug&&global.logger.debug(`Renewing UPnP port forwarding lease to destination port ${this.port}`),this.client.portMapping({public:this.port,private:this.port,ttl:this.ttl,description:"Foundry Virtual Tabletop"})}removeMapping(){this.#t&&(clearInterval(this.#t),this.#t=void 0),this.client.portUnmapping({public:this.port})}}