diff --git a/ctestenums.cc b/ctestenums.cc index fbc6239..507e3be 100644 --- a/ctestenums.cc +++ b/ctestenums.cc @@ -3,6 +3,11 @@ using namespace webrtc; +/* +In order to match native enums with Go enum values, it is necessary to +expose the values to CGO identifiers which Go can access. +*/ + const int CGO_IceTransportPolicyNone = PeerConnectionInterface::IceTransportsType::kNone; const int CGO_IceTransportPolicyRelay = @@ -38,6 +43,21 @@ const int CGO_SignalingStateHaveRemotePrAnswer = const int CGO_SignalingStateClosed = PeerConnectionInterface::SignalingState::kClosed; +const int CGO_IceConnectionStateNew = + PeerConnectionInterface::IceConnectionState::kIceConnectionNew; +const int CGO_IceConnectionStateChecking = + PeerConnectionInterface::IceConnectionState::kIceConnectionChecking; +const int CGO_IceConnectionStateConnected = + PeerConnectionInterface::IceConnectionState::kIceConnectionConnected; +const int CGO_IceConnectionStateCompleted = + PeerConnectionInterface::IceConnectionState::kIceConnectionCompleted; +const int CGO_IceConnectionStateFailed = + PeerConnectionInterface::IceConnectionState::kIceConnectionFailed; +const int CGO_IceConnectionStateDisconnected = + PeerConnectionInterface::IceConnectionState::kIceConnectionDisconnected; +const int CGO_IceConnectionStateClosed = + PeerConnectionInterface::IceConnectionState::kIceConnectionClosed; + const int CGO_IceGatheringStateNew = PeerConnectionInterface::IceGatheringState::kIceGatheringNew; const int CGO_IceGatheringStateGathering = diff --git a/ctestenums.h b/ctestenums.h index 824bb55..13ec2b7 100644 --- a/ctestenums.h +++ b/ctestenums.h @@ -29,6 +29,14 @@ extern "C" { extern const int CGO_SignalingStateHaveRemotePrAnswer; extern const int CGO_SignalingStateClosed; + extern const int CGO_IceConnectionStateNew; + extern const int CGO_IceConnectionStateChecking; + extern const int CGO_IceConnectionStateConnected; + extern const int CGO_IceConnectionStateCompleted; + extern const int CGO_IceConnectionStateFailed; + extern const int CGO_IceConnectionStateDisconnected; + extern const int CGO_IceConnectionStateClosed; + extern const int CGO_IceGatheringStateNew; extern const int CGO_IceGatheringStateGathering; extern const int CGO_IceGatheringStateComplete; diff --git a/peerconnection.go b/peerconnection.go index 0f09e2e..c13dfec 100644 --- a/peerconnection.go +++ b/peerconnection.go @@ -53,6 +53,7 @@ func init() { type ( PeerConnectionState int IceGatheringState int + IceConnectionState int ) const ( @@ -66,6 +67,20 @@ const ( var PeerConnectionStateString = []string{ "New", "Connecting", "Connected", "Disconnected", "Failed"} +const ( + IceConnectionStateNew IceConnectionState = iota + IceConnectionStateChecking + IceConnectionStateConnected + IceConnectionStateCompleted + IceConnectionStateFailed + IceConnectionStateDisconnected + IceConnectionStateClosed +) + +var IceConnectionStateString = []string{ + "New", "Checking", "Connected", "Completed", + "Failed", "Disconnected", "Closed"} + const ( IceGatheringStateNew IceGatheringState = iota IceGatheringStateGathering @@ -83,15 +98,8 @@ negotiation to setting up Data Channels. See: https://w3c.github.io/webrtc-pc/#idl-def-RTCPeerConnection */ type PeerConnection struct { - localDescription *SessionDescription - // currentLocalDescription - // pendingLocalDescription - - remoteDescription *SessionDescription - // currentRemoteDescription - // pendingRemoteDescription - - // iceConnectionState IceConnectionState + localDescription *SessionDescription + remoteDescription *SessionDescription canTrickleIceCandidates bool // Event handlers @@ -243,6 +251,11 @@ func (pc *PeerConnection) IceGatheringState() IceGatheringState { return (IceGatheringState)(C.CGO_IceGatheringState(pc.cgoPeer)) } +// readonly iceconnectionState +func (pc *PeerConnection) IceConnectionState() IceConnectionState { + return (IceConnectionState)(C.CGO_IceConnectionState(pc.cgoPeer)) +} + func (pc *PeerConnection) AddIceCandidate(ic IceCandidate) error { sdpMid := C.CString(ic.SdpMid) defer C.free(unsafe.Pointer(sdpMid)) @@ -392,6 +405,14 @@ func cgoOnDataChannel(p unsafe.Pointer, cDC C.CGO_Channel) { // Test helpers // +var _cgoIceConnectionStateNew = int(C.CGO_IceConnectionStateNew) +var _cgoIceConnectionStateChecking = int(C.CGO_IceConnectionStateChecking) +var _cgoIceConnectionStateConnected = int(C.CGO_IceConnectionStateConnected) +var _cgoIceConnectionStateCompleted = int(C.CGO_IceConnectionStateCompleted) +var _cgoIceConnectionStateFailed = int(C.CGO_IceConnectionStateFailed) +var _cgoIceConnectionStateDisconnected = int(C.CGO_IceConnectionStateDisconnected) +var _cgoIceConnectionStateClosed = int(C.CGO_IceConnectionStateClosed) + var _cgoIceGatheringStateNew = int(C.CGO_IceGatheringStateNew) var _cgoIceGatheringStateGathering = int(C.CGO_IceGatheringStateGathering) var _cgoIceGatheringStateComplete = int(C.CGO_IceGatheringStateComplete) diff --git a/webrtc_test.go b/webrtc_test.go index b0f01bd..c54ca7e 100644 --- a/webrtc_test.go +++ b/webrtc_test.go @@ -17,6 +17,22 @@ C++ webrtc::PeerConnectionInterface values`, t, func() { }) } +func TestIceConnectionStateEnums(t *testing.T) { + Convey(`Enum: IceConnectionState values should match +C++ webrtc::PeerConnectionInterface values`, t, func() { + So(IceConnectionStateNew, ShouldEqual, _cgoIceConnectionStateNew) + So(IceConnectionStateChecking, ShouldEqual, _cgoIceConnectionStateChecking) + So(IceConnectionStateConnected, ShouldEqual, + _cgoIceConnectionStateConnected) + So(IceConnectionStateCompleted, ShouldEqual, + _cgoIceConnectionStateCompleted) + So(IceConnectionStateFailed, ShouldEqual, _cgoIceConnectionStateFailed) + So(IceConnectionStateDisconnected, ShouldEqual, + _cgoIceConnectionStateDisconnected) + So(IceConnectionStateClosed, ShouldEqual, _cgoIceConnectionStateClosed) + }) +} + func TestPeerConnection(t *testing.T) { SetLoggingVerbosity(0) @@ -37,6 +53,7 @@ func TestPeerConnection(t *testing.T) { So(err, ShouldBeNil) So(pc.ConnectionState(), ShouldEqual, PeerConnectionStateNew) So(pc.IceGatheringState(), ShouldEqual, IceGatheringStateNew) + So(pc.IceConnectionState(), ShouldEqual, IceConnectionStateNew) Convey("Set and Get Configuration", func() { config := NewConfiguration(