From 6479fe6aee3db81e81805c08d0c9a3de2ab0c334 Mon Sep 17 00:00:00 2001 From: rdkartono Date: Thu, 6 Nov 2025 14:02:26 +0700 Subject: [PATCH] commit 06/11/2025 --- html/webpage/overview.html | 2 +- src/web/WebApp.kt | 37 ++++++++++++++++++++++--------------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/html/webpage/overview.html b/html/webpage/overview.html index 1716e2e..c6b6c3f 100644 --- a/html/webpage/overview.html +++ b/html/webpage/overview.html @@ -1347,7 +1347,7 @@
-
+
diff --git a/src/web/WebApp.kt b/src/web/WebApp.kt index cbf7124..12fe609 100644 --- a/src/web/WebApp.kt +++ b/src/web/WebApp.kt @@ -254,28 +254,35 @@ class WebApp(val listenPort: Int, val userlist: List>, val if (param.isNotEmpty()) { val bc = Get_Barix_Connection_by_ZoneName(param) if (bc != null) { - - - val key = ctx.cookie("client-id") ?: UUID.randomUUID().toString() - .also { ctx.cookie("client-id", it) } - val pipeIN = PipedInputStream(8192) - val pipeOUT = PipedOutputStream(pipeIN) - // write WAV Header 44 bytes contains samplingrate 44100 Hz, 16 bit, mono -// pipeOUT.write(Generate_WAV_Header()) - bc.AddPipeOut(key, pipeOUT) ctx.contentType("audio/mpeg") ctx.header("Cache-Control", "no-cache, no-store, must-revalidate") ctx.header("Pragma", "no-cache") ctx.header("Expires", "0") - - // 🔥 This one is critical — tells Jetty to send data in HTTP chunks as it becomes available: ctx.header("Transfer-Encoding", "chunked") - - // Keeps the TCP socket open so the browser doesn’t close after initial data ctx.header("Connection", "keep-alive") - ctx.result(pipeIN) - println("LiveAudio Open for zone $param SUCCESS") + val key = ctx.cookie("client-id") ?: UUID.randomUUID().toString() + .also { ctx.cookie("client-id", it) } + + val responseStream = ctx.res().outputStream + ctx.async { + + val pipeIN = PipedInputStream(8192) + val pipeOUT = PipedOutputStream(pipeIN) + bc.AddPipeOut(key, pipeOUT) + println("LiveAudio Open for zone $param SUCCESS") + try{ + pipeIN.transferTo(responseStream) + responseStream.flush() + } catch(e: Exception){ + + } finally{ + println("Cleaning up stream for $key") + bc.RemovePipeOut(key) + pipeIN.close() + } + } + } else ctx.status(400) .result(objectmapper.writeValueAsString(resultMessage("Broadcastzone not found"))) } else ctx.status(400)