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

View File

@@ -33,7 +33,7 @@ lateinit var audioPlayer: AudioPlayer
val StreamerOutputs: MutableMap<String, BarixConnection> = HashMap()
lateinit var udpreceiver: UDPReceiver
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
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.time.LocalDateTime
import codes.configKeys
import config
import database.QueueTable
import io.javalin.websocket.WsCloseStatus
import org.tinylog.Logger
@@ -126,8 +127,11 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
before { CheckUsers(it) }
ws("/ws") { ws ->
// WebSocket endpoint for home
//
ws.onConnect {
it.enableAutomaticPings()
}
ws.onMessage { wsMessageContext ->
try {
val cmd =
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") {
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") {
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") {
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") {
before { CheckUsers(it) }
}
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") {
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") {
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") {
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") {
before { CheckUsers(it) }
}
path("setting.html") {
before { CheckUsers(it) }
}
path("streamerstatus.html") {
before { CheckUsers(it) }
}
path("timer.html") {
before { CheckUsers(it) }
}
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") {
//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.cookie("aas-user")
if (user == null) {
ctx.redirect("login.html")
return null
}
val foundUser = userlist.find { it.first == user }
if (foundUser == null) {
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? {
if (ValidString(zonename)) {
val bz = db.broadcastDB.List.find { it.description == zonename }