From 7c18bbcceed776b547a44a0b921284db7d4bc69a Mon Sep 17 00:00:00 2001 From: Hugo Arregui Date: Tue, 30 Jul 2019 10:05:47 -0300 Subject: [PATCH] Add ToJSON ICECandidate method With this change we can always exchange ICECandidateInit when signaling --- go.mod | 2 +- go.sum | 4 ++-- ice_go.go | 14 -------------- icecandidate.go | 22 ++++++++++++++++++++++ peerconnection.go | 19 +++++++++++++------ 5 files changed, 38 insertions(+), 23 deletions(-) diff --git a/go.mod b/go.mod index 0325e23ef08..aff94ce6cd8 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/pion/rtcp v1.2.1 github.com/pion/rtp v1.1.3 github.com/pion/sctp v1.6.4 - github.com/pion/sdp/v2 v2.2.0 + github.com/pion/sdp/v2 v2.3.0 github.com/pion/srtp v1.2.6 github.com/pion/transport v0.8.6 github.com/stretchr/testify v1.3.0 diff --git a/go.sum b/go.sum index b0e0b353c65..db813bee38b 100644 --- a/go.sum +++ b/go.sum @@ -40,8 +40,8 @@ github.com/pion/rtp v1.1.3/go.mod h1:/l4cvcKd0D3u9JLs2xSVI95YkfXW87a3br3nqmVtSlE github.com/pion/sctp v1.6.3/go.mod h1:cCqpLdYvgEUdl715+qbWtgT439CuQrAgy8BZTp0aEfA= github.com/pion/sctp v1.6.4 h1:edUNxTabSErLWOdeUUAxds8gwx5kGnFam4zL5DWpILk= github.com/pion/sctp v1.6.4/go.mod h1:cCqpLdYvgEUdl715+qbWtgT439CuQrAgy8BZTp0aEfA= -github.com/pion/sdp/v2 v2.2.0 h1:JiixCEU8g6LbSsh1Bg5SOk0TPnJrn2HBOA1yJ+mRYhI= -github.com/pion/sdp/v2 v2.2.0/go.mod h1:idSlWxhfWQDtTy9J05cgxpHBu/POwXN2VDRGYxT/EjU= +github.com/pion/sdp/v2 v2.3.0 h1:5EhwPh1xKWYYjjvMuubHoMLy6M0B9U26Hh7q3f7vEGk= +github.com/pion/sdp/v2 v2.3.0/go.mod h1:idSlWxhfWQDtTy9J05cgxpHBu/POwXN2VDRGYxT/EjU= github.com/pion/srtp v1.2.6 h1:mHQuAMh0P67R7/j1F260u3O+fbRWLyjKLRPZYYvODFM= github.com/pion/srtp v1.2.6/go.mod h1:rd8imc5htjfs99XiEoOjLMEOcVjME63UHx9Ek9IGst0= github.com/pion/stun v0.3.1 h1:d09JJzOmOS8ZzIp8NppCMgrxGZpJ4Ix8qirfNYyI3BA= diff --git a/ice_go.go b/ice_go.go index 167268e42a3..2e412c1c254 100644 --- a/ice_go.go +++ b/ice_go.go @@ -53,17 +53,3 @@ func newICECandidateFromSDP(c sdp.ICECandidate) (ICECandidate, error) { RelatedPort: c.RelatedPort, }, nil } - -func iceCandidateToSDP(c ICECandidate) sdp.ICECandidate { - return sdp.ICECandidate{ - Foundation: c.Foundation, - Priority: c.Priority, - Address: c.Address, - Protocol: c.Protocol.String(), - Port: c.Port, - Component: c.Component, - Typ: c.Typ.String(), - RelatedAddress: c.RelatedAddress, - RelatedPort: c.RelatedPort, - } -} diff --git a/icecandidate.go b/icecandidate.go index 38e858dd966..c8e3f3110c9 100644 --- a/icecandidate.go +++ b/icecandidate.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/pion/ice" + "github.com/pion/sdp/v2" ) // ICECandidate represents a ice candidate @@ -137,3 +138,24 @@ func (c ICECandidate) String() string { } return ic.String() } + +func iceCandidateToSDP(c ICECandidate) sdp.ICECandidate { + return sdp.ICECandidate{ + Foundation: c.Foundation, + Priority: c.Priority, + Address: c.Address, + Protocol: c.Protocol.String(), + Port: c.Port, + Component: c.Component, + Typ: c.Typ.String(), + RelatedAddress: c.RelatedAddress, + RelatedPort: c.RelatedPort, + } +} + +// ToJSON returns an ICECandidateInit +// as indicated by the spec https://w3c.github.io/webrtc-pc/#dom-rtcicecandidate-tojson +func (c ICECandidate) ToJSON() ICECandidateInit { + var sdpmLineIndex uint16 + return ICECandidateInit{Candidate: iceCandidateToSDP(c).Marshal(), SDPMLineIndex: &sdpmLineIndex} +} diff --git a/peerconnection.go b/peerconnection.go index ad2d46eda01..c6f04931df4 100644 --- a/peerconnection.go +++ b/peerconnection.go @@ -825,17 +825,21 @@ func (pc *PeerConnection) SetLocalDescription(desc SessionDescription) error { return err } + // To support all unittests which are following the future trickle=true + // setup while also support the old trickle=false synchronous gathering + // process this is necessary to avoid calling Garther() in multiple + // pleces; which causes race conditions. (issue-707) if !pc.iceGatherer.agentIsTrickle { - // To support all unittests which are following the future trickle=true - // setup while also support the old trickle=false synchronous gathering - // process this is necessary to avoid calling Garther() in multiple - // pleces; which causes race conditions. (issue-707) if err := pc.iceGatherer.SignalCandidates(); err != nil { return err } return nil } - return pc.iceGatherer.Gather() + + if desc.Type == SDPTypeAnswer { + return pc.iceGatherer.Gather() + } + return nil } // LocalDescription returns pendingLocalDescription if it is not null and @@ -850,7 +854,7 @@ func (pc *PeerConnection) LocalDescription() *SessionDescription { } // SetRemoteDescription sets the SessionDescription of the remote peer -func (pc *PeerConnection) SetRemoteDescription(desc SessionDescription) error { +func (pc *PeerConnection) SetRemoteDescription(desc SessionDescription) error { //nolint pion/webrtc#614 if pc.currentRemoteDescription != nil { // pion/webrtc#207 return fmt.Errorf("remoteDescription is already defined, SetRemoteDescription can only be called once") } @@ -1027,6 +1031,9 @@ func (pc *PeerConnection) SetRemoteDescription(desc SessionDescription) error { pc.mu.Unlock() }() + if (desc.Type == SDPTypeAnswer || desc.Type == SDPTypePranswer) && pc.iceGatherer.agentIsTrickle { + return pc.iceGatherer.Gather() + } return nil }