src.nth.io/

summaryrefslogtreecommitdiff
path: root/scrypted
diff options
context:
space:
mode:
authorLuke Hoersten <[email protected]>2026-06-14 19:21:07 -0500
committerLuke Hoersten <[email protected]>2026-06-14 19:21:07 -0500
commit6f79cfe533a6be154488ed61ab470712c10f06a3 (patch)
treec6ffd89c032d15f59fded7a24509bbbdeffa8865 /scrypted
parent56cbea1c5dcb068057ea2d32245eaed8a7100d39 (diff)
scrypted: discover device before writing its storage in createDevice
Diffstat (limited to 'scrypted')
-rw-r--r--scrypted/scrypted-viewport.ts26
1 files changed, 13 insertions, 13 deletions
diff --git a/scrypted/scrypted-viewport.ts b/scrypted/scrypted-viewport.ts
index 37879af..8f9d136 100644
--- a/scrypted/scrypted-viewport.ts
+++ b/scrypted/scrypted-viewport.ts
@@ -296,13 +296,10 @@ class ScryptedViewportProvider extends ScryptedDeviceBase
const name = String(settings.name || "viewport").trim();
const nativeId = `vp_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 6)}`;
- // Pre-populate the child's storage so its first registration uses
- // the form values rather than empty defaults.
- const childStore = deviceManager.getDeviceStorage(nativeId);
- childStore.setItem("host", String(settings.host || ""));
- childStore.setItem("cameraId", String(settings.cameraId || ""));
- childStore.setItem("orientation", String(settings.orientation || "portrait"));
-
+ // 1. Register the device with Scrypted FIRST. deviceManager
+ // materialises the storage container only after discovery —
+ // calling getDeviceStorage before this returns undefined and
+ // setItem() throws "Cannot read properties of undefined".
await deviceManager.onDeviceDiscovered({
providerNativeId: this.nativeId,
nativeId,
@@ -311,15 +308,18 @@ class ScryptedViewportProvider extends ScryptedDeviceBase
interfaces: [ScryptedInterface.Settings],
});
+ // 2. Now safe to seed the child's storage from the form values.
+ const childStore = deviceManager.getDeviceStorage(nativeId);
+ childStore.setItem("host", String(settings.host || ""));
+ childStore.setItem("cameraId", String(settings.cameraId || ""));
+ childStore.setItem("orientation", String(settings.orientation || "portrait"));
+
this.childIds = [...this.childIds, nativeId];
this.console.log(`created viewport "${name}" (${nativeId})`);
- // Fire-and-forget mDNS resolve so the host field is auto-populated
- // by the time the operator opens the new device's settings page.
- // getDevice() above already attempted a register; this catches the
- // case where the operator left host blank and mDNS resolution was
- // the only way to fill it.
- const child = this.viewports.get(nativeId);
+ // Kick off the first register cycle (mDNS resolve + POST /config).
+ // Fire-and-forget — the new device shows up immediately either way.
+ const child = await this.getDevice(nativeId);
if (child) this.registerViewport(child).catch(() => {});
return nativeId;