commit 24/11/2025

This commit is contained in:
2025-11-24 16:08:17 +07:00
parent 7ab56e32c1
commit 74413a7fb8
3 changed files with 89 additions and 32 deletions

View File

@@ -297,8 +297,8 @@ function LiveAudioCommand(command, bz, cbOK = null, cbFail = null) {
/** /**
* Websocket for streaming * Websocket for streaming
*/ */
let streamws = null; window.streamws = null;
let mediasource = null; window.mediasource = null;
$(document).ready(function () { $(document).ready(function () {
@@ -314,13 +314,13 @@ $(document).ready(function () {
} }
$icon.toggleClass('fa-stop fa-play'); $icon.toggleClass('fa-stop fa-play');
$("#listenzone").prop('disabled', false); $("#listenzone").prop('disabled', false);
if (streamws) { if (window.streamws) {
streamws.close(); window.streamws.close();
streamws = null; window.streamws = null;
} }
if (mediasource) { if (window.mediasource) {
mediasource.endOfStream(); window.mediasource.endOfStream();
mediasource = null; window.mediasource = null;
} }
let audio = document.getElementById('listenaudio'); let audio = document.getElementById('listenaudio');
audio.src = ""; audio.src = "";
@@ -336,14 +336,14 @@ $(document).ready(function () {
} }
$icon.toggleClass('fa-stop fa-play'); $icon.toggleClass('fa-stop fa-play');
$("#listenzone").prop('disabled', true); $("#listenzone").prop('disabled', true);
streamws = new WebSocket(`ws://${window.location.host}/api/LiveAudio/ws`); window.streamws = new WebSocket(`ws://${window.location.host}/api/LiveAudio/ws`);
streamws.binaryType = 'arraybuffer'; window.streamws.binaryType = 'arraybuffer';
mediasource = new MediaSource(); window.mediasource = new MediaSource();
let audio = document.getElementById('listenaudio'); let audio = document.getElementById('listenaudio');
audio.src = URL.createObjectURL(mediasource); audio.src = URL.createObjectURL(window.mediasource);
mediasource.addEventListener('sourceopen', () => { window.mediasource.addEventListener('sourceopen', () => {
const sourceBuffer = mediasource.addSourceBuffer('audio/mpeg'); const sourceBuffer = window.mediasource.addSourceBuffer('audio/mpeg');
streamws.onmessage = (event) => { window.streamws.onmessage = (event) => {
if (event.data instanceof ArrayBuffer) { if (event.data instanceof ArrayBuffer) {
const chunk = new Uint8Array(event.data); const chunk = new Uint8Array(event.data);
sourceBuffer.appendBuffer(chunk); sourceBuffer.appendBuffer(chunk);

View File

@@ -33,7 +33,7 @@ lateinit var audioPlayer: AudioPlayer
val StreamerOutputs: MutableMap<String, BarixConnection> = HashMap() val StreamerOutputs: MutableMap<String, BarixConnection> = HashMap()
lateinit var udpreceiver: UDPReceiver lateinit var udpreceiver: UDPReceiver
lateinit var tcpreceiver: TCPReceiver lateinit var tcpreceiver: TCPReceiver
const val version = "0.0.14 (04/11/2025)" const val version = "0.0.15 (24/11/2025)"
// AAS 64 channels // AAS 64 channels
const val max_channel = 64 const val max_channel = 64

View File

@@ -42,6 +42,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook
import java.nio.file.Files import java.nio.file.Files
import java.time.LocalDateTime import java.time.LocalDateTime
import codes.configKeys import codes.configKeys
import config
import database.QueueTable import database.QueueTable
import io.javalin.websocket.WsCloseStatus import io.javalin.websocket.WsCloseStatus
import org.tinylog.Logger import org.tinylog.Logger
@@ -126,8 +127,11 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
before { CheckUsers(it) } before { CheckUsers(it) }
ws("/ws") { ws -> ws("/ws") { ws ->
// WebSocket endpoint for home // WebSocket endpoint for home
// ws.onConnect {
it.enableAutomaticPings()
}
ws.onMessage { wsMessageContext -> ws.onMessage { wsMessageContext ->
try { try {
val cmd = val cmd =
objectmapper.readValue(wsMessageContext.message(), WebsocketCommand::class.java) objectmapper.readValue(wsMessageContext.message(), WebsocketCommand::class.java)
@@ -207,43 +211,87 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
} }
} }
path("soundbank.html") { path("soundbank.html") {
before { CheckUsers(it) } before {
val user = CheckUsers(it)
// only admin user can access soundbank page
if (GetAdminUserFromConfig() != user){
it.redirect("overview.html")
}
}
} }
path("messagebank.html") { path("messagebank.html") {
before { CheckUsers(it) } before {
val user = CheckUsers(it)
// only admin user can access messagebank page
if (GetAdminUserFromConfig() != user){
it.redirect("overview.html")
}
}
} }
path("language.html") { path("language.html") {
before { CheckUsers(it) } before {
val user = CheckUsers(it)
// only admin user can access language link page
if (GetAdminUserFromConfig() != user) {
it.redirect("overview.html")
}
}
} }
path("log.html") { path("log.html") {
before { CheckUsers(it) } before { CheckUsers(it) }
} }
path("setting.html") { path("setting.html") {
before { CheckUsers(it) } before {
val user = CheckUsers(it)
// only admin user can access settings page
if (GetAdminUserFromConfig() != user){
it.redirect("overview.html")
}
}
} }
path("timer.html") { path("timer.html") {
before { CheckUsers(it) } before {
val user = CheckUsers(it)
// only admin user can access timer page
if (GetAdminUserFromConfig() != user){
it.redirect("overview.html")
}
}
} }
path("filemanagement.html") { path("filemanagement.html") {
before { CheckUsers(it) } before {
val user = CheckUsers(it)
// only admin user can access file management page
if (GetAdminUserFromConfig() != user){
it.redirect("overview.html")
}
}
} }
path("broadcastzones.html") { path("broadcastzones.html") {
before { CheckUsers(it) } before {
val user = CheckUsers(it)
// only admin user can access broadcast zones page
if (GetAdminUserFromConfig() != user){
it.redirect("overview.html")
}
}
} }
path("overview.html") { path("overview.html") {
before { CheckUsers(it) } before { CheckUsers(it) }
} }
path("setting.html") {
before { CheckUsers(it) }
}
path("streamerstatus.html") { path("streamerstatus.html") {
before { CheckUsers(it) } before { CheckUsers(it) }
} }
path("timer.html") {
before { CheckUsers(it) }
}
path("usermanagement.html") { path("usermanagement.html") {
before { CheckUsers(it) } before {
val user = CheckUsers(it)
// only admin user can access user management page
if (GetAdminUserFromConfig() != user){
it.redirect("overview.html")
}
}
} }
path("api") { path("api") {
//TODO https://stackoverflow.com/questions/70002015/streaming-into-audio-element //TODO https://stackoverflow.com/questions/70002015/streaming-into-audio-element
@@ -2278,18 +2326,27 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
} }
} }
fun CheckUsers(ctx: Context) { fun CheckUsers(ctx: Context) : String? {
//val user = ctx.sessionAttribute<String?>("user") //val user = ctx.sessionAttribute<String?>("user")
val user = ctx.cookie("aas-user") val user = ctx.cookie("aas-user")
if (user == null) { if (user == null) {
ctx.redirect("login.html") ctx.redirect("login.html")
return null
} }
val foundUser = userlist.find { it.first == user } val foundUser = userlist.find { it.first == user }
if (foundUser == null) { if (foundUser == null) {
ctx.redirect("login.html") ctx.redirect("login.html")
return null
} }
return foundUser.first
} }
fun GetAdminUserFromConfig() : String{
return config.Get(configKeys.WEBAPP_ADMIN_USERNAME.key)
}
fun Get_Barix_Connection_by_ZoneName(zonename: String): BarixConnection? { fun Get_Barix_Connection_by_ZoneName(zonename: String): BarixConnection? {
if (ValidString(zonename)) { if (ValidString(zonename)) {
val bz = db.broadcastDB.List.find { it.description == zonename } val bz = db.broadcastDB.List.find { it.description == zonename }