in source/console/src/app/secure/child-views/devices/default-device/default-device.component.ts [34:96]
ngOnInit() {
const self = this;
function defaultErrorCallback(err) {
console.error('Error:', err);
}
self.appSyncService
.getDeviceBlueprint(self.device.deviceBlueprintId)
.then((deviceBlueprint: DeviceBlueprint) => {
if (deviceBlueprint && deviceBlueprint.spec.hasOwnProperty('View')) {
self.parent = self;
self.iotService
.getThingShadow({
thingName: self.device.thingName
})
.then((shadow: any) => {
self.shadow = shadow;
const widgetSubscriptions = [];
const view = JSON.parse(
JSON.stringify(deviceBlueprint.spec.View)
.split('[CORE]')
.join(self.device.thingName)
.split('[THING_NAME]')
.join(self.device.thingName)
.split('[DEVICE_NAME]')
.join(self.device.name)
);
if (view.hasOwnProperty('subscriptions')) {
const subs = view.subscriptions;
for (let ref in subs) {
if (subs.hasOwnProperty(ref)) {
const topic = subs[ref];
// console.log('Subscription:', ref, topic);
self.widgetSubscriptionSubjects[ref] = new Subject<any>();
self.widgetSubscriptionObservable$[ref] = self.widgetSubscriptionSubjects[
ref
].asObservable();
widgetSubscriptions.push({
topic: topic,
onMessage: message => {
// console.log('onMessage:', topic, message);
self.widgetSubscriptionSubjects[ref].next(message.value);
},
onError: defaultErrorCallback
});
}
}
}
self.subscribe(widgetSubscriptions);
if (view.hasOwnProperty('widgets')) {
self.widgets = view.widgets;
}
});
}
})
.catch(defaultErrorCallback);
}