新增ws连接及webrtc连接

This commit is contained in:
zyj
2025-09-02 16:20:33 +08:00
parent 7afd1fdfcb
commit 79361c5857
3 changed files with 28 additions and 30 deletions

View File

@@ -10,6 +10,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/gorilla/websocket"
"github.com/pion/webrtc/v4"
)
func main() {
@@ -21,13 +22,31 @@ func main() {
app := gin.Default()
router.Init(app)
u := url.URL{Scheme: "ws", Host: "127.0.0.1:6996", Path: "/ws"}
u := url.URL{Scheme: "ws", Host: "106.12.33.188:6996", Path: "/ws"}
log.Printf("connecting to %s", u.String())
c, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
if err != nil {
log.Fatal("dial:", err)
}
defer c.Close()
// 配置使用自建 STUN 服务器
config := webrtc.Configuration{
ICEServers: []webrtc.ICEServer{
{
URLs: []string{"stun:106.12.33.188:3478"}, // 使用自建 STUN 服务器
},
},
}
// 创建 PeerConnection
peerConnection, err := webrtc.NewPeerConnection(config)
if err != nil {
log.Println(err)
return
}
defer peerConnection.Close()
t := "Hello"
c.WriteMessage(websocket.TextMessage, []byte(t))
app.Run(":" + strconv.Itoa(appConfig.Port))