From de226ce0cf187dbc79a351aaff30fe232f35d569 Mon Sep 17 00:00:00 2001 From: Jannis Mattheis Date: Sat, 1 Aug 2020 15:35:29 +0200 Subject: [PATCH] Make ws ping interval configurable --- config.example.yml | 1 + config/config.go | 3 ++- router/router.go | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/config.example.yml b/config.example.yml index 1292fc8..a7ef8fb 100644 --- a/config.example.yml +++ b/config.example.yml @@ -35,6 +35,7 @@ server: # - "Authorization" # - "content-type" stream: + pingperiodseconds: 45 # the interval in which websocket pings will be sent. Only change this value if you know what you are doing. allowedorigins: # allowed origins for websocket connections (same origin is always allowed) # - ".+.example.com" # - "otherdomain.com" diff --git a/config/config.go b/config/config.go index 66f2d03..b5c5ba8 100644 --- a/config/config.go +++ b/config/config.go @@ -31,7 +31,8 @@ type Configuration struct { } ResponseHeaders map[string]string Stream struct { - AllowedOrigins []string + PingPeriodSeconds int `default:"45"` + AllowedOrigins []string } Cors struct { AllowOrigins []string diff --git a/router/router.go b/router/router.go index 4fdd955..e34140f 100644 --- a/router/router.go +++ b/router/router.go @@ -25,7 +25,7 @@ func Create(db *database.GormDatabase, vInfo *model.VersionInfo, conf *config.Co g.Use(gin.Logger(), gin.Recovery(), error.Handler(), location.Default()) g.NoRoute(error.NotFound()) - streamHandler := stream.New(45*time.Second, 15*time.Second, conf.Server.Stream.AllowedOrigins) + streamHandler := stream.New(time.Duration(conf.Server.Stream.PingPeriodSeconds)*time.Second, 15*time.Second, conf.Server.Stream.AllowedOrigins) authentication := auth.Auth{DB: db} messageHandler := api.MessageAPI{Notifier: streamHandler, DB: db} healthHandler := api.HealthAPI{DB: db}