fix: Serve spectrum analyzer JavaScript dynamically via API
Changed from static file generation to Radiance API endpoint. Parenscript now generates JavaScript in-memory at runtime when the /api/asteroid/spectrum-analyzer.js endpoint is requested. This is the correct approach for Parenscript integration with Radiance.
This commit is contained in:
parent
a1257af16f
commit
090e8e9898
|
|
@ -4,10 +4,3 @@
|
|||
(:use #:cl #:radiance #:lass #:r-clip #:asteroid.app-utils)
|
||||
(:domain "asteroid")
|
||||
(:export #:-main))
|
||||
|
||||
;; Generate Parenscript files at compile time
|
||||
(eval-when (:compile-toplevel :load-toplevel :execute)
|
||||
(when (find-package :asteroid)
|
||||
(let ((pkg (find-package :asteroid)))
|
||||
(when (fboundp (find-symbol "WRITE-SPECTRUM-ANALYZER-JS" pkg))
|
||||
(funcall (find-symbol "WRITE-SPECTRUM-ANALYZER-JS" pkg))))))
|
||||
|
|
|
|||
|
|
@ -3,8 +3,9 @@
|
|||
;;; Spectrum Analyzer - Parenscript Implementation
|
||||
;;; Generates JavaScript for real-time audio visualization
|
||||
|
||||
(defun generate-spectrum-analyzer-js ()
|
||||
"Generate JavaScript code for the spectrum analyzer using Parenscript"
|
||||
(define-api asteroid/spectrum-analyzer.js () ()
|
||||
"Serve the spectrum analyzer JavaScript generated from Parenscript"
|
||||
(setf (content-type *response*) "application/javascript")
|
||||
(ps:ps
|
||||
(defvar *audio-context* nil)
|
||||
(defvar *analyser* nil)
|
||||
|
|
@ -85,12 +86,4 @@
|
|||
(let ((audio-element (chain document (get-element-by-id "live-audio"))))
|
||||
(when audio-element
|
||||
(chain audio-element (add-event-listener "play" init-spectrum-analyzer))
|
||||
(chain audio-element (add-event-listener "pause" stop-spectrum-analyzer)))))))))
|
||||
|
||||
(defun write-spectrum-analyzer-js ()
|
||||
"Write the generated JavaScript to a file"
|
||||
(with-open-file (stream (asdf:system-relative-pathname :asteroid "static/js/spectrum-analyzer.js")
|
||||
:direction :output
|
||||
:if-exists :supersede
|
||||
:if-does-not-exist :create)
|
||||
(write-string (generate-spectrum-analyzer-js) stream)))
|
||||
(chain audio-element (add-event-listener "pause" stop-spectrum-analyzer))))))))
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
<script src="/asteroid/static/js/auth-ui.js"></script>
|
||||
<script src="/asteroid/static/js/front-page.js"></script>
|
||||
<script src="/asteroid/static/js/recently-played.js"></script>
|
||||
<script src="/asteroid/static/js/spectrum-analyzer.js"></script>
|
||||
<script src="/api/asteroid/spectrum-analyzer.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
|
|
|
|||
Loading…
Reference in New Issue