fix: use correct signal-cli default port 8080 and robust connectivity check

- Change default noise-signal-cli-address to port 8080 (signal-cli's --http default)
- Replace getVersion (not a valid JSON-RPC method) with noisePing probe
- noise-rpc-check now returns t on any valid JSON-RPC response
- Update README to reflect correct default port
This commit is contained in:
2026-06-10 10:44:20 -04:00
parent 6d8727ea05
commit 8d820432ff
3 changed files with 41 additions and 10 deletions
+33 -4
View File
@@ -83,10 +83,39 @@ Signals `noise-rpc-error` on JSON-RPC error or malformed response."
(defun noise-rpc-check ()
"Check connectivity to signal-cli.
Returns the version string on success.
Signals `noise-rpc-error` on failure."
(let ((result (noise-rpc-call "getVersion")))
(gethash "version" result)))
Returns t if the daemon responds (even with an error indicating a valid JSON-RPC endpoint).
Signals `noise-rpc-error` on connection failure or timeout."
;; signal-cli daemon doesn't have a dedicated ping/version RPC method.
;; We send a request for a purposefully invalid method. If we get back
;; a valid JSON-RPC error response, the daemon is running and reachable.
;; If we get a connection error, the daemon is not running.
(let* ((url-request-method "POST")
(url-request-extra-headers
'(("Content-Type" . "application/json")))
(url-request-data "{\"jsonrpc\":\"2.0\",\"method\":\"noisePing\",\"id\":0}")
(url (concat noise-signal-cli-address "/api/v1/rpc"))
(url-show-status nil)
(buf (condition-case nil
(url-retrieve-synchronously url t)
(error (signal 'noise-rpc-error
(list (format "Could not connect to signal-cli at %s. Is signal-cli daemon running?"
noise-signal-cli-address)))))))
(if (not buf)
(signal 'noise-rpc-error (list (format "No response from signal-cli at %s" noise-signal-cli-address)))
(unwind-protect
(with-current-buffer buf
(goto-char (point-min))
(re-search-forward "\n\n" nil t)
(let* ((body (buffer-substring (point) (point-max)))
(parsed (condition-case nil
(json-parse-string body)
(error (signal 'noise-rpc-error
(list "signal-cli returned invalid JSON response"))))))
;; Any valid JSON-RPC response means the daemon is alive
(if (or (gethash "result" parsed) (gethash "error" parsed))
t
(signal 'noise-rpc-error (list "Invalid JSON-RPC response from signal-cli")))))
(kill-buffer buf)))))
(provide 'noise-rpc)
;;; noise-rpc.el ends here