From 630abfe474fd009287ba114f2f48b93944a6557b Mon Sep 17 00:00:00 2001 From: Zorchenhimer Date: Fri, 12 Jun 2020 23:58:45 -0400 Subject: [PATCH] Add option to change the RTMP listen address A new setting has been added to change the address and port that the RTMP server listens on. `RtmpListenAddress` in the settings json and `-r` on the command line. Both options use the same format: `host:port`. --- main.go | 12 ++++++++---- settings.go | 1 + settings_example.json | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 6322464..3dfeeac 100644 --- a/main.go +++ b/main.go @@ -16,6 +16,7 @@ import ( var ( pullEmotes bool addr string + rtmpAddr string sKey string stats = newStreamStats() sAdminPass string @@ -47,7 +48,8 @@ func setupSettings() error { } func main() { - flag.StringVar(&addr, "l", "", "host:port of the MovieNight") + flag.StringVar(&addr, "l", "", "host:port of the HTTP server") + flag.StringVar(&rtmpAddr, "r", "", "host:port of the RTMP server") flag.StringVar(&sKey, "k", "", "Stream key, to protect your stream") flag.StringVar(&sAdminPass, "a", "", "Set admin password. Overrides configuration in settings.json. This will not write the password to settings.json.") flag.BoolVar(&pullEmotes, "e", false, "Pull emotes") @@ -90,8 +92,8 @@ func main() { addr = settings.ListenAddress } - if addr[0] != ':' { - addr = ":" + addr + if rtmpAddr == "" { + rtmpAddr = settings.RtmpListenAddress } // A stream key was passed on the command line. Use it, but don't save @@ -102,7 +104,8 @@ func main() { common.LogInfoln("Stream key: ", settings.GetStreamKey()) common.LogInfoln("Admin password: ", settings.AdminPassword) - common.LogInfoln("Listen and serve ", addr) + common.LogInfoln("HTTP server listening on: ", addr) + common.LogInfoln("RTMP server listening on: ", rtmpAddr) common.LogInfoln("RoomAccess: ", settings.RoomAccess) common.LogInfoln("RoomAccessPin: ", settings.RoomAccessPin) @@ -116,6 +119,7 @@ func startRmtpServer() { server := &rtmp.Server{ HandlePlay: handlePlay, HandlePublish: handlePublish, + Addr: rtmpAddr, } err := server.ListenAndServe() if err != nil { diff --git a/settings.go b/settings.go index 059d921..d7f809c 100644 --- a/settings.go +++ b/settings.go @@ -36,6 +36,7 @@ type Settings struct { RegenAdminPass bool // regenerate admin password on start? RoomAccess AccessMode RoomAccessPin string // The current pin + RtmpListenAddress string // host:port that the RTMP server listens on SessionKey string // key for session data StreamKey string StreamStats bool diff --git a/settings_example.json b/settings_example.json index 620f2e0..f14ccd0 100644 --- a/settings_example.json +++ b/settings_example.json @@ -15,6 +15,7 @@ "RateLimitDuplicate": 30, "RateLimitNick": 300, "RegenAdminPass": true, + "RtmpListenAddress": ":1935", "StreamKey": "ALongStreamKey", "TitleLength": 50, "TwitchClientID": "",