MCPcopy
hub / github.com/agalwood/Motrix / watchUPnPPortsChange

Method watchUPnPPortsChange

src/main/Application.js:349–372  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

347 }
348
349 watchUPnPPortsChange () {
350 const { systemConfig } = this.configManager
351 const watchKeys = ['listen-port', 'dht-listen-port']
352
353 watchKeys.forEach((key) => {
354 this.configListeners[key] = systemConfig.onDidChange(key, async (newValue, oldValue) => {
355 logger.info('[Motrix] detected port change event:', key, newValue, oldValue)
356 const enable = this.configManager.getUserConfig('enable-upnp')
357 if (!enable) {
358 return
359 }
360
361 const promises = [
362 this.upnp.unmap(oldValue),
363 this.upnp.map(newValue)
364 ]
365 try {
366 await Promise.allSettled(promises)
367 } catch (e) {
368 logger.info('[Motrix] change UPnP port mapping failed:', e)
369 }
370 })
371 })
372 }
373
374 watchUPnPEnabledChange () {
375 const { userConfig } = this.configManager

Callers 1

initUPnPManagerMethod · 0.95

Calls 3

getUserConfigMethod · 0.80
unmapMethod · 0.80
mapMethod · 0.80

Tested by

no test coverage detected