Make ws ping interval configurable

This commit is contained in:
Jannis Mattheis
2020-08-01 15:35:29 +02:00
parent 909eeff406
commit de226ce0cf
3 changed files with 4 additions and 2 deletions

View File

@@ -35,6 +35,7 @@ server:
# - "Authorization" # - "Authorization"
# - "content-type" # - "content-type"
stream: 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) allowedorigins: # allowed origins for websocket connections (same origin is always allowed)
# - ".+.example.com" # - ".+.example.com"
# - "otherdomain.com" # - "otherdomain.com"

View File

@@ -31,7 +31,8 @@ type Configuration struct {
} }
ResponseHeaders map[string]string ResponseHeaders map[string]string
Stream struct { Stream struct {
AllowedOrigins []string PingPeriodSeconds int `default:"45"`
AllowedOrigins []string
} }
Cors struct { Cors struct {
AllowOrigins []string AllowOrigins []string

View File

@@ -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.Use(gin.Logger(), gin.Recovery(), error.Handler(), location.Default())
g.NoRoute(error.NotFound()) 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} authentication := auth.Auth{DB: db}
messageHandler := api.MessageAPI{Notifier: streamHandler, DB: db} messageHandler := api.MessageAPI{Notifier: streamHandler, DB: db}
healthHandler := api.HealthAPI{DB: db} healthHandler := api.HealthAPI{DB: db}