in jobs/index.js [206:245]
this.subscribeToJobs = function(thingName, operationName, callback) {
// Check for omitted optional operationName and fixup parameters
if (isUndefined(callback)) {
callback = operationName;
operationName = null;
}
if ((!isUndefined(options)) && (options.debug === true)) {
console.log('subscribeToJobs:', { thingName: thingName, operationName: operationName });
}
var thing = jobSubscriptions.find(function(elem) {
return elem.thingName === thingName;
});
// Check for previously unseen thing and add to job subscriptions
if (isUndefined(thing)) {
thing = { thingName: thingName, operations: [] };
jobSubscriptions.push(thing);
device.subscribe([ buildJobTopic(thingName, '$next/get/accepted'), buildJobTopic(thingName, 'notify-next') ], function(err, granted) {
if (!isUndefined(err)) {
callback(err);
}
});
}
// Find existing subscription for the given operationName
var operation = thing.operations.find(function(elem) {
return (isUndefined(operationName) ? isUndefined(elem.operationName) : operationName === elem.operationName);
});
// If existing subscription found then update callback, otherwise create new entry in the thing's operations array
if (!isUndefined(operation)) {
operation.callback = callback;
} else {
operation = { operationName: operationName, callback: callback };
thing.operations.push(operation);
}
}