新增ws连接及webrtc连接
This commit is contained in:
21
cmd/main.go
21
cmd/main.go
@@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
|
"github.com/pion/webrtc/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -21,13 +22,31 @@ func main() {
|
|||||||
|
|
||||||
app := gin.Default()
|
app := gin.Default()
|
||||||
router.Init(app)
|
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())
|
log.Printf("connecting to %s", u.String())
|
||||||
c, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
|
c, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("dial:", err)
|
log.Fatal("dial:", err)
|
||||||
}
|
}
|
||||||
defer c.Close()
|
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"
|
t := "Hello"
|
||||||
c.WriteMessage(websocket.TextMessage, []byte(t))
|
c.WriteMessage(websocket.TextMessage, []byte(t))
|
||||||
app.Run(":" + strconv.Itoa(appConfig.Port))
|
app.Run(":" + strconv.Itoa(appConfig.Port))
|
||||||
|
|||||||
@@ -7,28 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type AppConfig struct {
|
type AppConfig struct {
|
||||||
Port int `yaml:"port"`
|
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"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadConfig() (*AppConfig, error) {
|
func LoadConfig() (*AppConfig, error) {
|
||||||
|
|||||||
14
go.mod
14
go.mod
@@ -66,23 +66,23 @@ require (
|
|||||||
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
|
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
|
||||||
github.com/pion/datachannel v1.5.10 // indirect
|
github.com/pion/datachannel v1.5.10 // indirect
|
||||||
github.com/pion/dtls/v2 v2.2.12 // 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/ice/v4 v4.0.10 // indirect
|
||||||
github.com/pion/interceptor v0.1.40 // 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/mdns/v2 v2.0.7 // indirect
|
||||||
github.com/pion/randutil v0.1.0 // indirect
|
github.com/pion/randutil v0.1.0 // indirect
|
||||||
github.com/pion/rtcp v1.2.15 // 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/sctp v1.8.39 // indirect
|
||||||
github.com/pion/sdp/v3 v3.0.13 // indirect
|
github.com/pion/sdp/v3 v3.0.15 // indirect
|
||||||
github.com/pion/srtp/v3 v3.0.6 // indirect
|
github.com/pion/srtp/v3 v3.0.7 // indirect
|
||||||
github.com/pion/stun v0.6.1 // indirect
|
github.com/pion/stun v0.6.1 // indirect
|
||||||
github.com/pion/stun/v3 v3.0.0 // indirect
|
github.com/pion/stun/v3 v3.0.0 // indirect
|
||||||
github.com/pion/transport/v2 v2.2.10 // indirect
|
github.com/pion/transport/v2 v2.2.10 // indirect
|
||||||
github.com/pion/transport/v3 v3.0.7 // indirect
|
github.com/pion/transport/v3 v3.0.7 // indirect
|
||||||
github.com/pion/turn/v4 v4.0.2 // indirect
|
github.com/pion/turn/v4 v4.1.1 // indirect
|
||||||
github.com/pion/webrtc/v4 v4.1.2 // indirect
|
github.com/pion/webrtc/v4 v4.1.4 // indirect
|
||||||
github.com/prometheus/client_golang v1.22.0 // indirect
|
github.com/prometheus/client_golang v1.22.0 // indirect
|
||||||
github.com/prometheus/client_model v0.6.2 // indirect
|
github.com/prometheus/client_model v0.6.2 // indirect
|
||||||
github.com/prometheus/common v0.64.0 // indirect
|
github.com/prometheus/common v0.64.0 // indirect
|
||||||
|
|||||||
Reference in New Issue
Block a user