Make connection timeout configurable

This commit is contained in:
Tulir Asokan 2019-05-16 18:08:30 +03:00
parent 5d0edda04a
commit b5af35684d
2 changed files with 7 additions and 1 deletions

View file

@ -33,6 +33,8 @@ type BridgeConfig struct {
UsernameTemplate string `yaml:"username_template"`
DisplaynameTemplate string `yaml:"displayname_template"`
ConnectionTimeout int `yaml:"connection_timeout"`
CommandPrefix string `yaml:"command_prefix"`
Permissions PermissionConfig `yaml:"permissions"`

View file

@ -145,7 +145,11 @@ func (user *User) Connect(evenIfNoSession bool) bool {
return false
}
user.log.Debugln("Connecting to WhatsApp")
conn, err := whatsapp.NewConn(20 * time.Second)
timeout := time.Duration(user.bridge.Config.Bridge.ConnectionTimeout)
if timeout == 0 {
timeout = 20
}
conn, err := whatsapp.NewConn(timeout * time.Second)
if err != nil {
user.log.Errorln("Failed to connect to WhatsApp:", err)
return false