diff --git a/frontend-partials.lisp b/frontend-partials.lisp index 157ef61..a300e4c 100644 --- a/frontend-partials.lisp +++ b/frontend-partials.lisp @@ -96,3 +96,9 @@ (progn (setf (header "Content-Type") "text/plain") "Stream Offline"))))) + +(define-api asteroid/channel-name () () + "Get the current curated channel name for live updates. + Returns JSON with the channel name from the current playlist's PHASE header." + (with-error-handling + (api-output `(("channel_name" . ,(get-curated-channel-name)))))) diff --git a/parenscript/front-page.lisp b/parenscript/front-page.lisp index 628324d..de76396 100644 --- a/parenscript/front-page.lisp +++ b/parenscript/front-page.lisp @@ -594,8 +594,37 @@ ;; Update now playing every 5 seconds (set-interval update-now-playing 5000) - - ;; Listen for messages from popout window + + ;; Poll server for channel name changes (works across all listeners) + (let ((last-channel-name nil)) + (set-interval + (lambda () + (ps:chain + (fetch "/api/asteroid/channel-name") + (then (lambda (response) + (if (ps:@ response ok) + (ps:chain response (json)) + nil))) + (then (lambda (data) + (when data + (let ((current-channel-name (or (ps:@ data data channel_name) + (ps:@ data channel_name)))) + (when (and current-channel-name + (not (= current-channel-name last-channel-name))) + (setf last-channel-name current-channel-name) + ;; Update localStorage for cross-window sync + (ps:chain local-storage (set-item "curated-channel-name" current-channel-name)) + ;; Update channel selector in current document + (let ((channel-selector (ps:chain document (get-element-by-id "stream-channel")))) + (when channel-selector + (let ((curated-option (ps:chain channel-selector (query-selector "option[value='curated']")))) + (when curated-option + (setf (ps:@ curated-option text-content) (+ "🎧 " current-channel-name))))))))))) + (catch (lambda (error) + (ps:chain console (log "Could not fetch channel name:" error)))))) + 10000)) ;; Poll every 10 seconds + + ;; Listen for messages from popout window (ps:chain window (add-event-listener "message" diff --git a/parenscript/stream-player.lisp b/parenscript/stream-player.lisp index a2bcbc3..a69c7ab 100644 --- a/parenscript/stream-player.lisp +++ b/parenscript/stream-player.lisp @@ -556,20 +556,33 @@ ;; Update quality selector state based on channel (update-quality-selector-state) - ;; Check for channel name changes from localStorage periodically - (let ((last-channel-name (ps:chain local-storage (get-item "curated-channel-name")))) + ;; Poll server for channel name changes (works across all listeners) + (let ((last-channel-name nil)) (set-interval (lambda () - (let ((current-channel-name (ps:chain local-storage (get-item "curated-channel-name")))) - (when (and current-channel-name - (not (= current-channel-name last-channel-name))) - (setf last-channel-name current-channel-name) - (let ((channel-selector (ps:chain document (get-element-by-id "stream-channel")))) - (when channel-selector - (let ((curated-option (ps:chain channel-selector (query-selector "option[value='curated']")))) - (when curated-option - (setf (ps:@ curated-option text-content) (+ "🎧 " current-channel-name))))))))) - 2000)) + (ps:chain + (fetch "/api/asteroid/channel-name") + (then (lambda (response) + (if (ps:@ response ok) + (ps:chain response (json)) + nil))) + (then (lambda (data) + (when data + (let ((current-channel-name (or (ps:@ data data channel_name) + (ps:@ data channel_name)))) + (when (and current-channel-name + (not (= current-channel-name last-channel-name))) + (setf last-channel-name current-channel-name) + ;; Update localStorage for popout player sync + (ps:chain local-storage (set-item "curated-channel-name" current-channel-name)) + (let ((channel-selector (ps:chain document (get-element-by-id "stream-channel")))) + (when channel-selector + (let ((curated-option (ps:chain channel-selector (query-selector "option[value='curated']")))) + (when curated-option + (setf (ps:@ curated-option text-content) (+ "🎧 " current-channel-name))))))))))) + (catch (lambda (error) + (ps:chain console (log "Could not fetch channel name:" error)))))) + 10000)) ;; Poll every 10 seconds ;; Start now playing updates (set-timeout update-mini-now-playing 1000) diff --git a/parenscript/users.lisp b/parenscript/users.lisp index 28bad00..a2c5971 100644 --- a/parenscript/users.lisp +++ b/parenscript/users.lisp @@ -58,7 +58,7 @@ "" "