github.com/anycable/anycable-go@v1.5.1/cli/session_options.go (about) 1 package cli 2 3 import ( 4 "strconv" 5 "time" 6 7 "github.com/anycable/anycable-go/common" 8 "github.com/anycable/anycable-go/node" 9 "github.com/anycable/anycable-go/server" 10 ) 11 12 const ( 13 pingIntervalParameter = "pi" 14 pingPrecisionParameter = "ptp" 15 16 prevSessionHeader = "X-ANYCABLE-RESTORE-SID" 17 prevSessionParam = "sid" 18 ) 19 20 func (r *Runner) sessionOptionsFromProtocol(protocol string) []node.SessionOption { 21 opts := []node.SessionOption{} 22 23 if common.IsExtendedActionCableProtocol(protocol) { 24 opts = append(opts, node.WithResumable(true)) 25 26 if r.config.App.PongTimeout > 0 { 27 opts = append(opts, node.WithPongTimeout(time.Duration(r.config.App.PongTimeout)*time.Second)) 28 } 29 } 30 31 return opts 32 } 33 34 func (r *Runner) sessionOptionsFromParams(info *server.RequestInfo) []node.SessionOption { 35 opts := []node.SessionOption{} 36 37 if rawVal := info.Param(pingIntervalParameter); rawVal != "" { 38 val, err := strconv.Atoi(rawVal) 39 if err != nil { 40 r.log.Warn("invalid ping interval value, must be integer", "val", rawVal) 41 } else { 42 opts = append(opts, node.WithPingInterval(time.Duration(val)*time.Second)) 43 } 44 } 45 46 if val := info.Param(pingPrecisionParameter); val != "" { 47 opts = append(opts, node.WithPingPrecision(val)) 48 } 49 50 if hval := info.AnyCableHeader(prevSessionHeader); hval != "" { 51 opts = append(opts, node.WithPrevSID(hval)) 52 } else if pval := info.Param(prevSessionParam); pval != "" { 53 opts = append(opts, node.WithPrevSID(pval)) 54 } 55 56 return opts 57 }