Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,10 +1,38 @@
# 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
RTMP_URL=rtmp://localhost:1935/live/stream
# Output resolution (720p, 1080p, or 2k)
RESOLUTION=720p
# Output framerate (30 or 60)
FRAMERATE=30
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
41 changes: 41 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)

Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down