Skip to content
Merged
6 changes: 5 additions & 1 deletion app/viam_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"go.viam.com/utils"
"go.viam.com/utils/rpc"
"google.golang.org/grpc"
"google.golang.org/grpc/connectivity"

"go.viam.com/rdk/logging"
rutils "go.viam.com/rdk/utils"
Expand Down Expand Up @@ -43,7 +44,10 @@ func (m *MockConn) Invoke(ctx context.Context, method string, args, reply any, o
return nil
}
func (m *MockConn) PeerConn() *webrtc.PeerConnection { return nil }
func (m *MockConn) Close() error { return nil }

func (m *MockConn) GetState() connectivity.State { return rpc.Unknown }

func (m *MockConn) Close() error { return nil }
func mockDialDirectGRPC(
ctx context.Context,
address string,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ require (
go.uber.org/zap v1.27.0
go.viam.com/api v0.1.475
go.viam.com/test v1.2.4
go.viam.com/utils v0.1.166
go.viam.com/utils v0.1.167
goji.io v2.0.2+incompatible
golang.org/x/image v0.25.0
golang.org/x/mobile v0.0.0-20240112133503-c713f31d574b
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1534,8 +1534,8 @@ go.viam.com/api v0.1.475 h1:d0lpY/Ibgbv7CzSsET+ujSDRbq1K+xXeV76XXHGcy3s=
go.viam.com/api v0.1.475/go.mod h1:p/am76zx8SZ74V/F4rEAYQIpHaaLUwJgY2q3Uw3FIWk=
go.viam.com/test v1.2.4 h1:JYgZhsuGAQ8sL9jWkziAXN9VJJiKbjoi9BsO33TW3ug=
go.viam.com/test v1.2.4/go.mod h1:zI2xzosHdqXAJ/kFqcN+OIF78kQuTV2nIhGZ8EzvaJI=
go.viam.com/utils v0.1.166 h1:V28UrisivzSMTmVKSiammU9p4cgiWMeBuGN4sUnIZ/k=
go.viam.com/utils v0.1.166/go.mod h1:qZsilNWaD7Fd5WnTAI+s5SkWWxN9YLzImf7JwsB8JLg=
go.viam.com/utils v0.1.167 h1:OnuC5u2YcLTMuwbvyky5yjNDEbQjf0kpoUHoLXhJWz8=
go.viam.com/utils v0.1.167/go.mod h1:qZsilNWaD7Fd5WnTAI+s5SkWWxN9YLzImf7JwsB8JLg=
go4.org/unsafe/assume-no-moving-gc v0.0.0-20230525183740-e7c30c78aeb2 h1:WJhcL4p+YeDxmZWg141nRm7XC8IDmhz7lk5GpadO1Sg=
go4.org/unsafe/assume-no-moving-gc v0.0.0-20230525183740-e7c30c78aeb2/go.mod h1:FftLjUGFEDu5k8lt0ddY+HcrH/qU/0qk+H8j9/nTl3E=
gocv.io/x/gocv v0.25.0/go.mod h1:Rar2PS6DV+T4FL+PM535EImD/h13hGVaHhnCu1xarBs=
Expand Down
10 changes: 10 additions & 0 deletions grpc/app_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"go.viam.com/utils"
"go.viam.com/utils/rpc"
"google.golang.org/grpc/connectivity"

"go.viam.com/rdk/logging"
"go.viam.com/rdk/utils/contextutils"
Expand Down Expand Up @@ -102,6 +103,15 @@ func NewAppConn(ctx context.Context, appAddress, secret, id string, logger loggi
return appConn, nil
}

// GetState returns the current state of the connection.
func (ac *AppConn) GetState() connectivity.State {
if ac.conn == nil {
return connectivity.Connecting
}

return ac.conn.GetState()
}

// Close attempts to close the underlying connection and stops background dialing attempts.
func (ac *AppConn) Close() error {
if ac.dialer != nil {
Expand Down
13 changes: 13 additions & 0 deletions grpc/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"go.viam.com/utils/rpc"
"golang.org/x/exp/maps"
googlegrpc "google.golang.org/grpc"
"google.golang.org/grpc/connectivity"

"go.viam.com/rdk/logging"
)
Expand Down Expand Up @@ -101,6 +102,18 @@ func (c *ReconfigurableClientConn) PeerConn() *webrtc.PeerConnection {
return c.conn.PeerConn()
}

// GetState returns the current state of the connection.
func (c *ReconfigurableClientConn) GetState() connectivity.State {
c.connMu.RLock()
defer c.connMu.RUnlock()

if c.conn == nil {
return rpc.Unknown
}

return c.conn.GetState()
}

// Close attempts to close the underlying client connection if there is one.
func (c *ReconfigurableClientConn) Close() error {
c.connMu.Lock()
Expand Down
7 changes: 7 additions & 0 deletions grpc/shared_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"go.viam.com/utils/rpc"
"golang.org/x/exp/maps"
googlegrpc "google.golang.org/grpc"
"google.golang.org/grpc/connectivity"

"go.viam.com/rdk/logging"
rutils "go.viam.com/rdk/utils"
Expand Down Expand Up @@ -359,6 +360,12 @@ func (sc *SharedConn) ProcessEncodedAnswer(encodedAnswer string) error {
return nil
}

// GetState returns the current state of the connection.
func (sc *SharedConn) GetState() connectivity.State {
// TODO: RSDK-11849 - Handle surfacing dual connectivity states (grpc + webrtc).
return rpc.Unknown
}

// Close closes a shared connection.
func (sc *SharedConn) Close() error {
var err error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ func (*NoOpClientConn) PeerConn() *webrtc.PeerConnection {
return nil
}

func (*NoOpClientConn) GetState() connectivity.State {
return rpc.Unknown
}

func (*NoOpClientConn) Close() error {
return nil
}
Loading