From ddb8c5a1eb5c2093815fee70998a44752f692c51 Mon Sep 17 00:00:00 2001 From: Dave Johnston Date: Fri, 4 Sep 2020 10:54:47 +0100 Subject: [PATCH] Fix `connect()` to work with external component --- stream_manager.go | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/stream_manager.go b/stream_manager.go index 7bfb42c..c09f183 100644 --- a/stream_manager.go +++ b/stream_manager.go @@ -113,22 +113,27 @@ func (sm *StreamManager) Stop() { } func (sm *StreamManager) connect() error { - if sm.client != nil { - if c, ok := sm.client.(*Client); ok { - if c.CurrentState.getState() == StateDisconnected { - sm.Metrics = initMetrics() - err := c.Connect() - if err != nil { - return err - } - if sm.PostConnect != nil { - sm.PostConnect(sm.client) - } - return nil - } + if sm.client == nil { + return errors.New("client is not set") + } + + if c, ok := sm.client.(*Client); ok { + if c.CurrentState.getState() != StateDisconnected { + return errors.New("client is not disconnected") } } - return errors.New("client is not disconnected") + + sm.Metrics = initMetrics() + + if err := sm.client.Connect(); err != nil { + return err + } + + if sm.PostConnect != nil { + sm.PostConnect(sm.client) + } + + return nil } // resume manages the reconnection loop and apply the define backoff to avoid overloading the server.