commit 06/11/2025
This commit is contained in:
@@ -254,28 +254,35 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, 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)
|
||||
|
||||
Reference in New Issue
Block a user