Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function registerDevice(freebird, dev, callback) {
var devId, oldDev;
if (!validate.isDevice(dev)) {
setImmediate(callback, new TypeError('Input dev is not a valid device instance'));
return freebird;
}
devId = dev.get('id');
oldDev = _.isNil(devId) ? undefined : freebird.findById('device', devId);
if (oldDev) {
setImmediate(callback, new Error('Device with id: ' + devId + ' already exists, unregister it first'));
return freebird;
}
if (dev._recovering) { // recovered from database (when at booting up or restarting stage)
freebird._devbox.set(devId, dev, function (err, id) {
if (!err)
dev._recovering = false;
callback(err, id);
});
} else {
dev._poke();
dev.set('net', {
rRpt.max = setInterval(() => {
rAttrs.mute = true
dumper((err, val) => {
if (err) console.warn(err)
rAttrs.mute = false
notifier.data = val
qn.notify(notifier, () => {})
})
if (!_.isNil(rRpt.min)) clearTimeout(rRpt.min)
rRpt.min = null
rRpt.min = setTimeout(() => {
if (pmin === 0) {
rAttrs.mute = false
} else {
dumper((err, val) => {
if (err) console.warn(err)
rAttrs.mute = false
notifier.data = val
qn.notify(notifier, () => {})
})
}
}, pmin)
}, pmax)
function invokeCb (qn, msg, status, data, cb) {
if (_.isFunction(cb)) {
process.nextTick(() => {
cb(status, data)
})
}
if (!_.isNil(data)) reporter.checkAndReportResource(qn, msg.oid, msg.iid, msg.rid, data)
}
function buildAttrsAndRsc(cn, ssid, oid, iid, rid) {
var attrs = cn._getAttrs(ssid, oid, iid, rid),
allowedAttrs = [ 'pmin', 'pmax', 'gt', 'lt', 'stp' ],
target = cn._target(oid, iid, rid),
value,
data;
if (!_.isNil(iid))
value = cn.getSmartObject().dumpSync(oid, iid);
else
value = cn.getSmartObject().dumpSync(oid);
data = cutils.encodeLinkFormat(target.pathKey, value, attrs);
return data;
}
delete this._maxListeners
Object.defineProperty(this, 'domain', _.assign({ value: _domain }, propWritable))
Object.defineProperty(this, '_events', _.assign({ value: __events }, propWritable))
Object.defineProperty(this, '_eventsCount', _.assign({ value: __eventsCount }, propWritable))
Object.defineProperty(this, '_maxListeners', _.assign({ value: __maxListeners }, propWritable))
/** ***************************************************************************************** */
if (arguments.length === 1 && _.isObject(name)) {
settings = name
name = null
}
settings = settings || {}
if (!_.isNil(name) && !_.isString(name)) throw new TypeError('name should be a string if gieven.')
else if (!_.isPlainObject(settings)) throw new TypeError('settings should be an object if gieven.')
/** ************************************************ */
/** * Prepare Shepherd Settings ** */
/** ************************************************ */
this.name = name || config.shepherdName
Object.defineProperty(this, 'clientId', _.assign({ value: this.name }, propWritable))
Object.defineProperty(this, 'brokerSettings', _.assign({ value: settings.broker || config.brokerSettings }, propWritable))
Object.defineProperty(this, 'defaultAccount', _.assign({ value: settings.account || config.defaultAccount }, propWritable))
this.clientConnOptions = settings.clientConnOptions || config.clientConnOptions
this.reqTimeout = settings.reqTimeout || config.reqTimeout
this.devIncomingAcceptanceTimeout = settings.devIncomingAcceptanceTimeout || config.devIncomingAcceptanceTimeout
/** ************************************************ */
/** * Protected Memebers ** */