in thing/index.js [616:661]
this.unregister = function(thingName) {
if (thingShadows.hasOwnProperty(thingName)) {
var topicSpecs = [];
//
// If an operation is outstanding, it will have a timeout set; when it
// expires any accept/reject sub-topic subscriptions for the thing will be
// deleted. If any messages arrive after the thing has been deleted, they
// will simply be ignored as it no longer exists in the thing registrations.
// The only sub-topic we need to unsubscribe from is the delta sub-topic,
// which is always active.
//
topicSpecs.push({
operations: ['update'],
statii: ['delta']
});
//
// If we are persistently subscribing, we subscribe to everything we could ever
// possibly be interested in; this means that when it's time to unregister
// interest in a thing, we need to unsubscribe from all of these topics.
//
if (thingShadows[thingName].persistentSubscribe === true) {
topicSpecs.push({
operations: ['update', 'get', 'delete'],
statii: ['accepted', 'rejected']
});
}
this._handleSubscriptions(thingName, topicSpecs, 'unsubscribe');
//
// Delete any pending timeout
//
if (!isUndefined(thingShadows[thingName].timeout)) {
clearTimeout(thingShadows[thingName].timeout);
}
//
// Delete the thing from the Thing registrations.
//
delete thingShadows[thingName];
} else {
if (deviceOptions.debug === true) {
console.error('attempting to unregister unknown thing: ', thingName);
}
}
};