upnp-ts
TypeScript icon, indicating that this package has built-in type declarations

0.0.8 • Public • Published

UPNP TS

upnp-ts is a very basic upnp client for nodejs, written in typscript. It was written to manage port forwarding, but is generic enough you should be able to accomplish most client tasks.

the package webpacks cleanly, and has minimal dependencies. If using in nwjs or electron, keep in mind this will need to run on the nodejs thread.

Install

$ npm install upnp-ts --save

Usage

var upnp = require("upnp-ts");

let client = new upnp.Client();

//subscribe to debug messages
client.on('debug', (msg) => {
    console.warn('debug: ', msg);
});

//callback for once a device is found
client.onOneOf(['WANConnectionDevice', 'WANPPPConnection', 'LANDevice'], function( gateway ) {
    gateway.getService('WANIPConnection', function (service) {
        service.post('AddPortMapping', {
                NewRemoteHost: "",
                NewExternalPort: 8888,
                NewProtocol: 'TCP',
                NewInternalPort: 8888,
                NewInternalClient: d.network,
                NewEnabled: 1,
                NewPortMappingDescription: 'node:nat:upnp',
                NewLeaseDuration: 0
        }).then((portMapResponse) => {
                console.warn('port map response', portMapResponse);
        }).catch((err) => {
            console.warn('error mapping port', err);
        });
    }
});

//send out a discovery request;
client.search( 'urn:schemas-upnp-org:device:InternetGatewayDevice:1' );

Dependencies (4)

Dev Dependencies (3)

Package Sidebar

Install

npm i upnp-ts

Weekly Downloads

0

Version

0.0.8

License

ISC

Last publish

Collaborators

  • dthompso99