diff options
| author | Luke Hoersten <[email protected]> | 2026-06-14 18:46:40 -0500 |
|---|---|---|
| committer | Luke Hoersten <[email protected]> | 2026-06-14 18:46:40 -0500 |
| commit | 03cf7001bad0e34f065747434f801d19f59b9497 (patch) | |
| tree | e8a87a65ab43a58c244171e3352ed52a7c1df0c6 /scrypted/scrypted-viewport.ts | |
| parent | 731040bcf844c4ad88dca1ada2f84c2e400d3c87 (diff) | |
scrypted: declare runtime SDK names directly as globals
The scryptedEval sandbox pre-injects SDK names (ScryptedDeviceBase,
ScryptedDeviceType, ScryptedInterface, systemManager, deviceManager,
mediaManager, endpointManager, log, device, sdk, require) into the
script's scope. The previous attempt destructured them from `sdk`,
but on user's Scrypted 0.143.0 / @scrypted/core 0.3.147 something in
the compile pipeline was still emitting a `require('@scrypted/sdk')`
that failed to resolve.
Switch to `declare const <name>: any` for each runtime value — the
declarations fully erase at compile time, no require is emitted, and
the values come straight from the sandbox scope.
Diffstat (limited to 'scrypted/scrypted-viewport.ts')
| -rw-r--r-- | scrypted/scrypted-viewport.ts | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/scrypted/scrypted-viewport.ts b/scrypted/scrypted-viewport.ts index c23dbce..37879af 100644 --- a/scrypted/scrypted-viewport.ts +++ b/scrypted/scrypted-viewport.ts @@ -34,31 +34,29 @@ // - Camera must respect picture.width/height OR be paired with a snapshot // plugin that resizes. Otherwise /frame returns 400. -// The Scripts plugin (in @scrypted/core) evaluates this file inside a -// sandbox that does NOT resolve ESM `import` of npm modules — it injects -// `sdk` as a global and lets you `require()` Node built-ins. So we: -// - destructure runtime values from the injected `sdk` global -// - require('dns') for the Node mDNS lookup -// Type aliases below are declared loosely as `any` so the script works -// even when the SDK type package isn't installed locally (the Scrypted -// runtime doesn't care about types). +// The Scripts plugin (in @scrypted/core) evaluates this file inside the +// scryptedEval sandbox. The runtime pre-injects the SDK names as scope +// locals — no `import` is needed (or allowed: any `import ... from +// "@scrypted/sdk"` compiles to a require() that fails to resolve). +// All we do here is `declare` each one so TypeScript is happy; the +// declarations erase at compile time and the values come from the +// runtime scope. declare const sdk: any; -declare const require: any; - -const { - ScryptedDeviceBase, - ScryptedDeviceType, - ScryptedInterface, - systemManager, - endpointManager, - mediaManager, - deviceManager, -} = sdk; +declare const ScryptedDeviceBase: any; +declare const ScryptedDeviceType: any; +declare const ScryptedInterface: any; +declare const systemManager: any; +declare const endpointManager: any; +declare const mediaManager: any; +declare const deviceManager: any; +declare const log: any; +declare const device: any; +declare const require: any; const dns = require("dns").promises; -// Loose type aliases — the runtime values come from `sdk`, so these -// are purely cosmetic for the rest of the script's signatures. +// Loose type aliases — purely cosmetic for the rest of the script's +// signatures, since the runtime values are `any`. type DeviceCreator = any; type DeviceCreatorSettings = any; type DeviceProvider = any; |
