summaryrefslogtreecommitdiffstats
path: root/vendor/go.mau.fi/whatsmeow/keepalive.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/go.mau.fi/whatsmeow/keepalive.go')
-rw-r--r--vendor/go.mau.fi/whatsmeow/keepalive.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/vendor/go.mau.fi/whatsmeow/keepalive.go b/vendor/go.mau.fi/whatsmeow/keepalive.go
index d5e40286..48510a12 100644
--- a/vendor/go.mau.fi/whatsmeow/keepalive.go
+++ b/vendor/go.mau.fi/whatsmeow/keepalive.go
@@ -23,10 +23,13 @@ var (
KeepAliveIntervalMin = 20 * time.Second
// KeepAliveIntervalMax specifies the maximum interval for websocket keepalive pings.
KeepAliveIntervalMax = 30 * time.Second
+
+ // KeepAliveMaxFailTime specifies the maximum time to wait before forcing a reconnect if keepalives fail repeatedly.
+ KeepAliveMaxFailTime = 3 * time.Minute
)
func (cli *Client) keepAliveLoop(ctx context.Context) {
- var lastSuccess time.Time
+ lastSuccess := time.Now()
var errorCount int
for {
interval := rand.Int63n(KeepAliveIntervalMax.Milliseconds()-KeepAliveIntervalMin.Milliseconds()) + KeepAliveIntervalMin.Milliseconds()
@@ -41,6 +44,11 @@ func (cli *Client) keepAliveLoop(ctx context.Context) {
ErrorCount: errorCount,
LastSuccess: lastSuccess,
})
+ if cli.EnableAutoReconnect && time.Since(lastSuccess) > KeepAliveMaxFailTime {
+ cli.Log.Debugf("Forcing reconnect due to keepalive failure")
+ cli.Disconnect()
+ go cli.autoReconnect()
+ }
} else {
if errorCount > 0 {
errorCount = 0