diff --git a/README.md b/README.md index 0c50f0e..4492535 100644 --- a/README.md +++ b/README.md @@ -61,15 +61,20 @@ $ docker run --name rtsp-to-web \ ### Server settings ```text -debug - enable debug output -log_level - log level (trace, debug, info, warning, error, fatal, or panic) - -http_demo - serve static files -http_debug - debug http api server -http_login - http auth login -http_password - http auth password -http_port - http server port -http_dir - path to serve static files from +debug - enable debug output +log_level - log level (trace, debug, info, warning, error, fatal, or panic) + +http_demo - serve static files +http_debug - debug http api server +http_login - http auth login +http_password - http auth password +http_port - http server port +http_dir - path to serve static files from +ice_servers - array of servers to use for STUN/TURN +ice_username - username to use for STUN/TURN +ice_credential - credential to use for STUN/TURN +webrtc_port_min - minimum WebRTC port to use (UDP) +webrtc_port_max - maximum WebRTC port to use (UDP) https https_auto_tls @@ -78,24 +83,24 @@ https_cert https_key https_port -rtsp_port - rtsp server port +rtsp_port - rtsp server port ``` ### Stream settings ```text -name - stream name +name - stream name ``` ### Channel settings ```text -name - channel name -url - channel rtsp url -on_demand - stream mode static (run any time) or ondemand (run only has viewers) -debug - enable debug output (RTSP client) -audio - enable audio -status - default stream status +name - channel name +url - channel rtsp url +on_demand - stream mode static (run any time) or ondemand (run only has viewers) +debug - enable debug output (RTSP client) +audio - enable audio +status - default stream status ``` #### Authorization play video @@ -138,6 +143,7 @@ file.php need response json "http_login": "demo", "http_password": "demo", "http_port": ":8083", + "ice_servers": ["stun:stun.l.google.com:19302"], "rtsp_port": ":5541" }, "streams": { diff --git a/apiHTTPWebRTC.go b/apiHTTPWebRTC.go index 3864aeb..5976437 100644 --- a/apiHTTPWebRTC.go +++ b/apiHTTPWebRTC.go @@ -33,7 +33,7 @@ func HTTPAPIServerStreamWebRTC(c *gin.Context) { }).Errorln(err.Error()) return } - muxerWebRTC := webrtc.NewMuxer(webrtc.Options{}) + muxerWebRTC := webrtc.NewMuxer(webrtc.Options{ICEServers: Storage.ServerICEServers(), ICEUsername: Storage.ServerICEUsername(), ICECredential: Storage.ServerICECredential(), PortMin: Storage.ServerWebRTCPortMin(), PortMax: Storage.ServerWebRTCPortMax()}) answer, err := muxerWebRTC.WriteHeader(codecs, c.PostForm("data")) if err != nil { c.IndentedJSON(400, Message{Status: 0, Payload: err.Error()}) diff --git a/config.json b/config.json index 9ac1457..65067f7 100644 --- a/config.json +++ b/config.json @@ -13,6 +13,7 @@ "https_cert": "server.crt", "https_key": "server.key", "https_port": ":443", + "ice_servers": ["stun:stun.l.google.com:19302"], "log_level": "debug", "rtsp_port": ":5541", "token": { diff --git a/storageServer.go b/storageServer.go index fa7b655..9c5263b 100644 --- a/storageServer.go +++ b/storageServer.go @@ -112,6 +112,27 @@ func (obj *StorageST) ServerHTTPSKey() string { return obj.Server.HTTPSKey } +// ServerICEServers read ICE servers +func (obj *StorageST) ServerICEServers() []string { + obj.mutex.Lock() + defer obj.mutex.Unlock() + return obj.Server.ICEServers +} + +// ServerICEServers read ICE username +func (obj *StorageST) ServerICEUsername() string { + obj.mutex.Lock() + defer obj.mutex.Unlock() + return obj.Server.ICEUsername +} + +// ServerICEServers read ICE credential +func (obj *StorageST) ServerICECredential() string { + obj.mutex.Lock() + defer obj.mutex.Unlock() + return obj.Server.ICECredential +} + //ServerTokenEnable read HTTPS Key options func (obj *StorageST) ServerTokenEnable() bool { obj.mutex.RLock() @@ -125,3 +146,17 @@ func (obj *StorageST) ServerTokenBackend() string { defer obj.mutex.RUnlock() return obj.Server.Token.Backend } + +// ServerWebRTCPortMin read WebRTC Port Min +func (obj *StorageST) ServerWebRTCPortMin() uint16 { + obj.mutex.Lock() + defer obj.mutex.Unlock() + return obj.Server.WebRTCPortMin +} + +// ServerWebRTCPortMax read WebRTC Port Max +func (obj *StorageST) ServerWebRTCPortMax() uint16 { + obj.mutex.Lock() + defer obj.mutex.Unlock() + return obj.Server.WebRTCPortMax +} diff --git a/storageStruct.go b/storageStruct.go index 4faf464..ee91a8e 100644 --- a/storageStruct.go +++ b/storageStruct.go @@ -67,7 +67,12 @@ type ServerST struct { HTTPSKey string `json:"https_key" groups:"api,config"` HTTPSAutoTLSEnable bool `json:"https_auto_tls" groups:"api,config"` HTTPSAutoTLSName string `json:"https_auto_tls_name" groups:"api,config"` + ICEServers []string `json:"ice_servers" groups:"api,config"` + ICEUsername string `json:"ice_username" groups:"api,config"` + ICECredential string `json:"ice_credential" groups:"api,config"` Token Token `json:"token,omitempty" groups:"api,config"` + WebRTCPortMin uint16 `json:"webrtc_port_min" groups:"api,config"` + WebRTCPortMax uint16 `json:"webrtc_port_max" groups:"api,config"` } //Token auth