From e55463fc9829bbed582baaa8741fc59bc2a9913f Mon Sep 17 00:00:00 2001 From: Bohdan Horbeshko Date: Sat, 18 Dec 2021 10:33:13 -0500 Subject: [PATCH] Fix passing Component to StreamManager 0a4acd12c34b0048ff7554b7c56ddce975eb9286, which fixes #160, introduced a regression as it assumed only Client may implement StreamClient, and passing a component triggers an unconditional "client is not disconnected" error. --- stream_manager.go | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/stream_manager.go b/stream_manager.go index 7bfb42c..a671f5e 100644 --- a/stream_manager.go +++ b/stream_manager.go @@ -114,18 +114,23 @@ 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 + var scs *SyncConnState + if client, ok := sm.client.(*Client); ok { + scs = &client.CurrentState + } + if component, ok := sm.client.(*Component); ok { + scs = &component.CurrentState + } + if scs != nil && scs.getState() == StateDisconnected { + sm.Metrics = initMetrics() + err := sm.client.Connect() + if err != nil { + return err } + if sm.PostConnect != nil { + sm.PostConnect(sm.client) + } + return nil } } return errors.New("client is not disconnected")