add audio support, trying to manage MSD device

This commit is contained in:
Artem
2024-11-03 11:44:40 +01:00
parent 68ba48a3a2
commit 1b60f43df1
22 changed files with 1059 additions and 263 deletions

View File

@@ -7,9 +7,11 @@ import (
"net/http"
"rkkvm/config"
"rkkvm/http/hw/rtc"
"rkkvm/http/reqrsp"
"strconv"
"github.com/gin-gonic/gin"
"github.com/pion/webrtc/v4"
log "github.com/sirupsen/logrus"
)
@@ -136,23 +138,29 @@ func MjpegHandler(c *gin.Context) {
}
}
func WebRTCHandshake(c *gin.Context) {
str, err := c.GetRawData()
if err != nil {
c.String(http.StatusBadRequest, err.Error())
func WebRTCPeerConnect(c *gin.Context) {
var offer webrtc.SessionDescription
if err := c.ShouldBindJSON(&offer); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid offer"})
return
}
log.Debugf("Client session description: %s", string(str))
r := rtc.Get()
localSession, err := r.Handshake(string(str))
peer, err := rtc.NewPeer()
if err != nil {
c.String(http.StatusBadRequest, err.Error())
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to create peer connection"})
return
}
c.String(http.StatusOK, localSession)
answer, err := rtc.Get().AddPeer(peer, offer)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to add peer"})
return
}
c.JSON(http.StatusOK, reqrsp.NanoKVMRsp{
Msg: reqrsp.MsgSuccess,
Data: answer,
})
}
func WebRTCSettings(c *gin.Context) {