Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the possibility to bind an address on Discovery instead of a device #139

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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