From cfb84b707ad7cedd1633ccd5e241ad03ea046797 Mon Sep 17 00:00:00 2001 From: donhk Date: Sun, 26 Jan 2020 17:45:34 -0600 Subject: [PATCH] improved devices discovery by allowing to specify a custom address where to bind the socket, also added an option to specify the port to be used for the binding --- lib/node-onvif.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/node-onvif.js b/lib/node-onvif.js index 48b593d..95f8b16 100644 --- a/lib/node-onvif.js +++ b/lib/node-onvif.js @@ -52,9 +52,20 @@ Onvif.prototype.startDiscovery = function(callback) { }; /* ------------------------------------------------------------------ -* Method: startProbe([callback]) +* Method: startProbe([params,][callback]) * ---------------------------------------------------------------- */ -Onvif.prototype.startProbe = function(callback) { +Onvif.prototype.startProbe = function(params, callback) { + params = params || {}; + if (typeof (params['bind_address']) === 'string') { + this._BIND_ADDRESS = params['bind_address']; + } else { + this._BIND_ADDRESS = '0.0.0.0'; + } + if (typeof (params['bind_port']) === 'number') { + this._BIND_PORT = params['bind_port']; + } else { + this._BIND_PORT = 0; + } let promise = new Promise((resolve, reject) => { this._devices = {}; this._udp = mDgram.createSocket('udp4'); @@ -125,7 +136,7 @@ Onvif.prototype.startProbe = function(callback) { }); }); - this._udp.bind(() => { + this._udp.bind(this._BIND_PORT, this._BIND_ADDRESS, () => { this._udp.removeAllListeners('error'); this._sendProbe().then(() => { // Do nothing.