优化文件
This commit is contained in:
@@ -9,7 +9,6 @@ import ink.snowflake.server.route.ImageAnalytics
|
||||
import ink.snowflake.server.route.RemoteDebug
|
||||
import ink.snowflake.server.route.VideoAnalytics
|
||||
import ink.snowflake.server.route.VideoAnalyticsJetson
|
||||
import ink.snowflake.server.route.mainFunc
|
||||
import ink.snowflake.server.utils.AppConfig
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.tomcat.jakarta.*
|
||||
@@ -54,8 +53,6 @@ fun Application.module() {
|
||||
// 设置-WebSocket
|
||||
configureSockets()
|
||||
|
||||
// 业务-首页导航
|
||||
mainFunc()
|
||||
// 业务-用户信息相关操作
|
||||
User(appConfig)
|
||||
// 业务-聊天
|
||||
|
||||
@@ -32,7 +32,6 @@ object ImageDao {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun getImageList(name: String): List<ImageAnalyticsRequest> {
|
||||
return transaction {
|
||||
ImageTable.selectAll()
|
||||
|
||||
@@ -8,6 +8,7 @@ import io.ktor.server.auth.*
|
||||
import io.ktor.server.routing.*
|
||||
import io.ktor.server.request.*
|
||||
import io.ktor.server.response.*
|
||||
import kotlin.text.isNullOrEmpty
|
||||
|
||||
fun Application.ImageAnalytics() {
|
||||
routing {
|
||||
@@ -18,16 +19,6 @@ fun Application.ImageAnalytics() {
|
||||
call.respond(BaseResponse(data = ImageDao.insertImageAnalyticsData(request)))
|
||||
}
|
||||
authenticate {
|
||||
// 拍照保存为图片 并且调用Python程序进行分析
|
||||
get("/takePhoto") {
|
||||
val camera = call.request.queryParameters["cameraId"]
|
||||
if (camera.isNullOrEmpty()) {
|
||||
call.respond(BaseResponse(status = false, message = "摄像头名称不能为空", data = null))
|
||||
return@get
|
||||
}
|
||||
stopHLSStream(camera)
|
||||
call.respond(BaseResponse(message = "摄像头流已停止", data = null))
|
||||
}
|
||||
// 获取已分析图片列表
|
||||
get("/getImageList") {
|
||||
val name = call.parameters["name"]
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
package ink.snowflake.server.route
|
||||
|
||||
import com.google.gson.Gson
|
||||
import ink.snowflake.server.model.response.BaseResponse
|
||||
import ink.snowflake.server.model.response.DeviceItem
|
||||
import ink.snowflake.server.utils.runCommand
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.engine.cio.*
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.response.*
|
||||
import io.ktor.server.routing.*
|
||||
import java.io.BufferedReader
|
||||
import java.io.InputStreamReader
|
||||
import io.ktor.client.plugins.auth.*
|
||||
import io.ktor.client.plugins.auth.providers.*
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.client.statement.*
|
||||
import io.ktor.server.auth.*
|
||||
import io.ktor.server.http.content.*
|
||||
import java.io.File
|
||||
|
||||
fun Application.mainFunc() {
|
||||
routing {
|
||||
get("/") {
|
||||
// call.respondFile(File("src/main/resources/page/html/login.html"))
|
||||
// call.respondRedirect("html/login.html")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,42 +34,9 @@ import java.time.format.DateTimeFormatter
|
||||
import java.util.*
|
||||
|
||||
val clients = Collections.synchronizedList<WebSocketServerSession>(ArrayList()) // 线程安全的客户端列表
|
||||
var aiState = "等待分析任务中"
|
||||
|
||||
fun Application.VideoAnalytics() {
|
||||
routing {
|
||||
// 实时发送AI状态
|
||||
webSocket("/handleState") { // WebSocket 路由
|
||||
clients.add(this) // 添加当前连接的客户端
|
||||
send(aiState) // 向客户端发送连接成功消息
|
||||
try {
|
||||
incoming.consumeEach { frame -> // 持续接收消息
|
||||
when (frame) {
|
||||
is Frame.Text -> {
|
||||
aiState = frame.readText() // 更新状态
|
||||
broadcastMessage(aiState) // 使用封装的方法广播消息
|
||||
}
|
||||
|
||||
is Frame.Close -> {
|
||||
println("Closed")
|
||||
clients.remove(this)
|
||||
close() // 确保关闭 WebSocket 连接
|
||||
return@consumeEach
|
||||
}
|
||||
// 其他消息类型的处理
|
||||
is Frame.Binary -> TODO() // 处理二进制消息
|
||||
is Frame.Ping -> TODO() // 处理 Ping 消息
|
||||
is Frame.Pong -> TODO() // 处理 Pong 消息
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
// 处理接收消息时的异常
|
||||
close(CloseReason(CloseReason.Codes.NORMAL, "Client disconnected"))
|
||||
e.printStackTrace()
|
||||
} finally {
|
||||
clients.remove(this) // 确保在连接关闭时移除客户端
|
||||
}
|
||||
}
|
||||
route("/api/iva") {
|
||||
// 上传分析结果
|
||||
post("/saveVideoAnalyticsData") {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
|
||||
var aiState = "等待分析任务中"
|
||||
// 实时发送AI状态
|
||||
webSocket("/handleState") { // WebSocket 路由
|
||||
clients.add(this) // 添加当前连接的客户端
|
||||
send(aiState) // 向客户端发送连接成功消息
|
||||
try {
|
||||
incoming.consumeEach { frame -> // 持续接收消息
|
||||
when (frame) {
|
||||
is Frame.Text -> {
|
||||
aiState = frame.readText() // 更新状态
|
||||
broadcastMessage(aiState) // 使用封装的方法广播消息
|
||||
}
|
||||
|
||||
is Frame.Close -> {
|
||||
println("Closed")
|
||||
clients.remove(this)
|
||||
close() // 确保关闭 WebSocket 连接
|
||||
return@consumeEach
|
||||
}
|
||||
// 其他消息类型的处理
|
||||
is Frame.Binary -> TODO() // 处理二进制消息
|
||||
is Frame.Ping -> TODO() // 处理 Ping 消息
|
||||
is Frame.Pong -> TODO() // 处理 Pong 消息
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
// 处理接收消息时的异常
|
||||
close(CloseReason(CloseReason.Codes.NORMAL, "Client disconnected"))
|
||||
e.printStackTrace()
|
||||
} finally {
|
||||
clients.remove(this) // 确保在连接关闭时移除客户端
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 拍照保存为图片 并且调用Python程序进行分析
|
||||
//get("/takePhoto") {
|
||||
// val camera = call.request.queryParameters["cameraId"]
|
||||
// if (camera.isNullOrEmpty()) {
|
||||
// call.respond(BaseResponse(status = false, message = "摄像头名称不能为空", data = null))
|
||||
// return@get
|
||||
// }
|
||||
// stopHLSStream(camera)
|
||||
// call.respond(BaseResponse(message = "摄像头流已停止", data = null))
|
||||
//}
|
||||
Reference in New Issue
Block a user