Skip to content

Add WebSocket support for TrueNAS JSON-RPC 2.0 API#1578

Merged
KodeStar merged 2 commits into
2.xfrom
feat/truenas-websocket-client
Jul 9, 2026
Merged

Add WebSocket support for TrueNAS JSON-RPC 2.0 API#1578
KodeStar merged 2 commits into
2.xfrom
feat/truenas-websocket-client

Conversation

@KodeStar

@KodeStar KodeStar commented Jul 9, 2026

Copy link
Copy Markdown
Member

Revives #1538 (closed as stale, original work by @jaycollett — his commit authorship is preserved on the first commit).

The TrueNAS app merged in linuxserver/Heimdall-Apps#889 ships TrueNASApiTrait that gates its WebSocket JSON-RPC path on App\Helpers\TrueNASWebSocketClient and WebSocket\Client existing in core. Without this PR the app silently degrades to REST-only, and TrueNAS removes the REST API in 26.04 — so the migration's whole point is dead code until core ships this.

Two additions over the original PR:

  1. Vendored the dependency. This repo commits vendor/ and CI doesn't run composer install, so a composer.json-only change would never make WebSocket\Client exist at runtime. phrity/websocket ^3.6 (resolves 3.7.3) plus its transitive deps are committed with the updated lock; composer validate passes and the regenerated autoloader resolves all three classes.
  2. Fixed the exception namespace. The helper caught WebSocket\ConnectionException, which only existed in the old textalk/websocket v1/v2 — in phrity v3 exceptions live under WebSocket\Exception\*, so those catch blocks could never match. It now catches WebSocket\Exception\Exception.

Helper reviewed against the installed v3 API (text(), receive()->getContent(), setTimeout(), setContext(), close()): TLS verification only disabled behind explicit ignore_tls, ALPN forced to http/1.1 for TrueNAS's nginx, 15s timeout, no API-key logging. Not exercised against a live TrueNAS box — the app's auto mode falls back to REST if the socket fails, so worst case is unchanged behavior.

jaycollett and others added 2 commits July 9, 2026 21:56
TrueNAS is deprecating the REST API (api/v2.0/) in version 26.04,
requiring migration to JSON-RPC 2.0 over WebSocket.

This commit adds:
- phrity/websocket dependency for WebSocket communication
- TrueNASWebSocketClient helper class that handles:
  - Connection to ws(s)://host/api/current
  - Authentication via auth.login_with_api_key
  - JSON-RPC 2.0 request/response formatting
  - TLS verification toggle
  - Proper connection cleanup

Refs: #1530
The WebSocket support added for TrueNAS JSON-RPC 2.0 requires the
phrity/websocket library to actually be available at runtime. This repo
commits the vendor/ tree (CI does not run composer install), so the
dependency and composer.lock must be committed for class_exists() checks
in the TrueNAS app to succeed.

- composer require phrity/websocket:^3.6 (resolves to 3.7.3) with lock
  and vendor/ committed
- Fix TrueNASWebSocketClient to catch WebSocket\Exception\Exception
  (phrity/websocket v3 namespace) instead of the non-existent
  WebSocket\ConnectionException from the old textalk/websocket v1/v2 API,
  so connection/call failures are logged and wrapped as intended
@KodeStar KodeStar merged commit 1f7432f into 2.x Jul 9, 2026
2 checks passed
@KodeStar KodeStar deleted the feat/truenas-websocket-client branch July 9, 2026 21:06
@LinuxServer-CI LinuxServer-CI moved this from PRs to Done in Issue & PR Tracker Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants