UNPKG

5.2 kBMarkdownView Raw
1# axis-discovery-ssdp
2
3[![Build Status](https://travis-ci.org/FantasticFiasco/axis-discovery-ssdp.svg?branch=master)](https://travis-ci.org/FantasticFiasco/axis-discovery-ssdp)
4[![Coverage Status](https://coveralls.io/repos/github/FantasticFiasco/axis-discovery-ssdp/badge.svg)](https://coveralls.io/github/FantasticFiasco/axis-discovery-ssdp)
5[![npm version](https://img.shields.io/npm/v/axis-discovery-ssdp.svg)](https://www.npmjs.com/package/axis-discovery-ssdp)
6[![Greenkeeper badge](https://badges.greenkeeper.io/FantasticFiasco/axis-discovery-ssdp.svg)](https://greenkeeper.io/)
7[![dependencies Status](https://david-dm.org/FantasticFiasco/axis-discovery-ssdp/status.svg)](https://david-dm.org/FantasticFiasco/axis-discovery-ssdp)
8[![devDependencies Status](https://david-dm.org/FantasticFiasco/axis-discovery-ssdp/dev-status.svg)](https://david-dm.org/FantasticFiasco/axis-discovery-ssdp?type=dev)
9
10A Node.js SSDP (UPnP) client library written in TypeScript capable of searching for [Axis Communication](http://www.axis.com) cameras.
11
12To also find cameras on the network using Bonjour, please see [axis-discovery](https://github.com/FantasticFiasco/axis-discovery).
13
14## Table of contents
15
16- [Super simple to use](#super-simple-to-use)
17- [Installation](#installation)
18- [API](#api)
19- [Credit](#credit)
20
21---
22
23## Super simple to use
24
25```javascript
26import * as ssdp from 'axis-discovery-ssdp';
27
28const discovery = new ssdp.Discovery();
29
30discovery.onHello((device: ssdp.Device) => {
31 console.log(`Hello from ${device.address}`);
32});
33
34discovery.onGoodbye((device: ssdp.Device) => {
35 console.log(`Goodbye from ${device.address}`);
36});
37
38await discovery.start();
39await discovery.search();
40```
41
42## Installation
43
44```sh
45npm install axis-discovery-ssdp
46```
47
48## API
49
50### `Discovery`
51
52The `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.
53
54```javascript
55class Discovery {
56 /**
57 * Initializes a new instance of the class.
58 * @param options The SSDP discovery options.
59 */
60 constructor(options?: IOptions);
61
62 /**
63 * Start listen for device advertisements on all network interface
64 * addresses.
65 */
66 start(): Promise<void>;
67
68 /**
69 * Stop listening for device advertisements.
70 */
71 stop(): Promise<void>;
72
73 /**
74 * Triggers a new search for devices on the network.
75 */
76 search(): Promise<void>;
77
78 /**
79 * Register a callback that is invoked when a device is found on the
80 * network.
81 */
82 onHello(callback: (device: Device) => void): void;
83
84 /**
85 * Register a callback that is invoked when a device intentionally is
86 * disconnecting from the network.
87 */
88 onGoodbye(callback: (device: Device) => void): void;
89}
90```
91
92### `Device`
93
94The `Device` class is a immutable description of a camera on the network.
95
96```javascript
97class Device {
98 /**
99 * Gets the address.
100 */
101 readonly address: string;
102
103 /**
104 * Gets the port.
105 */
106 readonly port: number | undefined;
107
108 /**
109 * Gets the MAC address. In most situations this is identical to the
110 * serial number. The exceptions are the Axis products which bundle
111 * multiple physical devices into a single casing with a shared network
112 * interface. Because of the shared network interface they also share
113 * the same MAC address.
114 */
115 readonly macAddress: string | undefined;
116
117 /**
118 * Gets the short description for the end user.
119 */
120 readonly friendlyName: string | undefined;
121
122 /**
123 * Gets the model name.
124 */
125 readonly modelName: string | undefined;
126
127 /**
128 * Gets the long model description for the end user.
129 */
130 readonly modelDescription: string | undefined;
131
132 /**
133 * Gets the model number.
134 */
135 readonly modelNumber: string | undefined;
136
137 /**
138 * Gets the URL to the web page of the device.
139 */
140 readonly presentationURL: string | undefined;
141}
142```
143
144### `Options`
145
146The `Options` class can be specified to configure SSDP discovery.
147
148```javascript
149/**
150 * The SSDP discovery options.
151 */
152export interface IOptions {
153 /**
154 * An implementation of a HTTP client. Default value is based
155 * on <a href="https://www.npmjs.com/package/request">Request</a> but a
156 * custom implementation can be provided. This can be useful if discovery
157 * is required in an Electron application where one wish to benefit from
158 * the proxy configuration provided by using Electron's
159 * <a href="https://electronjs.org/docs/api/net">net.request</a>.
160 */
161 httpClient?: IHttpClient;
162}
163
164/**
165 * Interface responsible for HTTP communication on the network.
166 */
167export interface IHttpClient {
168 /**
169 * Send GET request over the network.
170 * @param url Fully qualified URL.
171 * @returns Promise with response body.
172 */
173 get(url: string): Promise<string>;
174}
175```
176
177## Credit
178
179Thank you [JetBrains](https://www.jetbrains.com/) for your important initiative to support the open source community with free licenses to your products.
180
181![JetBrains](./design/jetbrains.png)