Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// the first arument may be an object, if it is not, make an object
var opts;
if (is.obj(port)) {
opts = port;
} else {
opts = makeOptionsObj(port, host, inUse, retryTimeMs, timeOutMs);
}
//debug('opts:'+util.inspect(opts);
if (!is.bool(opts.inUse)) {
deferred.reject(new Error('inUse must be a boolean'));
return deferred.promise;
}
if (!is.positiveInt(opts.retryTimeMs)) {
opts.retryTimeMs = RETRYTIME;
debug('set retryTime to default '+RETRYTIME+'ms');
}
if (!is.positiveInt(opts.timeOutMs)) {
opts.timeOutMs = TIMEOUT;
debug('set timeOutMs to default '+TIMEOUT+'ms');
}
function cleanUp() {
if (timeoutId) {
clearTimeout(timeoutId);
}
if (retryId) {
clearTimeout(retryId);
}
Discovery.prototype.update = function(name, userData, interval, available) {
if (!is.nonEmptyStr(name)) {
debug('update error: missing name: '+inspect(name));
return false;
}
if (!userData) {
debug('update error: no userData: what is being announced?');
return false;
}
if (!is.positiveInt(interval)) interval = DEFAULT_INTERVAL;
if (!available) available = true;
// make a copy of the userData object
var userDataCopy = objToJson.copyObj(userData);
if (!userDataCopy) return false;
// attempt to add the announcement return result to user
return this.updateExisting(name, userDataCopy, interval, available);
};
opts = makeOptionsObj(port, host, inUse, retryTimeMs, timeOutMs);
}
//debug('opts:'+util.inspect(opts);
if (!is.bool(opts.inUse)) {
deferred.reject(new Error('inUse must be a boolean'));
return deferred.promise;
}
if (!is.positiveInt(opts.retryTimeMs)) {
opts.retryTimeMs = RETRYTIME;
debug('set retryTime to default '+RETRYTIME+'ms');
}
if (!is.positiveInt(opts.timeOutMs)) {
opts.timeOutMs = TIMEOUT;
debug('set timeOutMs to default '+TIMEOUT+'ms');
}
function cleanUp() {
if (timeoutId) {
clearTimeout(timeoutId);
}
if (retryId) {
clearTimeout(retryId);
}
}
function timeoutFunc() {
timedout = true;
cleanUp();