mirror of
https://github.com/zhoukk/rtsp2web.git
synced 2025-09-26 20:21:11 +08:00
feat: add webrtc ice config
This commit is contained in:
@@ -10,7 +10,10 @@ import (
|
||||
|
||||
func main() {
|
||||
|
||||
r2w := rtsp2web.NewRtsp2Web()
|
||||
cfg := rtsp2web.Config{}
|
||||
// cfg.WebRtc.WebRTCPortMin = 50010
|
||||
// cfg.WebRtc.WebRTCPortMax = 50020
|
||||
r2w := rtsp2web.NewRtsp2Web(cfg)
|
||||
|
||||
r2w.AddStream("live", "rtsp://192.168.1.3:554/live", false)
|
||||
r2w.Start("live")
|
||||
|
22
rtsp2web.go
22
rtsp2web.go
@@ -18,6 +18,16 @@ import (
|
||||
"golang.org/x/net/websocket"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
WebRtc struct {
|
||||
ICEServers []string
|
||||
ICEUsername string
|
||||
ICECredential string
|
||||
WebRTCPortMin uint16
|
||||
WebRTCPortMax uint16
|
||||
}
|
||||
}
|
||||
|
||||
type Viewer struct {
|
||||
c chan av.Packet
|
||||
}
|
||||
@@ -33,6 +43,7 @@ type Stream struct {
|
||||
}
|
||||
|
||||
type Rtsp2Web struct {
|
||||
config Config
|
||||
streams map[string]Stream
|
||||
lock sync.RWMutex
|
||||
}
|
||||
@@ -198,8 +209,9 @@ func (g *Rtsp2Web) Start(id string) {
|
||||
}
|
||||
}
|
||||
|
||||
func NewRtsp2Web() *Rtsp2Web {
|
||||
func NewRtsp2Web(config Config) *Rtsp2Web {
|
||||
return &Rtsp2Web{
|
||||
config: config,
|
||||
streams: make(map[string]Stream),
|
||||
}
|
||||
}
|
||||
@@ -222,7 +234,13 @@ func (g *Rtsp2Web) WebRtcHander() http.Handler {
|
||||
|
||||
sdp, _ := ioutil.ReadAll(r.Body)
|
||||
|
||||
muxerWebRTC := webrtc.NewMuxer(webrtc.Options{})
|
||||
muxerWebRTC := webrtc.NewMuxer(webrtc.Options{
|
||||
ICEServers: g.config.WebRtc.ICEServers,
|
||||
ICEUsername: g.config.WebRtc.ICEUsername,
|
||||
ICECredential: g.config.WebRtc.ICECredential,
|
||||
PortMin: g.config.WebRtc.WebRTCPortMin,
|
||||
PortMax: g.config.WebRtc.WebRTCPortMax,
|
||||
})
|
||||
answer, err := muxerWebRTC.WriteHeader(codecs, string(sdp))
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
|
Reference in New Issue
Block a user