Compare commits

..

No commits in common. "60c7fb458ba6089869f62f392d8b58aca65eb81f" and "e49bbb6800658c7807fdf9ab4f2ad6b1b656d8d5" have entirely different histories.

8 changed files with 42 additions and 50 deletions

View File

@ -97,10 +97,11 @@ logfile:
enabled: true # defaults to false
path: /path/to/logfile # defaults to $XDG_STATE_HOME/octoplex/octoplex.log
sources:
mediaServer:
rtmp:
enabled: true # must be true
streamKey: live # defaults to "live"
host: rtmp.example.com # defaults to "localhost"
rtmp: # must be present, use `rtmp: {}` for defaults
bindAddr: # optional
ip: 0.0.0.0 # defaults to 127.0.0.1
port: 1935 # defaults to 1935
destinations:

View File

@ -39,8 +39,8 @@ func Run(ctx context.Context, params RunParams) error {
applyConfig(cfg, state)
// While RTMP is the only source, it doesn't make sense to disable it.
if cfg.Sources.MediaServer.RTMP == nil {
return errors.New("config: sources.mediaServer.rtmp is required")
if !cfg.Sources.RTMP.Enabled {
return errors.New("config: sources.rtmp.enabled must be set to true")
}
logger := params.Logger
@ -89,9 +89,9 @@ func Run(ctx context.Context, params RunParams) error {
updateUI()
srv, err := mediaserver.NewActor(ctx, mediaserver.NewActorParams{
RTMPAddr: domain.NetAddr(cfg.Sources.MediaServer.RTMP.NetAddr),
Host: cfg.Sources.MediaServer.Host,
StreamKey: mediaserver.StreamKey(cfg.Sources.MediaServer.StreamKey),
RTMPAddr: domain.NetAddr(cfg.Sources.RTMP.BindAddr),
RTMPHost: cfg.Sources.RTMP.Host,
StreamKey: mediaserver.StreamKey(cfg.Sources.RTMP.StreamKey),
ContainerClient: containerClient,
Logger: logger.With("component", "mediaserver"),
})

View File

@ -78,13 +78,12 @@ func testIntegration(t *testing.T, rtmpHost string, rtmpIP string, rtmpPort int,
destURL2 := fmt.Sprintf("rtmp://%s:%d/%s/dest2", hostIP, destServerPort.Int(), wantStreamKey)
configService := setupConfigService(t, config.Config{
Sources: config.Sources{
MediaServer: config.MediaServerSource{
RTMP: config.RTMPSource{
Enabled: true,
Host: rtmpHost,
BindAddr: config.NetAddr{IP: rtmpIP, Port: rtmpPort},
StreamKey: streamKey,
RTMP: &config.RTMPSource{
NetAddr: config.NetAddr{IP: rtmpIP, Port: rtmpPort},
}},
},
// Load one destination from config, add the other in-app.
Destinations: []config.Destination{{Name: "Local server 1", URL: destURL1}},
})
@ -276,9 +275,9 @@ func TestIntegrationCustomRTMPURL(t *testing.T) {
configService := setupConfigService(t, config.Config{
Sources: config.Sources{
MediaServer: config.MediaServerSource{
RTMP: config.RTMPSource{
Enabled: true,
Host: "rtmp.live.tv",
RTMP: &config.RTMPSource{},
},
},
})
@ -302,7 +301,7 @@ func TestIntegrationCustomRTMPURL(t *testing.T) {
time.Second,
"expected to see custom host name",
)
printScreen(t, getContents, "Ater opening the app with a custom host name")
printScreen(t, getContents, "Ater displaying the fatal error modal")
cancel()
@ -337,7 +336,7 @@ func TestIntegrationRestartDestination(t *testing.T) {
screen, screenCaptureC, getContents := setupSimulationScreen(t)
configService := setupConfigService(t, config.Config{
Sources: config.Sources{MediaServer: config.MediaServerSource{RTMP: &config.RTMPSource{}}},
Sources: config.Sources{RTMP: config.RTMPSource{Enabled: true}},
Destinations: []config.Destination{{
Name: "Local server 1",
URL: fmt.Sprintf("rtmp://%s:%d/live", hostIP, destServerRTMPPort.Int()),
@ -483,7 +482,7 @@ func TestIntegrationStartDestinationFailed(t *testing.T) {
screen, screenCaptureC, getContents := setupSimulationScreen(t)
configService := setupConfigService(t, config.Config{
Sources: config.Sources{MediaServer: config.MediaServerSource{RTMP: &config.RTMPSource{}}},
Sources: config.Sources{RTMP: config.RTMPSource{Enabled: true}},
Destinations: []config.Destination{{Name: "Example server", URL: "rtmp://rtmp.example.com/live"}},
})
@ -559,7 +558,7 @@ func TestIntegrationDestinationValidations(t *testing.T) {
screen, screenCaptureC, getContents := setupSimulationScreen(t)
configService := setupConfigService(t, config.Config{
Sources: config.Sources{MediaServer: config.MediaServerSource{StreamKey: "live", RTMP: &config.RTMPSource{}}},
Sources: config.Sources{RTMP: config.RTMPSource{Enabled: true, StreamKey: "live"}},
})
done := make(chan struct{})
@ -702,7 +701,7 @@ func TestIntegrationStartupCheck(t *testing.T) {
dockerClient, err := dockerclient.NewClientWithOpts(dockerclient.FromEnv, dockerclient.WithAPIVersionNegotiation())
require.NoError(t, err)
configService := setupConfigService(t, config.Config{Sources: config.Sources{MediaServer: config.MediaServerSource{RTMP: &config.RTMPSource{}}}})
configService := setupConfigService(t, config.Config{Sources: config.Sources{RTMP: config.RTMPSource{Enabled: true}}})
screen, screenCaptureC, getContents := setupSimulationScreen(t)
done := make(chan struct{})
@ -771,7 +770,7 @@ func TestIntegrationMediaServerError(t *testing.T) {
dockerClient, err := dockerclient.NewClientWithOpts(dockerclient.FromEnv, dockerclient.WithAPIVersionNegotiation())
require.NoError(t, err)
configService := setupConfigService(t, config.Config{Sources: config.Sources{MediaServer: config.MediaServerSource{RTMP: &config.RTMPSource{}}}})
configService := setupConfigService(t, config.Config{Sources: config.Sources{RTMP: config.RTMPSource{Enabled: true}}})
screen, screenCaptureC, getContents := setupSimulationScreen(t)
done := make(chan struct{})
@ -810,7 +809,7 @@ func TestIntegrationDockerClientError(t *testing.T) {
var dockerClient mocks.DockerClient
dockerClient.EXPECT().NetworkCreate(mock.Anything, mock.Anything, mock.Anything).Return(network.CreateResponse{}, errors.New("boom"))
configService := setupConfigService(t, config.Config{Sources: config.Sources{MediaServer: config.MediaServerSource{RTMP: &config.RTMPSource{}}}})
configService := setupConfigService(t, config.Config{Sources: config.Sources{RTMP: config.RTMPSource{Enabled: true}}})
screen, screenCaptureC, getContents := setupSimulationScreen(t)
done := make(chan struct{})
@ -851,7 +850,7 @@ func TestIntegrationDockerConnectionError(t *testing.T) {
dockerClient, err := dockerclient.NewClientWithOpts(dockerclient.WithHost("http://docker.example.com"))
require.NoError(t, err)
configService := setupConfigService(t, config.Config{Sources: config.Sources{MediaServer: config.MediaServerSource{RTMP: &config.RTMPSource{}}}})
configService := setupConfigService(t, config.Config{Sources: config.Sources{RTMP: config.RTMPSource{Enabled: true}}})
screen, screenCaptureC, getContents := setupSimulationScreen(t)
done := make(chan struct{})

View File

@ -30,19 +30,15 @@ type NetAddr struct {
// RTMPSource holds the configuration for the RTMP source.
type RTMPSource struct {
NetAddr `yaml:",inline"`
}
// MediaServerSource holds the configuration for the media server source.
type MediaServerSource struct {
Enabled bool `yaml:"enabled"`
StreamKey string `yaml:"streamKey,omitempty"`
Host string `yaml:"host,omitempty"`
RTMP *RTMPSource `yaml:"rtmp,omitempty"`
BindAddr NetAddr `yaml:"bindAddr,omitempty"`
}
// Sources holds the configuration for the sources.
type Sources struct {
MediaServer MediaServerSource `yaml:"mediaServer"`
RTMP RTMPSource `yaml:"rtmp"`
}
// Config holds the configuration for the application.

View File

@ -182,8 +182,8 @@ func (s *Service) writeConfig(cfgBytes []byte) error {
//
// This function may set exported fields to arbitrary values.
func (s *Service) populateConfigOnBuild(cfg *Config) {
cfg.Sources.MediaServer.StreamKey = "live"
cfg.Sources.MediaServer.RTMP = &RTMPSource{NetAddr{"127.0.0.1", 1935}}
cfg.Sources.RTMP.Enabled = true
cfg.Sources.RTMP.StreamKey = "live"
s.populateConfigOnRead(cfg)
}

View File

@ -44,9 +44,7 @@ func TestConfigServiceCurrent(t *testing.T) {
t.Cleanup(func() { require.NoError(t, os.RemoveAll(systemConfigDir)) })
// Ensure defaults are set:
assert.NotNil(t, service.Current().Sources.MediaServer.RTMP)
assert.Equal(t, "127.0.0.1", service.Current().Sources.MediaServer.RTMP.IP)
assert.Equal(t, 1935, service.Current().Sources.MediaServer.RTMP.Port)
assert.True(t, service.Current().Sources.RTMP.Enabled)
}
func TestConfigServiceCreateConfig(t *testing.T) {
@ -69,9 +67,7 @@ func TestConfigServiceCreateConfig(t *testing.T) {
var readCfg config.Config
require.NoError(t, yaml.Unmarshal(cfgBytes, &readCfg))
assert.NotNil(t, readCfg.Sources.MediaServer.RTMP)
assert.Equal(t, "127.0.0.1", readCfg.Sources.MediaServer.RTMP.IP)
assert.Equal(t, 1935, readCfg.Sources.MediaServer.RTMP.Port)
assert.True(t, readCfg.Sources.RTMP.Enabled, "default values not set")
}
func TestConfigServiceReadConfig(t *testing.T) {
@ -94,17 +90,16 @@ func TestConfigServiceReadConfig(t *testing.T) {
Path: "test.log",
},
Sources: config.Sources{
MediaServer: config.MediaServerSource{
RTMP: config.RTMPSource{
Enabled: true,
StreamKey: "s3cr3t",
Host: "rtmp.example.com",
RTMP: &config.RTMPSource{
NetAddr: config.NetAddr{
BindAddr: config.NetAddr{
IP: "0.0.0.0",
Port: 19350,
},
},
},
},
Destinations: []config.Destination{
{
Name: "my stream",

View File

@ -3,10 +3,11 @@ logfile:
enabled: true
path: test.log
sources:
mediaServer:
rtmp:
enabled: true
streamKey: s3cr3t
host: rtmp.example.com
rtmp:
bindAddr:
ip: 0.0.0.0
port: 19350
destinations:

View File

@ -66,7 +66,7 @@ type Actor struct {
type NewActorParams struct {
APIPort int // defaults to 9997
RTMPAddr domain.NetAddr // defaults to 127.0.0.1:1935
Host string // defaults to "localhost"
RTMPHost string // defaults to "localhost"
StreamKey StreamKey // defaults to "live"
ChanSize int // defaults to 64
UpdateStateInterval time.Duration // defaults to 5 seconds
@ -95,7 +95,7 @@ func NewActor(ctx context.Context, params NewActorParams) (_ *Actor, err error)
return &Actor{
apiPort: cmp.Or(params.APIPort, defaultAPIPort),
rtmpAddr: rtmpAddr,
rtmpHost: cmp.Or(params.Host, defaultRTMPHost),
rtmpHost: cmp.Or(params.RTMPHost, defaultRTMPHost),
streamKey: cmp.Or(params.StreamKey, defaultStreamKey),
updateStateInterval: cmp.Or(params.UpdateStateInterval, defaultUpdateStateInterval),
tlsCert: tlsCert,