Skip to content

Commit

Permalink
feat(config): added endpoint configs
Browse files Browse the repository at this point in the history
  • Loading branch information
Roverr committed Jan 30, 2020
1 parent 6bd2d53 commit 0950ee3
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 25 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ docker run -p 80:8080 roverr/rtsp-stream:1
```
## Easy API

There are 2 endpoint to call
There are 4 endpoints that are fully configurable to call
* `/start` - to start transcoding of a stream
* `/stream/id/*fileId` - static endpoint to serve video files for your browser
* `/list` - lists streams already known
* `/stop` - stops and removes a given stream

[Read full documentation on API](docs/api/README.md).

Expand Down
30 changes: 18 additions & 12 deletions core/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,32 @@ type Process struct {

// Specification describes the application context settings
type Specification struct {
Debug bool `envconfig:"DEBUG" default:"false"` // Indicates if debug log should be enabled or not
Port int `envconfig:"PORT" default:"8080"` // Port that the application listens on
ListEndpoint bool `envconfig:"LIST_ENDPOINT" default:"false"` // Turns on / off the stream listing endpoint feature
Debug bool `envconfig:"DEBUG" default:"false"` // Indicates if debug log should be enabled or not
Port int `envconfig:"PORT" default:"8080"` // Port that the application listens on

CORS
Blacklist
Auth
Process
ProcessLogging
EndpointSetting
EndpointYML
}

// EndpointSetting describes how endpoints will work in the application
// EndpointSetting describes how a given endpoint works in the application
type EndpointSetting struct {
Enabled bool `yml:"enabled"`
Secret string `yml:"secret"`
}

// EndpointYML describes the yml structure used
type EndpointYML struct {
Version string `yaml:"version"`
Endpoints map[string]struct {
Enabled bool `yml:"enabled"`
Secret string `yml:"secret"`
}
Endpoints struct {
Start EndpointSetting `yaml:"start"`
Stop EndpointSetting `yaml:"stop"`
List EndpointSetting `yaml:"list"`
Static EndpointSetting `yaml:"static"`
} `yaml:"endpoints"`
}

// InitConfig is to initalise the config
Expand All @@ -85,9 +92,8 @@ func InitConfig() *Specification {
s.KeepFiles = true
s.Process.Audio = false
s.ProcessLogging.Enabled = true
s.ListEndpoint = true
}
setting := EndpointSetting{}
setting := EndpointYML{}
dat, err := ioutil.ReadFile("rtsp-stream.yml")
if err != nil {
log.Fatalf("error: %v", err)
Expand All @@ -96,6 +102,6 @@ func InitConfig() *Specification {
if err != nil {
log.Fatalf("error: %v", err)
}
s.EndpointSetting = setting
s.EndpointYML = setting
return &s
}
12 changes: 7 additions & 5 deletions docs/configuration/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Configuration

This page describes the enviroment settings the application accepts. You can find the API configuration [here.](../api)

You can configure the following settings in the application with environment variables:

### Transcoding related configuration:
Expand All @@ -16,6 +18,11 @@ Default: `./videos`<br/>
Type: string<br/>
Description: Sub directory to store the video chunks<br/>

#### RTSP_STREAM_AUDIO_ENABLED
Default: `true`<br/>
Type: boolean<br/>
Description: Indicates if transcoding will also include audio or not<br/>

#### RTSP_STREAM_KEEP_FILES
Default: `false`<br/>
Type: bool<br/>
Expand Down Expand Up @@ -65,11 +72,6 @@ Default: `false`<br/>
Type: bool<br/>
Description: Turns on / off debug features<br/>

#### RTSP_STREAM_LIST_ENDPOINT
Default: `false`<br/>
Type: bool<br/>
Description: Turns on / off the `/list` endpoint<br/>

#### RTSP_STREAM_BLACKLIST_ENABLED
Default: `true`<br/>
Type: bool<br/>
Expand Down
2 changes: 1 addition & 1 deletion docs/debugging/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ autostart=true
autorestart=true
stderr_logfile=/var/log/rtsp-stream.err.log
stdout_logfile=/var/log/rtsp-stream.out.log
environment=RTSP_STREAM_LIST_ENDPOINT=true
environment=RTSP_STREAM_DEBUG=true
[program:rtsp-stream-ui]
command=http-server -p 80 /ui/
autostart=true
Expand Down
22 changes: 16 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,25 @@ func main() {
fileServer := http.FileServer(http.Dir(config.StoreDir))
router := httprouter.New()
controllers := core.NewController(config, fileServer)
if config.ListEndpoint {
router.GET("/list", controllers.ListStreamHandler)
}
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
w.WriteHeader(http.StatusOK)
})
router.POST("/start", controllers.StartStreamHandler)
router.GET("/stream/*filepath", controllers.StaticFileHandler)
router.POST("/stop", controllers.StopStreamHandler)
if config.EndpointYML.Endpoints.List.Enabled {
router.GET("/list", controllers.ListStreamHandler)
logrus.Infoln("list endpoint enabled | MainProcess")
}
if config.EndpointYML.Endpoints.Start.Enabled {
router.POST("/start", controllers.StartStreamHandler)
logrus.Infoln("start endpoint enabled | MainProcess")
}
if config.EndpointYML.Endpoints.Static.Enabled {
router.GET("/stream/*filepath", controllers.StaticFileHandler)
logrus.Infoln("static endpoint enabled | MainProcess")
}
if config.EndpointYML.Endpoints.Stop.Enabled {
router.POST("/stop", controllers.StopStreamHandler)
logrus.Infoln("stop endpoint enabled | MainProcess")
}
done := controllers.ExitPreHook()
handler := cors.AllowAll().Handler(router)
if config.CORS.Enabled {
Expand Down

0 comments on commit 0950ee3

Please sign in to comment.