feat: add SSE connection state and reconnection logic
This commit is contained in:
@@ -11,6 +11,30 @@
|
||||
(require 'json)
|
||||
(require 'cl-lib)
|
||||
|
||||
(defvar noise-sse--process nil
|
||||
"Active SSE network process, or nil.")
|
||||
|
||||
(defvar noise-sse--reconnect-timer nil
|
||||
"Timer for reconnection attempts, or nil.")
|
||||
|
||||
(defvar noise-sse--reconnect-delay 1
|
||||
"Current delay in seconds before next reconnection attempt.")
|
||||
|
||||
(defcustom noise-sse-max-reconnect-delay 60
|
||||
"Maximum delay in seconds between reconnection attempts."
|
||||
:type 'integer
|
||||
:group 'noise)
|
||||
|
||||
(defun noise-sse--increase-reconnect-delay ()
|
||||
"Increase reconnect delay with exponential backoff, capped at max."
|
||||
(setq noise-sse--reconnect-delay
|
||||
(min (* noise-sse--reconnect-delay 2)
|
||||
noise-sse-max-reconnect-delay)))
|
||||
|
||||
(defun noise-sse--reset-reconnect-delay ()
|
||||
"Reset reconnect delay to initial value after successful connection."
|
||||
(setq noise-sse--reconnect-delay 1))
|
||||
|
||||
(defun noise-sse--parse-event (event-string)
|
||||
"Parse an SSE EVENT-STRING into a hash table.
|
||||
Returns nil for empty or invalid events."
|
||||
|
||||
Reference in New Issue
Block a user