Thumbnail

rani/matterbridge.git

Clone URL: https://git.buni.party/rani/matterbridge.git

commit b522ff9f2424fb2f72895202d9c9b5416c0f37e8 Author: Wim <wim@42.be> Date: Sat Jul 01 23:28:16 2017 +0000 Optimize StatusLoop. Execute function when specified in OnWsConnect diff --git a/matterclient/matterclient.go b/matterclient/matterclient.go index 91795b3..d389f9b 100644 --- a/matterclient/matterclient.go +++ b/matterclient/matterclient.go @@ -656 +657 @@ type MMClient struct {   WsSequence int64   WsPingChan chan *model.WebSocketResponse   ServerVersion string + OnWsConnect func()  }    func New(login, pass, team, server string) *MMClient { @@ -7246 +72512 @@ func (m *MMClient) GetTeamId() string {  }    func (m *MMClient) StatusLoop() { + retries := 0 + backoff := time.Second * 60 + if m.OnWsConnect != nil { + m.OnWsConnect() + } + m.log.Debug("StatusLoop:", m.OnWsConnect)   for {   if m.WsQuit {   return @@ -73414 +74123 @@ func (m *MMClient) StatusLoop() {   select {   case <-m.WsPingChan:   m.log.Debug("WS PONG received") + backoff = time.Second * 60   case <-time.After(time.Second * 5): - m.Logout() - m.WsQuit = false - m.Login() - go m.WsReceiver() + if retries > 3 { + m.Logout() + m.WsQuit = false + m.Login() + if m.OnWsConnect != nil { + m.OnWsConnect() + } + go m.WsReceiver() + } else { + retries++ + backoff = time.Second * 5 + }   }   } - time.Sleep(time.Second * 60) + time.Sleep(backoff)   }  }