feat:桌面共享UI/逻辑优化

This commit is contained in:
MatrixSeven
2025-09-18 18:43:54 +08:00
parent 2fc478e889
commit 08f9d50e66
23 changed files with 1521 additions and 562 deletions

View File

@@ -10,6 +10,7 @@ import (
type Handler struct {
webrtcService *services.WebRTCService
turnService *services.TurnService
}
func NewHandler() *Handler {
@@ -18,6 +19,11 @@ func NewHandler() *Handler {
}
}
// SetTurnService 设置TURN服务实例
func (h *Handler) SetTurnService(turnService *services.TurnService) {
h.turnService = turnService
}
// HandleWebRTCWebSocket 处理WebRTC信令WebSocket连接
func (h *Handler) HandleWebRTCWebSocket(w http.ResponseWriter, r *http.Request) {
h.webrtcService.HandleWebSocket(w, r)
@@ -105,3 +111,101 @@ func (h *Handler) GetRoomStatusHandler(w http.ResponseWriter, r *http.Request) {
status := h.webrtcService.GetRoomStatus(code)
json.NewEncoder(w).Encode(status)
}
// TurnStatsHandler 获取TURN服务器统计信息API
func (h *Handler) TurnStatsHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
if r.Method != http.MethodGet {
json.NewEncoder(w).Encode(map[string]interface{}{
"success": false,
"message": "方法不允许",
})
return
}
if h.turnService == nil {
json.NewEncoder(w).Encode(map[string]interface{}{
"success": false,
"message": "TURN服务器未启用",
})
return
}
stats := h.turnService.GetStats()
response := map[string]interface{}{
"success": true,
"data": stats,
}
json.NewEncoder(w).Encode(response)
}
// TurnConfigHandler 获取TURN服务器配置信息API用于前端WebRTC配置
func (h *Handler) TurnConfigHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
if r.Method != http.MethodGet {
json.NewEncoder(w).Encode(map[string]interface{}{
"success": false,
"message": "方法不允许",
})
return
}
if h.turnService == nil || !h.turnService.IsRunning() {
json.NewEncoder(w).Encode(map[string]interface{}{
"success": false,
"message": "TURN服务器未启用或未运行",
})
return
}
turnInfo := h.turnService.GetTurnServerInfo()
response := map[string]interface{}{
"success": true,
"data": turnInfo,
}
json.NewEncoder(w).Encode(response)
}
// AdminStatusHandler 获取服务器总体状态API
func (h *Handler) AdminStatusHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
if r.Method != http.MethodGet {
json.NewEncoder(w).Encode(map[string]interface{}{
"success": false,
"message": "方法不允许",
})
return
}
// 获取WebRTC服务状态
// 这里简化实际可以从WebRTC服务获取更多信息
webrtcStatus := map[string]interface{}{
"isRunning": true, // WebRTC服务总是运行的
}
// 获取TURN服务状态
var turnStatus interface{}
if h.turnService != nil {
turnStatus = h.turnService.GetStats()
} else {
turnStatus = map[string]interface{}{
"isRunning": false,
"message": "TURN服务器未启用",
}
}
response := map[string]interface{}{
"success": true,
"data": map[string]interface{}{
"webrtc": webrtcStatus,
"turn": turnStatus,
},
}
json.NewEncoder(w).Encode(response)
}