8496 Commits

Author SHA1 Message Date
Sergey Vilgelm
6d9a3876f5 server: guard plugin-repl against stale nativeId (#2024)
* server: guard plugin-repl against stale nativeId

The REPL handler destructured nativeIds.get(filter) directly, which
threw an unhandledRejection TypeError when filter was a nativeId for a
device that had been removed since the UI rendered the REPL link.
Break out of the chain walk when the lookup misses instead.

Assisted-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Sergey Vilgelm <sergey@vilgelm.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

---------

Signed-off-by: Sergey Vilgelm <sergey@vilgelm.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-05-02 09:24:06 -07:00
Koushik Dutta
57320b90ed fix using holder no-op release disposal 2026-04-29 10:50:59 -07:00
Koushik Dutta
0b62a7c1a5 Merge branch 'main' of github.com:koush/scrypted 2026-04-21 09:12:53 -07:00
Koushik Dutta
b72628c7b6 common: add tslib as dev dep 2026-04-21 09:12:46 -07:00
Pankaj Rupani
de65dffc7c docs: clarify avahi config for host vs bridge networking (#2014)
Some checks failed
Test / Test local installation on macos-13 (push) Has been cancelled
Test / Test local installation on macos-14 (push) Has been cancelled
Test / Test local installation on ubuntu-24.04-arm (push) Has been cancelled
Test / Test local installation on ubuntu-latest (push) Has been cancelled
Test / Test local installation on windows-latest (push) Has been cancelled
* docs: clarify avahi config for host vs bridge networking

The HomeKit plugin's MDNSServer binds UDP port 5353 directly on every
network interface. With network_mode: host (the default), this conflicts
with any system avahi-daemon running on the host, causing EADDRINUSE on
all interfaces and silently breaking HomeKit mDNS discovery.

The previous comments implied the host socket mount and
SCRYPTED_DOCKER_AVAHI=true were equivalent alternatives ("choose one or
the other"), which is misleading. Clarify the two distinct use cases:

- Option A (host networking): SCRYPTED_DOCKER_AVAHI=true is required.
  The host avahi-daemon must be stopped. The /var/run socket mounts are
  incompatible with this mode. Add a note about mounting
  /etc/avahi/services to preserve host service advertisements.

- Option B (bridge networking only): host socket mount works because
  Scrypted registers via D-Bus without binding 5353. Does not work with
  host networking.

Fixes #2013

* fix: use SCRYPTED_DOCKER_AVAHI=true for avahi setup with host networking

The install script was configuring the host avahi socket mount (Option B)
while the template uses network_mode: host. This is a broken combination:
the HomeKit plugin's MDNSServer binds UDP 5353 directly on every interface,
conflicting with the system avahi-daemon, causing EADDRINUSE on all
interfaces and silently breaking HomeKit mDNS discovery.

Fix: when the user opts in to avahi, use SCRYPTED_DOCKER_AVAHI=true
(Option A) instead. This makes Scrypted run its own internal avahi.
Also stop/disable the host avahi-daemon so it doesn't conflict, and
mount /etc/avahi/services:ro so Scrypted's avahi picks up existing host
service definitions (e.g. Time Machine, Samba).

Fixes #2013
2026-04-16 07:59:36 -07:00
Yuki MIZUNO
55369aeb88 rebroadcast: show stream selection options when synthetic streams are configured (#2012)
* fix: show stream selection options when synthetic streams are configured

* fix: show stream selection options and enforce FFmpeg parser for synthetic streams
2026-04-16 07:57:28 -07:00
Koushik Dutta
194acf15e8 common: use peerDependencies 2026-04-07 10:19:34 -07:00
Koushik Dutta
fbb4fc8fa4 common: update types 2026-04-07 10:17:40 -07:00
Koushik Dutta
c6be722989 various: strict fixes 2026-04-02 16:08:23 -07:00
Koushik Dutta
21ecfd85ef client: strict mode 2026-04-02 15:59:56 -07:00
Koushik Dutta
d0383c6503 server: match mediaobject constrcutor 2026-04-02 15:55:54 -07:00
Koushik Dutta
1c894561a0 tsconfig: remove redundant strict flags covered by 'strict: true'
Some checks failed
Build SDK / Build (push) Has been cancelled
The following flags are implied by 'strict: true' and are redundant:
- strictNullChecks
- strictFunctionTypes
- strictBindCallApply
- strictPropertyInitialization
- noImplicitThis
- alwaysStrict
- noImplicitAny

Kept explicitly:
- noFallthroughCasesInSwitch
- noUncheckedIndexedAccess
- noImplicitOverride
- noImplicitReturns
2026-04-02 14:59:37 -07:00
Koushik Dutta
d8b305dcdb fixup: services: update findPluginDevice call after return type change 2026-04-02 14:58:25 -07:00
Koushik Dutta
5a1c3d024b plugin: add type assertions for strictNullChecks in runtime workers
Fix strictNullChecks:
- child-process-worker.ts: add definite assignment for childProcess
- custom-worker.ts: add assertions for pluginDevice and options
- node-fork-worker.ts: add catch block type annotation
- node-thread-worker.ts: add catch block type annotation
- python-worker.ts: add assertions for worker properties
2026-04-02 14:57:53 -07:00
Koushik Dutta
2bd8354ead plugin: add type assertions for strictNullChecks in plugin core modules
Fix strictNullChecks:
- device.ts: add assertions for storage and nativeIds access
- endpoint.ts: add assertions for device and handler access
- plugin-api.ts: add definite assignment for callback properties
- plugin-host-api.ts: add assertions for findPluginDevice results,
  consolidate plugin assertions at declarations
- plugin-lazy-remote.ts: add assertion for getFile result
- system.ts: add definite assignment for manager properties,
  add assertions for state access
2026-04-02 14:57:14 -07:00
Koushik Dutta
34a9e698ae plugin: add type assertions for strictNullChecks in plugin-device and remote modules
Fix strictNullChecks:
- plugin-device.ts: consolidate entry/host assertions at declarations,
  use undefined! for proxy values, add definite assignment for mixinTable
- plugin-remote.ts: add assertions for callbacks and nativeIds access
- plugin-remote-worker.ts: fix clusterWorkerId as Promise<string | undefined>,
  add assertions for worker and options properties
2026-04-02 14:54:40 -07:00
Koushik Dutta
01aab01e46 plugin: add type assertions for strictNullChecks in plugin-host and media
Fix strictNullChecks:
- plugin-host.ts: consolidate logger assertion at declaration,
  extract handler variable to avoid repeated assertions,
  use undefined! for clusterWorkerId, add definite assignment
- media.ts: add assertions for converter and mediaObject access
2026-04-02 14:51:35 -07:00
Koushik Dutta
61d9345bf6 cluster: add type assertions for strictNullChecks compliance
Fix strictNullChecks in cluster modules:
- cluster-labels.ts: add assertions for label and weight access
- cluster.ts: keep getClusterWorkerId returning string (API contract)
- scrypted-cluster-main.ts: add assertions for socket properties,
  consolidate remoteAddress assertion, fix cluster worker lookups
- cluster-fork.ts: add assertions for worker and options properties,
  fix findPluginDevice call with assertion
2026-04-02 14:50:26 -07:00
Koushik Dutta
d0deb04588 runtime: add type assertions for strictNullChecks compliance
Fix strictNullChecks in runtime.ts and scrypted-server-main.ts:
- Change findPluginDevice return type to PluginDevice | undefined
- Add type assertions at call sites that expect valid results
- Consolidate assertions at variable declarations
- Use undefined! instead of undefined as any
- Use throw e instead of throw new Error(e as string)
- Add catch block type annotations (e: any)
- Fix socket property and plugin device lookups with assertions
2026-04-02 14:48:39 -07:00
Koushik Dutta
d69c949ec7 services: add type assertions for strictNullChecks compliance
Fix strictNullChecks in services:
- plugin.ts: assert findPluginDeviceById results at assignment point,
  clean up scattered assertions throughout methods
- users.ts: make aclId parameter optional in addUserToDatabase/addUserInternal
2026-04-02 14:19:26 -07:00
Koushik Dutta
519eb36368 utils: add type assertions for strictNullChecks compliance
Fix strictNullChecks in utility modules:
- rpc.ts: make onProxySerialization optional (used with ?.), add definite assignment for killedDeferred
- state.ts: cast catch block error to Error
- level.ts: add definite assignment for curId
- threading.ts: cast catch block errors to Error
- http-interfaces.ts: cast catch block error to Error
- plugin-http.ts: cast catch block errors to Error, fix abstract method return type
- usertoken.ts: make aclId optional in UserToken constructor
2026-04-02 14:15:28 -07:00
Koushik Dutta
6ece12e3cc sdk: change return type of getNativeIds 2026-04-02 13:34:39 -07:00
Koushik Dutta
896445ec80 strictNullChecks: fix plugin remote handlers
- Make PluginRemote.loadZip options parameter optional to match implementations
- Add undefined to _protocols type in WebSocket class
- Add non-null assertions for device lookup in REPL server
2026-04-02 13:33:12 -07:00
Koushik Dutta
85a30d7b87 strictNullChecks: fix plugin types
- Add non-null assertion for eventInterface in acl.ts
- Add non-null assertion for SCRYPTED_CLUSTER_ADDRESS env var
- Use .flat() instead of [].concat() for type safety
- Add non-null assertion for ScryptedDevice descriptor access
- Use options! and null! assertions for mediaObject properties
2026-04-02 13:33:12 -07:00
Koushik Dutta
f620c80589 strictNullChecks: fix plugin runtime workers
- Add non-null assertions for worker and stdio access
- Add non-null assertions for kill() undefined assignments
2026-04-02 13:33:12 -07:00
Koushik Dutta
5f040f5ff4 strictNullChecks: fix core utilities
- Change Express sendFile root from null to undefined
- Add undefined to RefreshPromise.promise type
- Add undefined to debouncer current promise type
2026-04-02 13:33:12 -07:00
Koushik Dutta
5bfb3e5675 strictNullChecks: fix services and notifyInterfaceEvent type
- Change notifyInterfaceEvent parameter to PluginDevice | undefined
- Pass undefined instead of null at call sites
- Add non-null assertion for webhookUpdateAuthorization
2026-04-02 13:33:12 -07:00
Koushik Dutta
056be96e4f strictNullChecks: fix cluster modules
- Initialize foundAny variable before use
- Add fallback for undefined env var in parseFloat
- Add non-null assertions for Map lookups and array indices
- Fix ClusterObject type annotation for undefined case
- Add non-null assertions for env vars and socket properties
2026-04-02 13:33:12 -07:00
Koushik Dutta
ca7efc1f04 fix: type annotations for event and state management
- Add type assertions for event callbacks and timestamps
- Use non-null assertions for guaranteed object references
- Update notify signature to accept number | undefined for eventTime
- Preserve crash behavior for logger and refresh throttle access
2026-04-02 13:33:12 -07:00
Koushik Dutta
9c1d2b78c8 fix: type annotations for plugin API layer
- setStorage interface uses ScryptedNativeId to match implementation
- getDeviceById returns Promise<ScryptedDevice | undefined>
- Add non-null assertions where objects are guaranteed to exist
- Add explicit error throws for null checks with descriptive messages
2026-04-02 13:33:12 -07:00
Koushik Dutta
2763f4af2c fix: make pid optional in RuntimeWorker interface
pid may be undefined if worker hasn't started yet.
Update implementations to return number | undefined.
2026-04-02 13:33:12 -07:00
Koushik Dutta
621c5537d4 fix: use ScryptedNativeId type for plugin device maps
Use ScryptedNativeId (string | undefined) as Map key type instead of string,
matching the actual usage pattern where nativeId can be undefined.
2026-04-02 13:33:12 -07:00
Koushik Dutta
2187982b07 fix: add type annotations for plugin HTTP handling
- Add ?? false for isUpgradeRequest return type
- Add non-null assertion for socket access
- Add early validation for empty endpoint
2026-04-02 13:33:12 -07:00
Koushik Dutta
5dde5ae893 fix: add type annotations for network address functions
- Add parseInt with empty string fallback for undefined env vars
- getIpAddress returns string | undefined when no addresses available
- Add type guard filters for network interface arrays
2026-04-02 13:33:12 -07:00
Koushik Dutta
cfa9e2a200 fix: make LevelDocument._id and _documentType required
These properties are always present after document creation.
Update PluginDevice constructor to require id parameter.
2026-04-02 13:33:12 -07:00
Koushik Dutta
0d4a0d2c2c fix: initialize RpcResult before try block to match Python implementation
Previously, if this.serialize() threw an exception, result would be undefined
when passed to createErrorResult. This fix brings TypeScript in sync with the
Python rpc.py implementation which already initializes result before the try block.
2026-04-02 13:33:12 -07:00
Koushik Dutta
24ecc19e99 fix: add ts-ignore for delete operations on required properties
zipFile and unzippedPath are set at runtime by cluster worker host.
2026-04-02 13:33:12 -07:00
Koushik Dutta
675b967862 fix: add undefined to buffer state type annotations
Buffer state variables can be undefined before initialization.
2026-04-02 13:33:12 -07:00
Koushik Dutta
3882805cfc fix: add type guard filter for network interfaces
Filter undefined values after flat() to prevent runtime errors
when accessing ni.address.
2026-04-02 13:33:12 -07:00
Koushik Dutta
6ac91bc1a3 fix: add undefined to return type and filter
inferTypeFromInterfaces can return undefined for empty arrays.
Add type guard filter to remove undefined entries.
2026-04-02 13:33:12 -07:00
Koushik Dutta
b2301a3073 fix: add non-null assertions for process.argv and process.send
These values are guaranteed to exist in the plugin main process context.
2026-04-02 13:33:12 -07:00
Koushik Dutta
9cfa6ea58b fix: refactor serviceKey undefined handling
Check serviceKey directly after parsing instead of checking existing?.serviceKey.
This fixes a bug where key parsing failures would be silently ignored.
2026-04-02 13:33:12 -07:00
Koushik Dutta
65199ecdf7 refactor: rename mixins parameter to avoid mutation
Rename parameter to mixinsList to avoid mutating the input parameter.
Add non-null assertion for pop result.
2026-04-02 13:33:12 -07:00
Koushik Dutta
64ed95e9aa fix: add non-null assertions for parentPort access
parentPort is guaranteed to exist in worker thread context.
2026-04-02 13:33:12 -07:00
Koushik Dutta
8c5b2f48cc fix: add definite assignment assertion for cancel variable
Add `!` assertion to cancel variable that is assigned in callback.
2026-04-02 13:33:12 -07:00
Koushik Dutta
bc8f1ebc97 refactor: use Object.entries() in createHeadersArray
Use Object.entries() spread instead of manual loop for cleaner code.
2026-04-02 13:33:12 -07:00
Koushik Dutta
2977d0a90b server: update types 2026-04-02 13:33:12 -07:00
Koushik Dutta
dd59ac40b6 noImplicitReturns: enabled implicit return checking
Fixed all 32 errors by:
- Adding '| undefined' to return type signatures where functions could return undefined
- Changing 'return;' to 'return undefined;' (explicit instead of implicit)
- Adding 'return undefined;' at function ends where needed

Functions updated:
- src/cluster/cluster-setup.ts: getClusterObject, getScryptedClusterMode
- src/fetch/index.ts: getHttpFetchAccept
- src/infer-defaults.ts: inferRoomFromName, getProvidedRoomOrDefault, getDisplayRoom
- src/level.ts: tryGet
- src/plugin/plugin-api.ts: getDeviceById
- src/plugin/plugin-device.ts: findMethod, findMixin
- src/plugin/plugin-host-api.ts: setDeviceProperty
- src/plugin/system.ts: getOwnPropertyDescriptor
- src/rpc.ts: getIteratorNext
- src/runtime.ts: getAccessControlAllowOrigin, getDeviceLogger, getEndpointPluginData, getAccessControls, invalidatePluginDevice, rebuildPluginDeviceMixinTable, installNpm, getPluginHostForDevice, getDevice
- src/scrypted-server-main.ts: getDefaultAuthentication, checkValidUserToken
- src/services/addresses.ts: getLocalAddresses
- src/state.ts: setState
2026-04-02 13:33:09 -07:00
Koushik Dutta
fd0b3a0b8f noImplicitOverride: enabled override modifier checking
Added 'override' keyword to methods that override base class members:
- src/level.ts: override open() methods
- src/plugin/plugin-remote-worker.ts: override setStorage() methods
- src/plugin/runtime/node-fork-worker.ts: override pid getter
- src/plugin/runtime/python-worker.ts: override stdout/stderr getters
- src/rpc.ts: override cause parameter in RPCResultError
- src/runtime.ts: override wss property
- src/state.ts: override listenDevice() method
2026-04-02 13:32:51 -07:00
Koushik Dutta
196ff8378c noUncheckedIndexedAccess: enabled unchecked indexed access checking 2026-04-02 13:32:51 -07:00