Skip to content

Commit

Permalink
Merge pull request #128 from chriswiggins/ice-servers-port-minmax
Browse files Browse the repository at this point in the history
Adds ability to set STUN/TURN, and WebRTC Min/Max Ports
  • Loading branch information
allenporter authored Mar 21, 2022
2 parents 05b184b + 21fcde0 commit d7f2dd0
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 18 deletions.
40 changes: 23 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion apiHTTPWebRTC.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()})
Expand Down
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
35 changes: 35 additions & 0 deletions storageServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
}
5 changes: 5 additions & 0 deletions storageStruct.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d7f2dd0

Please sign in to comment.