Skip to content

Commit

Permalink
client: add option to disable autoreconnect after login
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Sep 16, 2024
1 parent bb3364a commit ea8c175
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ type Client struct {
// the client will not attempt to reconnect. The number of retries can be read from AutoReconnectErrors.
AutoReconnectHook func(error) bool

DisableLoginAutoReconnect bool

sendActiveReceipts atomic.Uint32

// EmitAppStateEventsOnFullSync can be set to true if you want to get app state events emitted
Expand Down
5 changes: 5 additions & 0 deletions connectionevents.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ func (cli *Client) handleStreamError(node *waBinary.Node) {
conflictType := conflict.AttrGetter().OptionalString("type")
switch {
case code == "515":
if cli.DisableLoginAutoReconnect {
cli.Log.Infof("Got 515 code, but login autoreconnect is disabled, not reconnecting")
cli.dispatchEvent(&events.ManualLoginReconnect{})
return
}
cli.Log.Infof("Got 515 code, reconnecting...")
go func() {
cli.Disconnect()
Expand Down
3 changes: 3 additions & 0 deletions types/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ type LoggedOut struct {
// or otherwise try to connect twice with the same session.
type StreamReplaced struct{}

// ManualLoginReconnect is emitted after login if DisableLoginAutoReconnect is set.
type ManualLoginReconnect struct{}

// TempBanReason is an error code included in temp ban error events.
type TempBanReason int

Expand Down

0 comments on commit ea8c175

Please sign in to comment.