Skip to content

Commit

Permalink
Add interface for permanent disconnect events
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Feb 13, 2024
1 parent ccac3f0 commit a85e168
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions types/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ type KeepAliveTimeout struct {
// Note that if the websocket disconnects before the pings start working, this event will not be emitted.
type KeepAliveRestored struct{}

// PermanentDisconnect is a class of events emitted when the client will not auto-reconnect by default.
type PermanentDisconnect interface {
PermanentDisconnectDescription() string
}

func (l *LoggedOut) PermanentDisconnectDescription() string { return l.Reason.String() }
func (*StreamReplaced) PermanentDisconnectDescription() string { return "stream replaced" }
func (*ClientOutdated) PermanentDisconnectDescription() string { return "client outdated" }
func (*CATRefreshError) PermanentDisconnectDescription() string { return "CAT refresh failed" }
func (tb *TemporaryBan) PermanentDisconnectDescription() string {
return fmt.Sprintf("temporarily banned: %s", tb.String())
}
func (cf *ConnectFailure) PermanentDisconnectDescription() string {
return fmt.Sprintf("connect failure: %s", cf.Reason.String())
}

// LoggedOut is emitted when the client has been unpaired from the phone.
//
// This can happen while connected (stream:error messages) or right after connecting (connect failure messages).
Expand Down

0 comments on commit a85e168

Please sign in to comment.