server: improve fix mixin table not sending final state update when complete

This commit is contained in:
Koushik Dutta
2022-11-22 09:34:44 -08:00
parent 2df8907262
commit 49e3da58ef
4 changed files with 9 additions and 16 deletions

View File

@@ -1,12 +1,12 @@
{
"name": "@scrypted/server",
"version": "0.3.10",
"version": "0.4.1",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@scrypted/server",
"version": "0.3.10",
"version": "0.4.1",
"license": "ISC",
"dependencies": {
"@ffmpeg-installer/ffmpeg": "^1.1.0",

View File

@@ -1,6 +1,6 @@
{
"name": "@scrypted/server",
"version": "0.3.10",
"version": "0.4.1",
"description": "",
"dependencies": {
"@ffmpeg-installer/ffmpeg": "^1.1.0",

View File

@@ -51,22 +51,13 @@ export class PluginComponent {
throw new Error(message);
}
const pluginDevice = this.scrypted.findPluginDeviceById(id);
// immediately remove the mixin and save this state,
// but hold off on generating the new descriptor until
// the new table is finished.
this.scrypted.stateManager.setPluginDeviceState(pluginDevice, ScryptedInterfaceProperty.mixins, [...new Set(mixins)]);
this.scrypted.stateManager.updateDescriptor(pluginDevice);
await this.scrypted.datastore.upsert(pluginDevice);
// device may not exist, so force creation.
this.scrypted.rebuildPluginDeviceMixinTable(id);
this.scrypted.getDevice(id);
await this.scrypted.devices[id]?.handler?.ensureProxy();
// after the mixin table is generated, report/persist the final device descriptor
const promises = this.scrypted.devices[id]?.handler?.mixinTable?.map(e => e.entry);
await Promise.allSettled(promises);
this.scrypted.stateManager.updateDescriptor(pluginDevice);
await this.scrypted.datastore.upsert(pluginDevice);
}
async getIdForPluginId(pluginId: string) {
return this.scrypted.findPluginDevice(pluginId)?._id;

View File

@@ -46,12 +46,14 @@ export class ScryptedStateManager extends EventRegistry {
if (!eventInterface)
throw new Error(`${property} is not a valid property`);
const changed = setState(device, property, value) && eventInterface !== ScryptedInterface.ScryptedDevice;
const changed = setState(device, property, value);
const eventTime = device?.state?.[property]?.lastEventTime;
if (this.notify(device?._id, eventTime, eventInterface, property, value, changed) && device) {
this.scrypted.getDeviceLogger(device).log('i', `state change: ${property} ${value}`);
if (eventInterface !== ScryptedInterface.ScryptedDevice) {
if (this.notify(device?._id, eventTime, eventInterface, property, value, changed) && device) {
this.scrypted.getDeviceLogger(device).log('i', `state change: ${property} ${value}`);
}
}
this.upserts.add(device._id);