Skip to content

feat(camera): add the modern iOS 27 camera features: tiered live views, views from away and camera-uploaded recordings - #1154

Merged
hjdhjd merged 16 commits into
beta-2.4.0from
feat/hjd-hksv3
Nov 28, 2026
Merged

hjdhjd merged 16 commits into
beta-2.4.0from
feat/hjd-hksv3

Conversation

@hjdhjd

@hjdhjd hjdhjd commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

What this adds

HAP-NodeJS gains the camera features Apple introduced with iOS 27, which Apple calls HKSV3 internally:

  • Live view in tiers. A camera offers each video sensor's picture at several sizes and bitrates, HEVC with Opus sound, and a viewer at home takes the tier that suits it. Talkback is included.
  • Live view from away over WebRTC. The library answers a viewer off the home's network itself, on a WebRTC engine built on werift.
  • Recordings the camera uploads. The library keeps the recorded tier's recent video, serves a home hub what it asks for, and packages, encrypts and uploads each clip the hub decides to keep.
  • The services around them: operating modes, motion attribution across sensors, motion zones and the camera's capabilities advertisement.

A camera takes these by stating one new block of options, cameraCapabilities. This pull request calls that the modern form. A camera set up as it always has been, the legacy form, keeps working as it does today, and nothing about it is deprecated. A camera is one form or the other, never both.

What a plugin provides, and what it stops writing

In the modern form a plugin describes each video sensor and its tiers, writes each tier's video to the library as fragmented MP4, answers a snapshot, and reports motion. The library runs every session at home and from away, shares one stream among all of a tier's viewers, applies mute, builds and uploads every recording, and releases what a plugin registers on a stream when it is no longer needed.

src/accessories/ModernCamera_example.ts is a complete camera in the modern form, fed by ffmpeg's test pattern and tone. It can be added to a home on iOS 27 as it stands.

How to read the commits

The sixteen commits tell the change in the order a reader learns it. The first five make the library ready and stand alone. The rest build the camera from its catalog up to the controller that composes it, and the last adds the example camera and the two guides.

  1. The definitions generator writes only validated, lint-clean definitions.
  2. The TLV helpers read and write 64-bit integers as bigint.
  3. transient and sensitive characteristic props: a control point's values never linger, and a key's value never reaches the debug log.
  4. The Node.js floor moves to 22.20, with the disposable stacks that version lacks as globals.
  5. A destroyed data stream server stays destroyed, and the data stream's resources are released from disposable stacks.
  6. The camera services and characteristics for tiered streams, WebRTC views and buffered recording.
  7. The TLV8 codecs of the camera characteristics, over one field layer.
  8. The camera diagnostics and the session plane every hub-commanded service shares.
  9. The modern camera's options and its own services: operating modes, video sensors and capabilities, motion attribution and motion zones.
  10. The media primitives: the fragmented MP4 reader and writer, the RTP clock, the frame cutter and SRTP.
  11. The recording that provisions a camera and uploads each clip a hub commands, packaged as CMAF and sealed under the Camera Key.
  12. Each video sensor's tier table, which paces every tier's frames from its camera buffer and keeps running the tiers a camera holds itself.
  13. Live views at home, through each sensor's multi-tier RTP stream management, with talkback.
  14. Live views from away, through each sensor's WebRTC stream management, on the WebRTC engine.
  15. The camera controller that composes every camera, legacy and modern, with recording from the camera buffer and the suites that drive it.
  16. The example camera, with the two guides.

The two guides

  • guides/UpgradingCameraPlugins.md is for plugin authors: what changed in the library, and how a camera takes the modern form.
  • guides/HKSV3Protocol.md describes the features themselves and how a home hub behaves around them.

Both are linked from the readme.

Compatibility with 2.3.1

