diff --git a/.env.example b/.env.example index 909bff5..0fcd5d7 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,7 @@ # To use this file, copy it to `.env` and update and/or add your own values. # Be sure to read the `Environment Variables` section in the README. + +# Basic streaming configuration # Webpage to capture and stream WEBPAGE_URL="https://www.youtube.com/embed/xuCn8ux2gbs?autoplay=1&loop=1&playlist=xuCn8ux2gbs" # RTMP endpoint to stream to @@ -7,4 +9,30 @@ RTMP_URL=rtmp://localhost:1935/live/stream # Output resolution (720p, 1080p, or 2k) RESOLUTION=720p # Output framerate (30 or 60) -FRAMERATE=30 \ No newline at end of file +FRAMERATE=30 + +# Optional configurations (uncomment to use) +# Webpage refresh interval in seconds (optional - if not set, automatic refresh is disabled) +# WEBPAGE_REFRESH_INTERVAL=120 + +# Logging configuration +# Log format (json or console) - default: json +# LOG_FORMAT=json +# Log level (debug, info, warn, warning, error, dpanic, panic, fatal) - default: info +# LOG_LEVEL=info + +# HTTP server configuration +# Port for health and metrics endpoint - default: 8080 +# PORT=8080 + +# Stream status checking configuration +# Cron schedule for checking stream status - default: */10 * * * * (every 10 minutes) +# STATUS_CRON_SCHEDULE="*/10 * * * *" + +# Twitch integration (all three required for Twitch status checking) +# Twitch channel name to monitor +# TWITCH_CHANNEL=your_channel_name +# Twitch Client ID from https://dev.twitch.tv/console +# TWITCH_CLIENT_ID=your_client_id +# Twitch Client Secret from https://dev.twitch.tv/console +# TWITCH_CLIENT_SECRET=your_client_secret \ No newline at end of file diff --git a/README.md b/README.md index 4446e17..eca6185 100644 --- a/README.md +++ b/README.md @@ -169,6 +169,10 @@ To enable status checking for Twitch, provide a `TWITCH_CHANNEL`, `TWITCH_CLIENT - Twitch Client ID obtained from the [Twitch Developer Console](https://dev.twitch.tv/console) for checking stream status if the `TWITCH_CHANNEL` environmental variable is set. - Checking for the stream status on Twitch will not work without this and `TWITCH_CLIENT_ID` being set. - For more information about registering an app on Twitch, see [the developer documentation](https://dev.twitch.tv/docs/authentication/register-app/). +- `WEBPAGE_REFRESH_INTERVAL` + - String + - If set to a positive integer, the browser will automatically refresh the webpage at the specified interval in seconds. This can help prevent issues with stale content or memory leaks during long streaming sessions, as a memory usage can build if the `WEBPAGE_URL` location has memory leaks. + - If not set or set to an invalid value, automatic refresh is disabled. - `WEBPAGE_URL` - String - Default: `https://google.com` diff --git a/cmd/main.go b/cmd/main.go index be1fef1..2734863 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -366,6 +366,12 @@ func streamWebpage(ctx context.Context, config *Config) error { chromedp.Flag("disable-blink-features", "AutomationControlled"), chromedp.Flag("mute-audio", false), chromedp.Flag("window-position", "0,0"), + chromedp.Flag("memory-pressure-off", true), + chromedp.Flag("disable-background-timer-throttling", true), + chromedp.Flag("disable-renderer-backgrounding", true), + chromedp.Flag("disable-backgrounding-occluded-windows", true), + chromedp.Flag("disable-features", "TranslateUI,VizDisplayCompositor"), + chromedp.Flag("aggressive-cache-discard", true), chromedp.WindowSize(config.Width, config.Height), ) @@ -407,6 +413,41 @@ func streamWebpage(ctx context.Context, config *Config) error { // Wait a moment for the page to fully load time.Sleep(3 * time.Second) + // Check if automatic refresh is enabled via environment variable + refreshIntervalStr := utils.GetEnvOrDefault("WEBPAGE_REFRESH_INTERVAL", "") + if refreshIntervalStr != "" { + refreshInterval, err := strconv.Atoi(refreshIntervalStr) + if err != nil || refreshInterval <= 0 { + logger.Warn("Invalid WEBPAGE_REFRESH_INTERVAL value, automatic refresh disabled", + zap.String("invalidValue", refreshIntervalStr), zap.Error(err)) + } else { + logger.Info("Enabling automatic browser refresh", + zap.Int("refreshInterval", refreshInterval)) + + go func() { + ticker := time.NewTicker(time.Duration(refreshInterval) * time.Second) + defer ticker.Stop() + + for { + select { + case <-ticker.C: + logger.Info("Refreshing browser page", zap.String("url", config.WebpageURL)) + if err := chromedp.Run(chromeCtx, chromedp.Reload()); err != nil { + logger.Error("Failed to refresh browser page", zap.Error(err)) + } else { + logger.Debug("Browser page refreshed successfully") + } + case <-streamCtx.Done(): + logger.Debug("Stream context cancelled, stopping browser refresh goroutine") + return + } + } + }() + } + } else { + logger.Debug("WEBPAGE_REFRESH_INTERVAL not set, automatic refresh disabled") + } + // Get the display information to find where Chrome is running displayInfo, err := getDisplayInfo() if err != nil { diff --git a/docker-compose.yml b/docker-compose.yml index 711af03..0584543 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,6 +13,7 @@ services: - TWITCH_CHANNEL=${TWITCH_CHANNEL} - TWITCH_CLIENT_ID=${TWITCH_CLIENT_ID} - TWITCH_CLIENT_SECRET=${TWITCH_CLIENT_SECRET} + - WEBPAGE_REFRESH_INTERVAL=${WEBPAGE_REFRESH_INTERVAL:-0} - WEBPAGE_URL=${WEBPAGE_URL:-https://www.youtube.com/embed/xuCn8ux2gbs?autoplay=1&loop=1&playlist=xuCn8ux2gbs} # Image to run unit tests in