Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

axis-discovery-ssdp

FantasticFiasco142Apache-2.08.0.1TypeScript support: included

A Node.js SSDP (UPnP) client library written in TypeScript capable of searching for Axis Communication cameras.

axis, communications, camera, device, discovery, ssdp, upnp

readme

axis-discovery-ssdp

axis-discovery-ssdp npm version SemVer compatible

A Node.js SSDP (UPnP) client library written in TypeScript capable of searching for Axis Communication cameras.

To also find cameras on the network using Bonjour, please see axis-discovery.

Table of contents


Super simple to use

import * as ssdp from 'axis-discovery-ssdp';

const discovery = new ssdp.Discovery();

discovery.on('hello', (device: ssdp.Device) => {
    console.log(`Hello from ${device.address}`);
});

discovery.on('goodbye', (device: ssdp.Device) => {
    console.log(`Goodbye from ${device.address}`);
});

await discovery.start();
await discovery.search();

Installation

npm install axis-discovery-ssdp
# or
yarn add axis-discovery-ssdp

Who is using it?

The application Searchlight is depending on this package to find Axis cameras on the network using SSDP. Download and give it a spin!

API

Discovery

The Discovery class is the main class in the package. With it you can register for changes to cameras on the network and respond accordingly when a camera is found on, or intentionally disconnects from, the network.

class Discovery {
    /**
     * Initializes a new instance of the class.
     * @param options The SSDP discovery options.
     */
    constructor(options?: IOptions);

    /**
     * Start listen for device advertisements on all network interface
     * addresses.
     */
    start(): Promise<void>;

    /**
     * Stop listening for device advertisements.
     */
    stop(): Promise<void>;

    /**
     * Triggers a new search for devices on the network.
     */
    search(): Promise<void>;

    /**
     * Adds the listener function to the end of the listeners array for the event named eventName.
     * No checks are made to see if the listener has already been added. Multiple calls passing the
     * same combination of eventName and listener will result in the listener being added, and
     * called, multiple times.
     * @param eventName The name of the event.
     * @param listener The callback function.
     */
    on(eventName: 'hello' | 'goodbye', listener: (device: Device) => void): this;

    // The remaining implementation of EventEmitter has been removed for brevity
}

Device

The Device class is a immutable description of a camera on the network.

class Device {
    /**
     * Gets the address.
     */
    readonly address: string;

    /**
     * Gets the port.
     */
    readonly port: number | undefined;

    /**
     * Gets the MAC address. In most situations this is identical to the
     * serial number. The exceptions are the Axis products which bundle
     * multiple physical devices into a single casing with a shared network
     * interface. Because of the shared network interface they also share
     * the same MAC address.
     */
    readonly macAddress: string | undefined;

    /**
     * Gets the short description for the end user.
     */
    readonly friendlyName: string | undefined;

    /**
     * Gets the model name.
     */
    readonly modelName: string | undefined;

    /**
     * Gets the long model description for the end user.
     */
    readonly modelDescription: string | undefined;

    /**
     * Gets the model number.
     */
    readonly modelNumber: string | undefined;

    /**
     * Gets the URL to the web page of the device.
     */
    readonly presentationURL: string | undefined;
}

Options

The Options class can be specified to configure SSDP discovery.

/**
 * The SSDP discovery options.
 */
export interface IOptions {
    /**
     * An implementation of a HTTP client. Default value is based
     * on <a href="https://www.npmjs.com/package/request">Request</a> but a
     * custom implementation can be provided. This can be useful if discovery
     * is required in an Electron application where one wish to benefit from
     * the proxy configuration provided by using Electron's
     * <a href="https://electronjs.org/docs/api/net">net.request</a>.
     */
    httpClient?: IHttpClient;
}

/**
 * Interface responsible for HTTP communication on the network.
 */
export interface IHttpClient {
    /**
     * Send GET request over the network.
     * @param url Fully qualified URL.
     * @returns Promise with response body.
     */
    get(url: string): Promise<string>;
}

changelog

Change Log

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

[Unreleased]

[8.0.1] - 2023-04-16

:policeman: Security

  • Security vulnerability in transient dependency http-cache-semantics
  • Security vulnerability in transient dependency xml2js

[8.0.0] - 2023-01-08

:syringe: Changed

  • [BREAKING CHANGE] Deprecate Node.js 15 and below

:policeman: Security

  • Security vulnerability in transient dependency json5
  • Security vulnerability in transient dependency minimatch
  • Security vulnerability in transient dependency qs

[7.0.0] - 2021-06-15

:policeman: Security

  • Security vulnerability in transient dependency normalize-url

:dizzy: Changed

  • [BREAKING CHANGE] Deprecate Node.js 13 and below

[6.0.1] - 2021-01-10

:policeman: Security

[6.0.0] - 2020-10-11

:dizzy: Changed

  • [BREAKING CHANGE] Renamed method Discovery.onHello(callback: (device: Device) => void) to Discovery.on("hello", (device: Device) => void)
  • [BREAKING CHANGE] Renamed method Discovery.onGoodbye(callback: (device: Device) => void) to Discovery.on("goodbye", (device: Device) => void)

:zap: Added

  • Class Discovery implements EventEmitter

[5.0.6] - 2020-03-09

:syringe: Fixed

  • Add membership to port 1900 might throw error if already in use by another process

[5.0.5] - 2019-12-27

:policeman: Security

  • Security vulnerability in transient dependency handlebars

[5.0.4] - 2019-07-14

:policeman: Security

  • Security vulnerability in transient dependency diff
  • Security vulnerability in transient dependency lodash

[5.0.3] - 2019-06-07

:policeman: Security

  • Security vulnerability in transient dependency handlebars
  • Security vulnerability in transient dependency js-yaml

[5.0.2] - 2019-03-09

:policeman: Security

  • Security vulnerability in transient dependency sshpk

[5.0.1] - 2019-01-07

:syringe: Fixed

  • Update dependencies

[5.0.0] - 2017-12-22

:dizzy: Changed

  • The property macAddress on Device changed type from string | undefined to string. Devices without a MAC address are now omitted from search results.

[4.1.0] - 2017-11-27

:zap: Added

  • The option to specify a custom implementation of a HTTP client, where the default is based on Request. This can be useful if discovery is required in an Electron application where one wish to benefit from the proxy configuration provided by using Electron's net.request.

[4.0.2] - 2017-10-14

:syringe: Fixed

  • Issue where exception was thrown when received message didn't specify MAC address

[4.0.1] - 2017-07-06

:syringe: Fixed

  • Issue where socket listeners remained alive when discovery was stopped

[4.0.0] - 2017-07-04

:zap: Added

  • Support for enabling logs using debug

:skull: Removed

  • Support for Node.js v5 (v6 is LTS)

[3.0.0] - 2017-06-26

:dizzy: Changed

  • Renamed Device.serialNumber to Device.macAddress. In most situations they are still the same, but the exceptions are the Axis products which bundle multiple physical devices into a single casing with a shared network interface. Because of the shared network interface they also share the same MAC address. This package is opinionated in that even though the devices via SSDP (UPnP) call the property serial number, it actually is a MAC address and should be named accordingly.

[2.0.0] - 2017-06-24

:zap: Added

  • #2 - Calling Discovery.stop() stops listening for SSDP advertisements

:dizzy: Changed

[1.0.2] - 2017-01-26

:syringe: Fixed

  • #40 - Calling Discovery.search() didn't trigger a new search

[1.0.1] - 2016-12-06

:syringe: Fixed

  • Updated README.md in package

[1.0.0] - 2016-12-04

:zap: Added