No name the library exported in 2.3.1 is removed or renamed. These are the changes a plugin can meet, each stated in full in the upgrade guide:

  • Node.js ^22.20.0 || ^24 || ^26. The floor was ^22.12.0.
  • A new dependency, werift, at one exact version. It is loaded only when a camera in the modern form is built.
  • CameraControllerOptions is a union of CameraControllerLegacyOptions and CameraControllerCapabilitiesOptions. An object literal compiles as before. An interface that extends it, a class that implements it, or a member read through a value typed as the union stops compiling.
  • RTPStreamManagement.setupEndpointsResponse is gone. The answer to Setup Endpoints is served to the connection that asked and is never stored.
  • RecordingManagement.options is optional, as are five fields of RecordingManagementState.
  • CameraRecordingDelegate.handleRecordingStreamRequest returns AsyncIterable<RecordingPacket>, where it returned AsyncGenerator<RecordingPacket>.
  • CameraController, CameraControllerEvents, CharacteristicProps and Characteristic have new members. A subclass that declares one of the new names stops compiling.
  • At run time, for a camera set up exactly as in 2.3.1: a controller with no delegate or no streamingOptions throws at construction; the two mute events reach listeners through a guarded dispatch and no longer through emit; a recording delegate can hear updateRecordingActive at more moments; Setup Endpoints keeps no value; and a snapshot handler whose promise rejects fails its snapshot at once.
  • A destroyed DataStreamServer stays destroyed, wherever a HomeKit Data Stream is used.

By the letter of semantic versioning the removed public field would make this a major version. No plugin we could find reads it, and we propose 2.4.0, with test versions numbered 2.4.0-beta. The number is the maintainers' to set.

A convention this starts

A set of named constants first released in 2.4 or later is a constant object with a type of the same name, as CameraSensorIntent and CameraVideoQuality are here. The enums the library has already released stay enums through 2.x, because changing their kind would break the plugins that use them. The project intends to move them to this form in the next major version.

How it was tested

  • Both typechecks and the lint are clean at every one of the sixteen commits, and the suite is green at each: 3544 tests in 106 files at the last. The documentation lint is clean at the last.
  • The camera work was run against home hubs on iOS 27 throughout: pairing, live view at home and from away with talkback, recordings kept and played back, snapshots, restarts, and failures of the camera's source.
  • A private build of homebridge-unifi-protect ran on it, serving both forms.

…ich keep a control point's values from lingering and a key's value out of the debug log
…ng the data stream's resources from disposable stacks
…ered streams, WebRTC views and buffered recording
…service a hub commands shares, each controller handed its accessory's context
…perating modes, video sensors and capabilities, motion attribution and motion zones
… writer, the RTP clock, the frame cutter and SRTP
…each clip a hub commands, packaged over CMAF and sealed under the Camera Key
… frames from its camera buffer and keeping the tiers a camera holds itself running
…ulti-tier RTP stream management, with its talkback
… WebRTC stream management, on a WebRTC engine over werift
…controller, recording from the camera buffer, with the suites that drive it
@github-actions github-actions Bot added feature beta This is in some form related to the current beta release labels Nov 28, 2026
@coveralls

coveralls commented Nov 28, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 46195537695

Warning

No base build found for commit f719e11 on beta-2.4.0.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 94.453%

Details

  • Patch coverage: Could not be determined — this PR's diff is too large for GitHub to return (406 error at GitHub).

Uncovered Changes

No uncovered changes found.

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 16708
Covered Lines: 15715
Line Coverage: 94.06%
Relevant Branches: 2798
Covered Branches: 2709
Branch Coverage: 96.82%
Branches in Coverage %: Yes
Coverage Strength: 51780.29 hits per line

💛 - Coveralls

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

use() incorrectly handles disposal members, rejecting valid async disposables with throwing sync getters and accepting non-callable async members when a callable sync fallback exists.

1 open issue
What changed in this PR

Adds an opt-in modern camera path to HAP-NodeJS for tiered live views, remote WebRTC sessions, and camera-uploaded recordings, alongside the legacy camera configuration.

Changes:

  • Adds camera services, capability codecs, session helpers, media security primitives, and plugin-facing APIs.
  • Strengthens resource cleanup, connection context, diagnostics, and integer precision.
  • Adds supporting tests and fixtures, updates runtime requirements, and links the camera guides and example.
