直播:画质可选、只读 /live/info、弹幕 WS 透传;Nginx 弹幕路径
Made-with: Cursor
This commit is contained in:
50
server/pkg/weblive/info.go
Normal file
50
server/pkg/weblive/info.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package weblive
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// liveQualitySet 与前端开播档位一致;非法 query 回落为 high
|
||||
var liveQualitySet = map[string]struct{}{
|
||||
"source": {}, "high": {}, "mid": {}, "low": {},
|
||||
}
|
||||
|
||||
func normalizeQuality(q string) string {
|
||||
q = strings.TrimSpace(strings.ToLower(q))
|
||||
if _, ok := liveQualitySet[q]; ok {
|
||||
return q
|
||||
}
|
||||
return "high"
|
||||
}
|
||||
|
||||
func liveQualityList() []gin.H {
|
||||
return []gin.H{
|
||||
{"id": "source", "label": "原画(设备默认)"},
|
||||
{"id": "high", "label": "高清 720p"},
|
||||
{"id": "mid", "label": "标清 480p"},
|
||||
{"id": "low", "label": "流畅 360p"},
|
||||
}
|
||||
}
|
||||
|
||||
// handleLiveInfo 仅 GET、无请求体、不读 query;只输出直播状态与画质元数据
|
||||
func handleLiveInfo(c *gin.Context) {
|
||||
h, herr := getHub()
|
||||
live := false
|
||||
cq := ""
|
||||
if herr == nil {
|
||||
h.mu.RLock()
|
||||
live = h.publishConn != nil && h.pubPC != nil && len(h.forwarders) > 0
|
||||
cq = h.publishQuality
|
||||
h.mu.RUnlock()
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"live": live,
|
||||
"qualities": liveQualityList(),
|
||||
"current_quality": cq,
|
||||
"ts": time.Now().UnixMilli(),
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user