From 79361c5857b5cef0898cf263f5aba16a91a7b135 Mon Sep 17 00:00:00 2001 From: zyj <18107291228@163.com> Date: Tue, 2 Sep 2025 16:20:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Ews=E8=BF=9E=E6=8E=A5=E5=8F=8A?= =?UTF-8?q?webrtc=E8=BF=9E=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/main.go | 21 ++++++++++++++++++++- config/index.go | 23 +---------------------- go.mod | 14 +++++++------- 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index eb1dbf0..de5c59e 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -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)) diff --git a/config/index.go b/config/index.go index 6b245c0..15e448b 100644 --- a/config/index.go +++ b/config/index.go @@ -7,28 +7,7 @@ import ( ) type AppConfig struct { - Port int `yaml:"port"` - Database DatabaseConfig `yaml:"database"` - BitBrowser BitBrowserConfig `yaml:"bitBrowser"` - AdsPower AdsPowerConfig `yaml:"adsPower"` -} - -type DatabaseConfig struct { - Username string `yaml:"username"` - Password string `yaml:"password"` - Host string `yaml:"host"` - Port int `yaml:"port"` - Database string `yaml:"database"` -} - -type BitBrowserConfig struct { - ApiUrl string `yaml:"apiUrl"` - ApiToken string `yaml:"apiToken"` -} - -type AdsPowerConfig struct { - ApiUrl string `yaml:"apiUrl"` - ApiToken string `yaml:"apiToken"` + Port int `yaml:"port"` } func LoadConfig() (*AppConfig, error) { diff --git a/go.mod b/go.mod index fdaad79..e5e6126 100644 --- a/go.mod +++ b/go.mod @@ -66,23 +66,23 @@ require ( github.com/pelletier/go-toml/v2 v2.2.2 // indirect github.com/pion/datachannel v1.5.10 // indirect github.com/pion/dtls/v2 v2.2.12 // indirect - github.com/pion/dtls/v3 v3.0.6 // indirect + github.com/pion/dtls/v3 v3.0.7 // indirect github.com/pion/ice/v4 v4.0.10 // indirect github.com/pion/interceptor v0.1.40 // indirect - github.com/pion/logging v0.2.3 // indirect + github.com/pion/logging v0.2.4 // indirect github.com/pion/mdns/v2 v2.0.7 // indirect github.com/pion/randutil v0.1.0 // indirect github.com/pion/rtcp v1.2.15 // indirect - github.com/pion/rtp v1.8.19 // indirect + github.com/pion/rtp v1.8.21 // indirect github.com/pion/sctp v1.8.39 // indirect - github.com/pion/sdp/v3 v3.0.13 // indirect - github.com/pion/srtp/v3 v3.0.6 // indirect + github.com/pion/sdp/v3 v3.0.15 // indirect + github.com/pion/srtp/v3 v3.0.7 // indirect github.com/pion/stun v0.6.1 // indirect github.com/pion/stun/v3 v3.0.0 // indirect github.com/pion/transport/v2 v2.2.10 // indirect github.com/pion/transport/v3 v3.0.7 // indirect - github.com/pion/turn/v4 v4.0.2 // indirect - github.com/pion/webrtc/v4 v4.1.2 // indirect + github.com/pion/turn/v4 v4.1.1 // indirect + github.com/pion/webrtc/v4 v4.1.4 // indirect github.com/prometheus/client_golang v1.22.0 // indirect github.com/prometheus/client_model v0.6.2 // indirect github.com/prometheus/common v0.64.0 // indirect