forked from MirrorHub/mautrix-whatsapp
Add option to auto-reconnect even on clean disconnects
This commit is contained in:
parent
3c7ff4bc0c
commit
1c801594d5
3 changed files with 11 additions and 4 deletions
|
@ -42,6 +42,7 @@ type BridgeConfig struct {
|
|||
MaxConnectionAttempts int `yaml:"max_connection_attempts"`
|
||||
ConnectionRetryDelay int `yaml:"connection_retry_delay"`
|
||||
ReportConnectionRetry bool `yaml:"report_connection_retry"`
|
||||
AggressiveReconnect bool `yaml:"aggressive_reconnect"`
|
||||
ChatListWait int `yaml:"chat_list_wait"`
|
||||
PortalSyncWait int `yaml:"portal_sync_wait"`
|
||||
UserMessageBuffer int `yaml:"user_message_buffer"`
|
||||
|
|
|
@ -106,6 +106,8 @@ bridge:
|
|||
# Whether or not the bridge should send a notice to the user's management room when it retries connecting.
|
||||
# If false, it will only report when it stops retrying.
|
||||
report_connection_retry: true
|
||||
# Whether or not the bridge should reconnect even if WhatsApp says another web client connected.
|
||||
aggressive_reconnect: false
|
||||
# Maximum number of seconds to wait for chats to be sent at startup.
|
||||
# If this is too low and you have lots of chats, it could cause backfilling to fail.
|
||||
chat_list_wait: 30
|
||||
|
|
12
user.go
12
user.go
|
@ -746,10 +746,14 @@ func (user *User) HandleError(err error) {
|
|||
if closed, ok := err.(*whatsapp.ErrConnectionClosed); ok {
|
||||
user.bridge.Metrics.TrackDisconnection(user.MXID)
|
||||
if closed.Code == 1000 && user.cleanDisconnection {
|
||||
user.bridge.Metrics.TrackConnectionState(user.JID, false)
|
||||
user.cleanDisconnection = false
|
||||
user.log.Infoln("Clean disconnection by server")
|
||||
return
|
||||
if !user.bridge.Config.Bridge.AggressiveReconnect {
|
||||
user.bridge.Metrics.TrackConnectionState(user.JID, false)
|
||||
user.log.Infoln("Clean disconnection by server")
|
||||
return
|
||||
} else {
|
||||
user.log.Debugln("Clean disconnection by server, but aggressive reconnection is enabled")
|
||||
}
|
||||
}
|
||||
go user.tryReconnect(fmt.Sprintf("Your WhatsApp connection was closed with websocket status code %d", closed.Code))
|
||||
} else if failed, ok := err.(*whatsapp.ErrConnectionFailed); ok {
|
||||
|
@ -1084,8 +1088,8 @@ func (user *User) HandleCommand(cmd whatsappExt.Command) {
|
|||
go portal.UpdateAvatar(user, cmd.ProfilePicInfo, true)
|
||||
}
|
||||
case whatsappExt.CommandDisconnect:
|
||||
user.cleanDisconnection = true
|
||||
if cmd.Kind == "replaced" {
|
||||
user.cleanDisconnection = true
|
||||
go user.sendMarkdownBridgeAlert("\u26a0 Your WhatsApp connection was closed by the server because you opened another WhatsApp Web client.\n\n" +
|
||||
"Use the `reconnect` command to disconnect the other client and resume bridging.")
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue