mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-18 08:16:39 +00:00
Add OnDisconnecting service callback (#767)
Add OnDisconnecting service callback for mobile
This commit is contained in:
@@ -8,6 +8,7 @@ const (
|
||||
stateDisconnected = iota
|
||||
stateConnected
|
||||
stateConnecting
|
||||
stateDisconnecting
|
||||
)
|
||||
|
||||
type notifier struct {
|
||||
@@ -57,8 +58,12 @@ func (n *notifier) updateServerStates(mgmState bool, signalState bool) {
|
||||
}
|
||||
|
||||
n.currentServerState = newState
|
||||
n.lastNotification = n.calculateState(newState, n.currentClientState)
|
||||
|
||||
if n.lastNotification == stateDisconnecting {
|
||||
return
|
||||
}
|
||||
|
||||
n.lastNotification = n.calculateState(newState, n.currentClientState)
|
||||
go n.notifyAll(n.lastNotification)
|
||||
}
|
||||
|
||||
@@ -78,6 +83,14 @@ func (n *notifier) clientStop() {
|
||||
go n.notifyAll(n.lastNotification)
|
||||
}
|
||||
|
||||
func (n *notifier) clientTearDown() {
|
||||
n.serverStateLock.Lock()
|
||||
defer n.serverStateLock.Unlock()
|
||||
n.currentClientState = false
|
||||
n.lastNotification = stateDisconnecting
|
||||
go n.notifyAll(n.lastNotification)
|
||||
}
|
||||
|
||||
func (n *notifier) isServerStateChanged(newState bool) bool {
|
||||
return n.currentServerState != newState
|
||||
}
|
||||
@@ -99,6 +112,8 @@ func (n *notifier) notifyListener(l Listener, state int) {
|
||||
l.OnConnected()
|
||||
case stateConnecting:
|
||||
l.OnConnecting()
|
||||
case stateDisconnecting:
|
||||
l.OnDisconnecting()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user