webhook: fix mixin late init

This commit is contained in:
Koushik Dutta
2021-11-06 13:56:15 -07:00
parent 11545a34bb
commit c195f48322
3 changed files with 8 additions and 5 deletions

View File

@@ -1,12 +1,12 @@
{
"name": "@scrypted/webhook",
"version": "0.0.9",
"version": "0.0.10",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@scrypted/webhook",
"version": "0.0.9",
"version": "0.0.10",
"dependencies": {
"@types/node": "^16.6.1"
},

View File

@@ -33,5 +33,5 @@
"devDependencies": {
"@scrypted/sdk": "file:../../sdk"
},
"version": "0.0.9"
"version": "0.0.10"
}

View File

@@ -80,7 +80,7 @@ class WebhookMixin extends SettingsMixinDeviceBase<Settings> {
async maybeSendMediaObject(response: HttpResponse, value: any, method: string) {
if (!mediaObjectMethods.includes(method)) {
response?.send(value.toString());
response?.send(value?.toString());
return;
}
@@ -149,7 +149,7 @@ class WebhookPlugin extends ScryptedDeviceBase implements Settings, MixinProvide
const pathSegments = relPath.split('/');
const id = pathSegments[1];
const device = systemManager.getDeviceById<ScryptedDevice>(id);
const device = systemManager.getDeviceById<ScryptedDevice & Settings>(id);
this.console.log('device', id, device.name);
if (!device.mixins.includes(this.id)) {
@@ -160,6 +160,9 @@ class WebhookPlugin extends ScryptedDeviceBase implements Settings, MixinProvide
return;
}
if (!this.createdMixins.has(id)) {
await device.getSettings();
}
const mixin = this.createdMixins.get(id);
mixin.handle(request, response, device, pathSegments);
}