Take control over your live stream video by running it yourself. Streaming + chat out of the box.
HTML activitypubbroadcastingchatdecentralizedfederationfediversegolanghacktoberfesthlslivelivestreamowncastrtmpself-hostedstreaming-videovideo
Add server config admin endpoint (#207)
Gabe Kangasefdc004f3401
diff --git a/config/config.go b/config/config.goindex 46d5645727..1f80003b20 100644--- a/config/config.go+++ b/config/config.go@@ -22,7 +22,7 @@ type config struct {InstanceDetails InstanceDetails `yaml:"instanceDetails"`PrivateHLSPath string `yaml:"privateHLSPath"`PublicHLSPath string `yaml:"publicHLSPath"`- S3 s3 `yaml:"s3"`+ S3 S3 `yaml:"s3"`VersionInfo string `yaml:"-"`VideoSettings videoSettings `yaml:"videoSettings"`WebServerPort int `yaml:"webServerPort"`@@ -72,35 +72,35 @@ type StreamQuality struct {// Enable passthrough to copy the video and/or audio directly from the// incoming stream and disable any transcoding. It will ignore any of// the below settings.- IsVideoPassthrough bool `yaml:"videoPassthrough"`- IsAudioPassthrough bool `yaml:"audioPassthrough"`+ IsVideoPassthrough bool `yaml:"videoPassthrough" json:"videoPassthrough"`+ IsAudioPassthrough bool `yaml:"audioPassthrough" json:"audioPassthrough"`- VideoBitrate int `yaml:"videoBitrate"`- AudioBitrate int `yaml:"audioBitrate"`+ VideoBitrate int `yaml:"videoBitrate" json:"videoBitrate"`+ AudioBitrate int `yaml:"audioBitrate" json:"audioBitrate"`// Set only one of these in order to keep your current aspect ratio.// Or set neither to not scale the video.- ScaledWidth int `yaml:"scaledWidth"`- ScaledHeight int `yaml:"scaledHeight"`+ ScaledWidth int `yaml:"scaledWidth" json:"scaledWidth,omitempty"`+ ScaledHeight int `yaml:"scaledHeight" json:"scaledHeight,omitempty"`- Framerate int `yaml:"framerate"`- EncoderPreset string `yaml:"encoderPreset"`+ Framerate int `yaml:"framerate" json:"framerate"`+ EncoderPreset string `yaml:"encoderPreset" json:"encoderPreset"`}type files struct {MaxNumberInPlaylist int `yaml:"maxNumberInPlaylist"`}-//s3 is for configuring the s3 integration-type s3 struct {- Enabled bool `yaml:"enabled"`- Endpoint string `yaml:"endpoint"`- ServingEndpoint string `yaml:"servingEndpoint"`- AccessKey string `yaml:"accessKey"`- Secret string `yaml:"secret"`- Bucket string `yaml:"bucket"`- Region string `yaml:"region"`- ACL string `yaml:"acl"`+//S3 is for configuring the S3 integration+type S3 struct {+ Enabled bool `yaml:"enabled" json:"enabled"`+ Endpoint string `yaml:"endpoint" json:"endpoint,omitempty"`+ ServingEndpoint string `yaml:"servingEndpoint" json:"servingEndpoint,omitempty"`+ AccessKey string `yaml:"accessKey" json:"accessKey,omitempty"`+ Secret string `yaml:"secret" json:"secret,omitempty"`+ Bucket string `yaml:"bucket" json:"bucket,omitempty"`+ Region string `yaml:"region" json:"region,omitempty"`+ ACL string `yaml:"acl" json:"acl,omitempty"`}func (c *config) load(filePath string) error {diff --git a/config/configUtils.go b/config/configUtils.goindex f15a443a02..5b9fa60ae6 100644--- a/config/configUtils.go+++ b/config/configUtils.go@@ -1,6 +1,9 @@package config-import "sort"+import (+ "encoding/json"+ "sort"+)func findHighestQuality(qualities []StreamQuality) int {type IndexedQuality struct {@@ -32,3 +35,15 @@ func findHighestQuality(qualities []StreamQuality) int {return indexedQualities[0].index}++// MarshalJSON is a custom JSON marshal function for video stream qualities+func (q *StreamQuality) MarshalJSON() ([]byte, error) {+ type Alias StreamQuality+ return json.Marshal(&struct {+ Framerate int `json:"framerate"`+ *Alias+ }{+ Framerate: q.GetFramerate(),+ Alias: (*Alias)(q),+ })+}diff --git a/controllers/serverConfig.go b/controllers/serverConfig.gonew file mode 100644index 0000000000..bfc7bb36c1--- /dev/null+++ b/controllers/serverConfig.go@@ -0,0 +1,40 @@+package controllers++import (+ "encoding/json"+ "net/http"++ "github.com/gabek/owncast/config"+)++// GetServerConfig gets the config details of the server+func GetServerConfig(w http.ResponseWriter, r *http.Request) {+ response := serverConfigAdminResponse{+ InstanceDetails: config.Config.InstanceDetails,+ FFmpegPath: config.Config.GetFFMpegPath(),+ WebServerPort: config.Config.GetPublicWebServerPort(),+ VideoSettings: videoSettings{+ VideoQualityVariants: config.Config.GetVideoStreamQualities(),+ SegmentLengthSeconds: config.Config.GetVideoSegmentSecondsLength(),+ NumberOfPlaylistItems: config.Config.GetMaxNumberOfReferencedSegmentsInPlaylist(),+ },+ S3: config.Config.S3,+ }++ w.Header().Set("Content-Type", "application/json")+ json.NewEncoder(w).Encode(response)+}++type serverConfigAdminResponse struct {+ InstanceDetails config.InstanceDetails `json:"instanceDetails"`+ FFmpegPath string `json:"ffmpegPath"`+ WebServerPort int `json:"webServerPort"`+ S3 config.S3 `json:"s3"`+ VideoSettings videoSettings `json:"videoSettings"`+}++type videoSettings struct {+ VideoQualityVariants []config.StreamQuality `json:"videoQualityVariants"`+ SegmentLengthSeconds int `json:"segmentLengthSeconds"`+ NumberOfPlaylistItems int `json:"numberOfPlaylistItems"`+}diff --git a/router/router.go b/router/router.goindex 8504fba1f8..f80c815995 100644--- a/router/router.go+++ b/router/router.go@@ -57,6 +57,9 @@ func Start() error {// Change the current streaming key in memoryhttp.HandleFunc("/api/admin/changekey", middleware.RequireAdminAuth(admin.ChangeStreamKey))+ // Server config+ http.HandleFunc("/api/admin/serverconfig", middleware.RequireAdminAuth(controllers.GetServerConfig))+port := config.Config.GetPublicWebServerPort()log.Infof("Web server running on port: %d", port)