Commit 01/08/2025
This commit is contained in:
2
.idea/inspectionProfiles/Project_Default.xml
generated
2
.idea/inspectionProfiles/Project_Default.xml
generated
@@ -7,9 +7,11 @@
|
|||||||
<inspection_tool class="GrazieInspection" enabled="false" level="GRAMMAR_ERROR" enabled_by_default="false" />
|
<inspection_tool class="GrazieInspection" enabled="false" level="GRAMMAR_ERROR" enabled_by_default="false" />
|
||||||
<inspection_tool class="LanguageDetectionInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
<inspection_tool class="LanguageDetectionInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||||
<inspection_tool class="LocalVariableName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
<inspection_tool class="LocalVariableName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="LoggingPlaceholderCountMatchesArgumentCount" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||||
<inspection_tool class="MethodNameSameAsClassName" enabled="false" level="WARNING" enabled_by_default="false" />
|
<inspection_tool class="MethodNameSameAsClassName" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||||
<inspection_tool class="PrivatePropertyName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
<inspection_tool class="PrivatePropertyName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||||
<inspection_tool class="PropertyName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
<inspection_tool class="PropertyName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="SafeVarargsDetector" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||||
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
|
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
|
||||||
<option name="processCode" value="true" />
|
<option name="processCode" value="true" />
|
||||||
<option name="processLiterals" value="true" />
|
<option name="processLiterals" value="true" />
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
||||||
<orderEntry type="library" name="net.java.dev.jna" level="project" />
|
<orderEntry type="library" name="net.java.dev.jna" level="project" />
|
||||||
<orderEntry type="library" name="io.javalin.bundle" level="project" />
|
|
||||||
<orderEntry type="library" name="java.websocket.Java.WebSocket" level="project" />
|
<orderEntry type="library" name="java.websocket.Java.WebSocket" level="project" />
|
||||||
|
<orderEntry type="library" name="io.javalin.bundle" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import audio.AudioUtility
|
import audio.AudioUtility
|
||||||
import audio.OpusStreamReceiver
|
import audio.OpusStreamReceiver
|
||||||
import somecodes.Codes.Companion.ValidString
|
import somecodes.Codes.Companion.ValidString
|
||||||
|
import web.webApp
|
||||||
import zello.ZelloClient
|
import zello.ZelloClient
|
||||||
import zello.ZelloEvent
|
import zello.ZelloEvent
|
||||||
|
|
||||||
@@ -23,6 +24,9 @@ fun main() {
|
|||||||
|
|
||||||
val o = OpusStreamReceiver(audioID)
|
val o = OpusStreamReceiver(audioID)
|
||||||
|
|
||||||
|
val w = webApp("0.0.0.0",3030, javafx.util.Pair("admin","admin1234"))
|
||||||
|
w.Start()
|
||||||
|
|
||||||
val z = ZelloClient.fromConsumerZello("gtcdevice01","GtcDev2025")
|
val z = ZelloClient.fromConsumerZello("gtcdevice01","GtcDev2025")
|
||||||
z.Start(object : ZelloEvent {
|
z.Start(object : ZelloEvent {
|
||||||
override fun onChannelStatus(
|
override fun onChannelStatus(
|
||||||
|
|||||||
122
src/web/webApp.java
Normal file
122
src/web/webApp.java
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
package web;
|
||||||
|
|
||||||
|
import io.javalin.Javalin;
|
||||||
|
import javafx.util.Pair;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static io.javalin.apibuilder.ApiBuilder.*;
|
||||||
|
|
||||||
|
public class webApp {
|
||||||
|
private final Javalin app;
|
||||||
|
private final String listenAddress;
|
||||||
|
private final int listenPort;
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(webApp.class);
|
||||||
|
private final Map<String, String> usermap = new HashMap<>();
|
||||||
|
public webApp(String listenAddress, int listenPort, Pair<String, String>... users) {
|
||||||
|
this.listenAddress = listenAddress;
|
||||||
|
this.listenPort = listenPort;
|
||||||
|
if (users != null){
|
||||||
|
for (Pair<String, String> user : users) {
|
||||||
|
this.usermap.put(user.getKey(), user.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
app = Javalin.create(config -> {
|
||||||
|
config.useVirtualThreads = true; // Enable virtual threads for better performance
|
||||||
|
config.staticFiles.add("/");
|
||||||
|
config.router.apiBuilder(()->{
|
||||||
|
path("/", () -> get(ctx -> {
|
||||||
|
if (ctx.sessionAttribute("user") == null) {
|
||||||
|
ctx.redirect("/index.html");
|
||||||
|
} else {
|
||||||
|
ctx.redirect("/pocreceiver.html");
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
path("/index.html", ()-> {
|
||||||
|
before( ctx ->{
|
||||||
|
ctx.sessionAttribute("user", null); // Clear user session on index page
|
||||||
|
});
|
||||||
|
post(ctx-> {
|
||||||
|
var username = ctx.formParam("username");
|
||||||
|
var password = ctx.formParam("password");
|
||||||
|
var xx = usermap.get(username);
|
||||||
|
if (xx != null && xx.equals(password)) {
|
||||||
|
ctx.sessionAttribute("user", username);
|
||||||
|
ctx.redirect("/pocreceiver.html");
|
||||||
|
} else {
|
||||||
|
ctx.result("Invalid username or password");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
path("/pocreceiver.html", ()->{
|
||||||
|
before(ctx -> {
|
||||||
|
if (ctx.sessionAttribute("user") == null) {
|
||||||
|
ctx.redirect("/index.html");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ws("/ws", wshandler -> wshandler.onMessage(wsMessageContext -> {
|
||||||
|
// Handle incoming WebSocket messages
|
||||||
|
String message = wsMessageContext.message();
|
||||||
|
// Process the message as needed
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
path("/prerecordedbroadcast.html", ()->{
|
||||||
|
before(ctx -> {
|
||||||
|
if (ctx.sessionAttribute("user") == null) {
|
||||||
|
ctx.redirect("/index.html");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ws("/ws", wshandler -> wshandler.onMessage(wsMessageContext -> {
|
||||||
|
// Handle incoming WebSocket messages
|
||||||
|
String message = wsMessageContext.message();
|
||||||
|
// Process the message as needed
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
path("/setting.html", () ->{
|
||||||
|
before(ctx -> {
|
||||||
|
if (ctx.sessionAttribute("user") == null) {
|
||||||
|
ctx.redirect("/index.html");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ws("/ws", wshandler -> wshandler.onMessage(wsMessageContext -> {
|
||||||
|
// Handle incoming WebSocket messages
|
||||||
|
String message = wsMessageContext.message();
|
||||||
|
// Process the message as needed
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start the web application.
|
||||||
|
*/
|
||||||
|
public boolean Start(){
|
||||||
|
try{
|
||||||
|
app.start(listenAddress, listenPort);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e){
|
||||||
|
logger.error("webApp start failed", e.getMessage());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop the web application.
|
||||||
|
*/
|
||||||
|
public void Stop(){
|
||||||
|
try{
|
||||||
|
app.stop();
|
||||||
|
logger.info("webApp stopped");
|
||||||
|
} catch (Exception e){
|
||||||
|
logger.error("webApp stop failed", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user