Fix connect() to work with external component

This commit is contained in:
Dave Johnston 2020-09-04 10:54:47 +01:00 committed by GitHub
parent ac5b066815
commit ddb8c5a1eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -113,22 +113,27 @@ func (sm *StreamManager) Stop() {
} }
func (sm *StreamManager) connect() error { func (sm *StreamManager) connect() error {
if sm.client != nil { if sm.client == nil {
return errors.New("client is not set")
}
if c, ok := sm.client.(*Client); ok { if c, ok := sm.client.(*Client); ok {
if c.CurrentState.getState() == StateDisconnected { if c.CurrentState.getState() != StateDisconnected {
return errors.New("client is not disconnected")
}
}
sm.Metrics = initMetrics() sm.Metrics = initMetrics()
err := c.Connect()
if err != nil { if err := sm.client.Connect(); err != nil {
return err return err
} }
if sm.PostConnect != nil { if sm.PostConnect != nil {
sm.PostConnect(sm.client) sm.PostConnect(sm.client)
} }
return nil return nil
}
}
}
return errors.New("client is not disconnected")
} }
// resume manages the reconnection loop and apply the define backoff to avoid overloading the server. // resume manages the reconnection loop and apply the define backoff to avoid overloading the server.