mirror of
https://github.com/netbirdio/netbird.git
synced 2026-08-28 18:41:30 +02:00
Losing the last network only flipped the availability state: the dead management, signal and relay sockets stayed silently connected until their own timeouts, so the client kept reporting Connected with no network at all. Introduce client/netevents with a Manager that ties the availability state, the connection sweeper and the status recorder together, and move the netstate and netsweep packages under it (netsweep renamed to sweep). SetNetworkAvailable(false) now also sweeps the registered connections so their owners redial and the listener reaches the NoNetwork state. The Android and iOS bindings own a Manager instance and inject it through the constructors; consumers hold the concrete *Manager whose nil zero value reports always-online and never sweeps, with interfaces kept only as parameter contracts. The relay guard settle wait moved into the Manager as WaitSettled, removing the netevents import from the relay package.
27 lines
808 B
Go
27 lines
808 B
Go
package grpc
|
|
|
|
import (
|
|
"context"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"github.com/netbirdio/netbird/client/netevents/sweep"
|
|
"github.com/netbirdio/netbird/util/wsproxy/client"
|
|
)
|
|
|
|
// Sweeper registers in-flight dials for the network change sweep.
|
|
type Sweeper interface {
|
|
StartDial(ctx context.Context) *sweep.Dial
|
|
}
|
|
|
|
// WithCustomDialer returns a gRPC dial option that uses WebSocket transport for WASM/JS environments.
|
|
// The component parameter specifies the WebSocket proxy component path (e.g., "/management", "/signal").
|
|
func WithCustomDialer(tlsEnabled bool, component string) grpc.DialOption {
|
|
return client.WithWebSocketDialer(tlsEnabled, component)
|
|
}
|
|
|
|
// WithSweeper is a no-op on WASM/JS: there is no network change signal.
|
|
func WithSweeper(_ Sweeper) grpc.DialOption {
|
|
return grpc.EmptyDialOption{}
|
|
}
|