Skip to content

Commit f2fcb49

Browse files
authored
Implemented WEBPAGE_REFRESH_INTERVAL environmental variable (#16)
1 parent 3672912 commit f2fcb49

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed

.env.example

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,38 @@
11
# To use this file, copy it to `.env` and update and/or add your own values.
22
# Be sure to read the `Environment Variables` section in the README.
3+
4+
# Basic streaming configuration
35
# Webpage to capture and stream
46
WEBPAGE_URL="https://www.youtube.com/embed/xuCn8ux2gbs?autoplay=1&loop=1&playlist=xuCn8ux2gbs"
57
# RTMP endpoint to stream to
68
RTMP_URL=rtmp://localhost:1935/live/stream
79
# Output resolution (720p, 1080p, or 2k)
810
RESOLUTION=720p
911
# Output framerate (30 or 60)
10-
FRAMERATE=30
12+
FRAMERATE=30
13+
14+
# Optional configurations (uncomment to use)
15+
# Webpage refresh interval in seconds (optional - if not set, automatic refresh is disabled)
16+
# WEBPAGE_REFRESH_INTERVAL=120
17+
18+
# Logging configuration
19+
# Log format (json or console) - default: json
20+
# LOG_FORMAT=json
21+
# Log level (debug, info, warn, warning, error, dpanic, panic, fatal) - default: info
22+
# LOG_LEVEL=info
23+
24+
# HTTP server configuration
25+
# Port for health and metrics endpoint - default: 8080
26+
# PORT=8080
27+
28+
# Stream status checking configuration
29+
# Cron schedule for checking stream status - default: */10 * * * * (every 10 minutes)
30+
# STATUS_CRON_SCHEDULE="*/10 * * * *"
31+
32+
# Twitch integration (all three required for Twitch status checking)
33+
# Twitch channel name to monitor
34+
# TWITCH_CHANNEL=your_channel_name
35+
# Twitch Client ID from https://dev.twitch.tv/console
36+
# TWITCH_CLIENT_ID=your_client_id
37+
# Twitch Client Secret from https://dev.twitch.tv/console
38+
# TWITCH_CLIENT_SECRET=your_client_secret

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ To enable status checking for Twitch, provide a `TWITCH_CHANNEL`, `TWITCH_CLIENT
169169
- 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.
170170
- Checking for the stream status on Twitch will not work without this and `TWITCH_CLIENT_ID` being set.
171171
- For more information about registering an app on Twitch, see [the developer documentation](https://dev.twitch.tv/docs/authentication/register-app/).
172+
- `WEBPAGE_REFRESH_INTERVAL`
173+
- String
174+
- 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.
175+
- If not set or set to an invalid value, automatic refresh is disabled.
172176
- `WEBPAGE_URL`
173177
- String
174178
- Default: `https://google.com`

cmd/main.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,12 @@ func streamWebpage(ctx context.Context, config *Config) error {
366366
chromedp.Flag("disable-blink-features", "AutomationControlled"),
367367
chromedp.Flag("mute-audio", false),
368368
chromedp.Flag("window-position", "0,0"),
369+
chromedp.Flag("memory-pressure-off", true),
370+
chromedp.Flag("disable-background-timer-throttling", true),
371+
chromedp.Flag("disable-renderer-backgrounding", true),
372+
chromedp.Flag("disable-backgrounding-occluded-windows", true),
373+
chromedp.Flag("disable-features", "TranslateUI,VizDisplayCompositor"),
374+
chromedp.Flag("aggressive-cache-discard", true),
369375
chromedp.WindowSize(config.Width, config.Height),
370376
)
371377

@@ -407,6 +413,41 @@ func streamWebpage(ctx context.Context, config *Config) error {
407413
// Wait a moment for the page to fully load
408414
time.Sleep(3 * time.Second)
409415

416+
// Check if automatic refresh is enabled via environment variable
417+
refreshIntervalStr := utils.GetEnvOrDefault("WEBPAGE_REFRESH_INTERVAL", "")
418+
if refreshIntervalStr != "" {
419+
refreshInterval, err := strconv.Atoi(refreshIntervalStr)
420+
if err != nil || refreshInterval <= 0 {
421+
logger.Warn("Invalid WEBPAGE_REFRESH_INTERVAL value, automatic refresh disabled",
422+
zap.String("invalidValue", refreshIntervalStr), zap.Error(err))
423+
} else {
424+
logger.Info("Enabling automatic browser refresh",
425+
zap.Int("refreshInterval", refreshInterval))
426+
427+
go func() {
428+
ticker := time.NewTicker(time.Duration(refreshInterval) * time.Second)
429+
defer ticker.Stop()
430+
431+
for {
432+
select {
433+
case <-ticker.C:
434+
logger.Info("Refreshing browser page", zap.String("url", config.WebpageURL))
435+
if err := chromedp.Run(chromeCtx, chromedp.Reload()); err != nil {
436+
logger.Error("Failed to refresh browser page", zap.Error(err))
437+
} else {
438+
logger.Debug("Browser page refreshed successfully")
439+
}
440+
case <-streamCtx.Done():
441+
logger.Debug("Stream context cancelled, stopping browser refresh goroutine")
442+
return
443+
}
444+
}
445+
}()
446+
}
447+
} else {
448+
logger.Debug("WEBPAGE_REFRESH_INTERVAL not set, automatic refresh disabled")
449+
}
450+
410451
// Get the display information to find where Chrome is running
411452
displayInfo, err := getDisplayInfo()
412453
if err != nil {

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ services:
1313
- TWITCH_CHANNEL=${TWITCH_CHANNEL}
1414
- TWITCH_CLIENT_ID=${TWITCH_CLIENT_ID}
1515
- TWITCH_CLIENT_SECRET=${TWITCH_CLIENT_SECRET}
16+
- WEBPAGE_REFRESH_INTERVAL=${WEBPAGE_REFRESH_INTERVAL:-0}
1617
- WEBPAGE_URL=${WEBPAGE_URL:-https://www.youtube.com/embed/xuCn8ux2gbs?autoplay=1&loop=1&playlist=xuCn8ux2gbs}
1718

1819
# Image to run unit tests in

0 commit comments

Comments
 (0)