feat: add SSE URL construction and connection management

This commit is contained in:
2026-06-11 12:45:25 -04:00
parent a4dbcf8287
commit 15baff4f26
2 changed files with 48 additions and 0 deletions
+29
View File
@@ -71,5 +71,34 @@ Buffers incoming STRING and processes complete events."
This function will be overridden in noise-receive to process envelopes."
(message "SSE event received: %s" event))
(defvar noise-signal-cli-address)
(defvar noise-account)
(defun noise-sse--build-url ()
"Build the SSE endpoint URL for signal-cli."
(let ((base (concat noise-signal-cli-address "/api/v1/events")))
(if (and (boundp 'noise-account) noise-account)
(concat base "?account=" (url-hexify-string noise-account))
base)))
(defun noise-sse--sentinel (proc status)
"Process sentinel for SSE connection.
Handles connection close and triggers reconnection."
(when (or (equal status "finished\n")
(string-match-p "failed" status)
(string-match-p "deleted" status))
(message "Noise: SSE connection lost, reconnecting in %ds..."
noise-sse--reconnect-delay)
(setq noise-sse--process nil)
(noise-sse--schedule-reconnect)))
(defun noise-sse--schedule-reconnect ()
"Schedule a reconnection attempt after the current delay."
(when noise-sse--reconnect-timer
(cancel-timer noise-sse--reconnect-timer))
(setq noise-sse--reconnect-timer
(run-with-timer noise-sse--reconnect-delay nil
#'noise-sse-connect)))
(provide 'noise-sse)
;;; noise-sse.el ends here