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

This commit is contained in:
Koushik Dutta
2022-11-22 09:24:12 -08:00
parent e10bae526c
commit 35d15d4f08
3 changed files with 13 additions and 4 deletions

View File

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

View File

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

View File

@@ -51,13 +51,22 @@ 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;