File Description
tsconfig.json Adds disposable types and skips declaration-file checking.
src/​test-utils/​talkbackSink.ts Provides reusable talkback capture fixtures.
src/​test-utils/​settle.ts Shares asynchronous waiting and timeout helpers.
src/​test-utils/​reporterFixtures.ts Provides camera reporters and problem capture fixtures.
src/​test-utils/​openingStamp.ts Shares expected opening-frame timestamp calculations.
src/​test-utils/​ingest/​stranger.pem Adds an untrusted client certificate fixture.
src/​test-utils/​ingest/​stranger.key Adds its test private key.
src/​test-utils/​ingest/​stranger-ca.pem Adds an untrusted certificate authority fixture.
src/​test-utils/​ingest/​server.pem Adds a localhost ingest server certificate.
src/​test-utils/​ingest/​server.key Adds the ingest server’s test key.
src/​test-utils/​ingest/​server-ca.pem Adds the ingest server’s test authority.
src/​test-utils/​ingest/​hub-ca.pem Adds a trusted test hub authority.
src/​test-utils/​ingest/​client.pem Adds a trusted client certificate fixture.
src/​test-utils/​ingest/​client.key Adds the trusted client’s test key.
src/​test-utils/​engineDebug.ts Captures camera debug events in tests.
src/​test-utils/​connectionFixtures.ts Models connection addresses and closure in tests.
src/​test-utils/​certificateAuthority.ts Issues runtime certificates for provisioning tests.
src/​lib/​util/​valueGuard.ts Adds internal characteristic value guards.
src/​lib/​util/​tlv.ts Adds precise bigint integer codecs.
src/​lib/​util/​tlv.spec.ts Tests bigint precision, widths, and bounds.
src/​lib/​util/​promise-utils.ts Adds guarded delegate calls and failure rendering.
src/​lib/​util/​promise-utils.spec.ts Tests delegate failures and rejection handling.
src/​lib/​util/​ntp.ts Converts wall-clock time to precise NTP values.
src/​lib/​util/​ntp.spec.ts Tests NTP fractions and era rollover.
src/​lib/​util/​libraryVersion.ts Centralizes cached package-version lookup.
src/​lib/​util/​eventedhttp.spec.ts Adjusts mock and timer cleanup order.
src/​lib/​util/​der.ts Adds DER encoding for signing requests.
src/​lib/​util/​der.spec.ts Tests DER encodings and validation.
src/​lib/​util/​counted.ts Adds count-aware diagnostic wording helpers.
src/​lib/​util/​counted.spec.ts Tests singular and plural formatting.
src/​lib/​util/​asyncDisposableStack.ts Adds an internal asynchronous disposal stack.
src/​lib/​Service.ts Declares camera services and clarifies a timeout comment.
src/​lib/​HAPServer.ts Passes connection context to resource handlers.
src/​lib/​HAPServer.spec.ts Tests resource-request connection forwarding.
src/​lib/​definitions/​ServiceDefinitions.ts Defines modern camera services and motion characteristics.
src/​lib/​datastream/​DataStreamManagement.ts Moves teardown into a disposal stack.
src/​lib/​datastream/​DataStreamManagement.spec.ts Tests setup validation, responses, and teardown.
src/​lib/​controller/​eventDispatch.ts Guards camera event listeners against failures.
src/​lib/​controller/​DoorbellController.ts Preserves reconfiguration options and permits motionless modern doorbells.
src/​lib/​controller/​DoorbellController.spec.ts Tests validation and doorbell reconfiguration.
src/​lib/​controller/​Controller.ts Adds accessory context to serializable controllers.
src/​lib/​camera/​webrtc/​werift.ts Loads werift lazily with explicit debug gating.
src/​lib/​camera/​webrtc/​voice/​ReceiveKeys.ts Bounds receive-key storage and zeroes removed keys.
src/​lib/​camera/​webrtc/​voice/​ReceiveKeys.spec.ts Tests key replacement, eviction, and disposal.
src/​lib/​camera/​webrtc/​sessionDescription.ts Adds tier restrictions and session-description helpers.
src/​lib/​camera/​webrtc/​EngineSession.spec.ts Tests teardown bounds and RTP packet sequencing.
src/​lib/​camera/​srtp/​keystream.ts Adds SRTP counter-mode encryption primitives.
src/​lib/​camera/​srtp/​keystream.spec.ts Checks keystream and key-derivation reference vectors.
src/​lib/​camera/​session/​StreamingEnabledSwitch.ts Tracks streaming changes, restoration, and persistence.
src/​lib/​camera/​session/​settleWithin.ts Adds abortable, bounded delegate waits.
src/​lib/​camera/​session/​settleWithin.spec.ts Tests settlement, cancellation, and timeout behavior.
src/​lib/​camera/​session/​HandleScope.ts Manages plugin cleanup registrations per handle.
src/​lib/​camera/​session/​controlPoint.ts Wires queued control-point writes and answer release.
src/​lib/​camera/​session/​CommandQueue.ts Serializes service commands across asynchronous work.
src/​lib/​camera/​session/​CommandQueue.spec.ts Tests command ordering and failure isolation.
src/​lib/​camera/​SensorRegistry.ts Validates sensors and advertises ordered capabilities.
src/​lib/​camera/​rtp/​packetRules.ts Shares RTP sequence, timestamp, and marker rules.
src/​lib/​camera/​rtp/​packetRules.spec.ts Tests RTP header-field rules and rollover.
src/​lib/​camera/​recording/​signingRequest.ts Creates camera signing requests and nonce signatures.
src/​lib/​camera/​recording/​signingRequest.spec.ts Tests request structure and signature verification.
src/​lib/​camera/​recording/​clipSealing.ts Derives recording keys and encrypts media segments.
src/​lib/​camera/​recording/​clipSealing.spec.ts Tests key derivation and authenticated encryption.
src/​lib/​camera/​recording/​CameraEventQueue.spec.ts Tests event numbering, acknowledgements, and overflow.
src/​lib/​camera/​MotionAttribution.ts Associates detected motion with contributing video sensors.
src/​lib/​camera/​index.ts Exports modern camera types and diagnostics.
src/​lib/​camera/​GlobalOperatingMode.ts Projects camera-wide policy onto its service.
src/​lib/​camera/​diagnostics/​problems.spec.ts Tests problem delivery and subscriber isolation.
src/​lib/​camera/​diagnostics/​debugChannels.ts Adds structured camera debug channels and printers.
src/​lib/​camera/​diagnostics/​debugChannels.spec.ts Tests debug selection and duplicate-printer prevention.
src/​lib/​camera/​capabilityKeys.ts Shares service-map keys and sensor reconciliation.
src/​lib/​camera/​capabilities/​zones.ts Encodes and decodes motion-zone payloads.
src/​lib/​camera/​capabilities/​zones.spec.ts Tests zone vectors and malformed payloads.
src/​lib/​camera/​capabilities/​supportedRtpConfiguration.ts Shares supported SRTP-suite encoding and decoding.
src/​lib/​camera/​capabilities/​supportedRtpConfiguration.spec.ts Tests suite encoding parity and validation.
src/​lib/​camera/​capabilities/​streamTiers.spec.ts Tests tier payload vectors and integer widths.
src/​lib/​camera/​capabilities/​rtpStreaming.ts Adds tiered RTP command and response codecs.
src/​lib/​camera/​capabilities/​rtpStreaming.spec.ts Tests RTP commands, responses, and hub payloads.
src/​lib/​camera/​capabilities/​provisioning.spec.ts Tests key and certificate provisioning codecs.
src/​lib/​camera/​capabilities/​index.ts Exposes plugin-facing capability types and constants.
src/​hap.ts Reuses version lookup and explicitly lists public TLV exports.
README.md Updates Node requirements and links camera documentation.
package.json Raises the runtime floor, pins werift, and adjusts packaging scripts.
eslint.config.mjs Adds disposal, precision, guide, and packaging lint rules.

Review effort: Balanced

Comment thread src/lib/util/asyncDisposableStack.ts Resolved
@hjdhjd
hjdhjd merged commit e83d144 into beta-2.4.0 Nov 28, 2026
15 checks passed
@hjdhjd
hjdhjd deleted the feat/hjd-hksv3 branch November 28, 2026 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beta This is in some form related to the current beta release feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants