Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

UPnP Client Library for NodeJS. Aims to support as many device specifications as possible...

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 examples
Octocat-spinner-32 lib
Octocat-spinner-32 README.md
Octocat-spinner-32 package.json
README.md

node-upnp-client

UPnP "Control Point" Library for NodeJS.

A module for NodeJS written in JavaScript to interface with UPnP compliant devices.

The entire range of UPnP devices aims to be supported through contributors. Currently implemented specifications are:

  • InternetGatewayDevice:1
    • WANDevice:1
      • WANIPConnection:1

Usage

This module is still alpha quality, and it's API is a work-in-progress and subject to change!

Discovery

Discovering UPnP compliant devices on the network is usually the first step in anything UPnP-related:

var upnp = require("upnp");

var controlPoint = new upnp.ControlPoint();
controlPoint.on("deviceAdded", function(err, device) {
  console.log(device.deviceType);
    //-> "urn:schemas-upnp-org:device:InternetGatewayDevice:1"
  console.log(device.location);
    //-> "http://192.168.0.1/root.sxml"
});

Description

Once a device is "discovered", there's still not very much known about the device other than it's root device type. The loadDescription function needs to be called on a "device" object to determine which services, child devices, events, etc. the device implements. The prototype of the device object gets extended to reflect the parsed description of the device:

device.loadDescription(function(err) {
  console.log(device);
  // 'device' is now populated with a lot more properties
});

Control

Invoking the services that a device exposes is probably your primary concern with interacting with a UPnP device. GetExternalIPAddress is an example of an action exposed from a WANIPConnection service:

device.GetExternalIPAddress(function(err, ip) {
  console.log(ip);
    //-> "1.1.1.1"
});

Event Notification

Individual device "service"s often emit their own events when certain properties of the device change. Use the notification event of Device or Service instances to invoke a callback whenever a notification is emitter from the device:

device.on("notification", function(properties) {
  for (var i in properties) {
    console.log(i + ": " + properties[i]);
  }
});
Something went wrong with that request. Please try again.