axis-discovery-bonjour
v3.0.0
Published
A Node.js Bonjour client library written in TypeScript capable of searching for Axis Communication cameras.
Downloads
371
Maintainers
Readme
axis-discovery-bonjour
A Node.js Bonjour client library written in TypeScript capable of searching for Axis Communication cameras.
To also find cameras on the network using SSDP (UPnP), please see axis-discovery.
Table of contents
Super simple to use
import * as bonjour from 'axis-discovery-bonjour';
const discovery = new bonjour.Discovery();
discovery.on('hello', (device: bonjour.Device) => {
console.log(`Hello from ${device.address}`);
});
discovery.on('goodbye', (device: bonjour.Device) => {
console.log(`Goodbye from ${device.address}`);
});
discovery.start();
discovery.search();
Installation
npm install axis-discovery-bonjour
# or
yarn add axis-discovery-bonjour
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 implements EventEmitter {
/**
* Start listen for device advertisements on all network interface
* addresses.
*/
start(): void;
/**
* Stop listening for device advertisements.
*/
stop(): void;
/**
* Triggers a new search for devices on the network.
*/
search(): 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 describing a device on the network.
*/
class Device {
/**
* Gets the address.
*/
readonly address: string;
/**
* Gets the link local address.
* For more information regarding link local addresses, please see
* [Wikipedia]{@link https://wikipedia.org/wiki/Link-local_address}.
*/
readonly linkLocalAddress: string;
/**
* Gets the port.
*/
readonly port: number;
/**
* 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;
/**
* Gets the short description for the end user.
*/
readonly friendlyName: string;
}