Skip to content

Commit

Permalink
Add the possibility to bind an address on Discovery instead of a devi…
Browse files Browse the repository at this point in the history
…ce, in case a device has multiple aliases.

Because of binding and because the urn is set in discovery.js, urn is important so...
Add line 'this.urn = options.urn' removed on a previous commit.
Because of binding, we need to know which alias received the camera, so we now send a remote and local info in Discovery.emit('device').
  • Loading branch information
Jessy committed Feb 19, 2020
1 parent fb421bd commit 256e82f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/cam.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ var Cam = function(options, callback) {
this.hostname = options.hostname;
this.username = options.username;
this.password = options.password;
this.urn = options.urn;
this.port = options.port || 80;
this.path = options.path || '/onvif/device_service';
this.timeout = options.timeout || 120000;
this.agent = options.agent || false;
this.localAddress = options.localAddress;
/**
* Force using hostname and port from constructor for the services
* @type {boolean}
Expand Down Expand Up @@ -193,6 +195,7 @@ Cam.prototype._request = function(options, callback) {
};

reqOptions.method = 'POST';
reqOptions.localAddress = this.localAddress;
var req = http.request(reqOptions, function(res) {
var bufs = [], length = 0;
res.on('data', function(chunk) {
Expand Down
6 changes: 4 additions & 2 deletions lib/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,16 @@ Discovery.probe = function(options, callback) {
* @event Discovery#device
* @type {Cam|object}
*/
Discovery.emit('device', cam, rinfo, xml);
Discovery.emit('device', cam, {remote: rinfo, local: socket.address()}, xml);
}
}
});
};

// If device is specified try to bind to that interface
if (options.device) {
if (options.bindAddress) {
socket.bind(null,options.bindAddress);
} else if (options.device) {
var interfaces = os.networkInterfaces();
// Try to find the interface based on the device name
if (options.device in interfaces) {
Expand Down

0 comments on commit 256e82f

Please sign in to comment.