Remove the on reconnect callback from client layer. This event will be managed by guard.

This commit is contained in:
Zoltán Papp
2025-01-29 13:25:03 +01:00
parent e20be2397c
commit 14a99a8693
3 changed files with 65 additions and 42 deletions

View File

@@ -141,7 +141,6 @@ type Client struct {
muInstanceURL sync.Mutex
onDisconnectListener func(string)
onConnectedListener func()
listenerMutex sync.Mutex
}
@@ -190,7 +189,6 @@ func (c *Client) Connect() error {
c.wgReadLoop.Add(1)
go c.readLoop(c.relayConn)
go c.notifyConnected()
return nil
}
@@ -238,12 +236,6 @@ func (c *Client) SetOnDisconnectListener(fn func(string)) {
c.onDisconnectListener = fn
}
func (c *Client) SetOnConnectedListener(fn func()) {
c.listenerMutex.Lock()
defer c.listenerMutex.Unlock()
c.onConnectedListener = fn
}
// HasConns returns true if there are connections.
func (c *Client) HasConns() bool {
c.mu.Lock()
@@ -559,16 +551,6 @@ func (c *Client) notifyDisconnected() {
go c.onDisconnectListener(c.connectionURL)
}
func (c *Client) notifyConnected() {
c.listenerMutex.Lock()
defer c.listenerMutex.Unlock()
if c.onConnectedListener == nil {
return
}
go c.onConnectedListener()
}
func (c *Client) writeCloseMsg() {
msg := messages.MarshalCloseMsg()
_, err := c.relayConn.Write(msg)