Skip to content

Commit 7c18bbc

Browse files
Hugo ArreguihugoArregui
authored andcommitted
Add ToJSON ICECandidate method
With this change we can always exchange ICECandidateInit when signaling
1 parent 1464ad4 commit 7c18bbc

File tree

5 files changed

+38
-23
lines changed

5 files changed

+38
-23
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/pion/rtcp v1.2.1
1212
github.com/pion/rtp v1.1.3
1313
github.com/pion/sctp v1.6.4
14-
github.com/pion/sdp/v2 v2.2.0
14+
github.com/pion/sdp/v2 v2.3.0
1515
github.com/pion/srtp v1.2.6
1616
github.com/pion/transport v0.8.6
1717
github.com/stretchr/testify v1.3.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ github.com/pion/rtp v1.1.3/go.mod h1:/l4cvcKd0D3u9JLs2xSVI95YkfXW87a3br3nqmVtSlE
4040
github.com/pion/sctp v1.6.3/go.mod h1:cCqpLdYvgEUdl715+qbWtgT439CuQrAgy8BZTp0aEfA=
4141
github.com/pion/sctp v1.6.4 h1:edUNxTabSErLWOdeUUAxds8gwx5kGnFam4zL5DWpILk=
4242
github.com/pion/sctp v1.6.4/go.mod h1:cCqpLdYvgEUdl715+qbWtgT439CuQrAgy8BZTp0aEfA=
43-
github.com/pion/sdp/v2 v2.2.0 h1:JiixCEU8g6LbSsh1Bg5SOk0TPnJrn2HBOA1yJ+mRYhI=
44-
github.com/pion/sdp/v2 v2.2.0/go.mod h1:idSlWxhfWQDtTy9J05cgxpHBu/POwXN2VDRGYxT/EjU=
43+
github.com/pion/sdp/v2 v2.3.0 h1:5EhwPh1xKWYYjjvMuubHoMLy6M0B9U26Hh7q3f7vEGk=
44+
github.com/pion/sdp/v2 v2.3.0/go.mod h1:idSlWxhfWQDtTy9J05cgxpHBu/POwXN2VDRGYxT/EjU=
4545
github.com/pion/srtp v1.2.6 h1:mHQuAMh0P67R7/j1F260u3O+fbRWLyjKLRPZYYvODFM=
4646
github.com/pion/srtp v1.2.6/go.mod h1:rd8imc5htjfs99XiEoOjLMEOcVjME63UHx9Ek9IGst0=
4747
github.com/pion/stun v0.3.1 h1:d09JJzOmOS8ZzIp8NppCMgrxGZpJ4Ix8qirfNYyI3BA=

ice_go.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,3 @@ func newICECandidateFromSDP(c sdp.ICECandidate) (ICECandidate, error) {
5353
RelatedPort: c.RelatedPort,
5454
}, nil
5555
}
56-
57-
func iceCandidateToSDP(c ICECandidate) sdp.ICECandidate {
58-
return sdp.ICECandidate{
59-
Foundation: c.Foundation,
60-
Priority: c.Priority,
61-
Address: c.Address,
62-
Protocol: c.Protocol.String(),
63-
Port: c.Port,
64-
Component: c.Component,
65-
Typ: c.Typ.String(),
66-
RelatedAddress: c.RelatedAddress,
67-
RelatedPort: c.RelatedPort,
68-
}
69-
}

icecandidate.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55

66
"github.com/pion/ice"
7+
"github.com/pion/sdp/v2"
78
)
89

910
// ICECandidate represents a ice candidate
@@ -137,3 +138,24 @@ func (c ICECandidate) String() string {
137138
}
138139
return ic.String()
139140
}
141+
142+
func iceCandidateToSDP(c ICECandidate) sdp.ICECandidate {
143+
return sdp.ICECandidate{
144+
Foundation: c.Foundation,
145+
Priority: c.Priority,
146+
Address: c.Address,
147+
Protocol: c.Protocol.String(),
148+
Port: c.Port,
149+
Component: c.Component,
150+
Typ: c.Typ.String(),
151+
RelatedAddress: c.RelatedAddress,
152+
RelatedPort: c.RelatedPort,
153+
}
154+
}
155+
156+
// ToJSON returns an ICECandidateInit
157+
// as indicated by the spec https://w3c.github.io/webrtc-pc/#dom-rtcicecandidate-tojson
158+
func (c ICECandidate) ToJSON() ICECandidateInit {
159+
var sdpmLineIndex uint16
160+
return ICECandidateInit{Candidate: iceCandidateToSDP(c).Marshal(), SDPMLineIndex: &sdpmLineIndex}
161+
}

peerconnection.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -825,17 +825,21 @@ func (pc *PeerConnection) SetLocalDescription(desc SessionDescription) error {
825825
return err
826826
}
827827

828+
// To support all unittests which are following the future trickle=true
829+
// setup while also support the old trickle=false synchronous gathering
830+
// process this is necessary to avoid calling Garther() in multiple
831+
// pleces; which causes race conditions. (issue-707)
828832
if !pc.iceGatherer.agentIsTrickle {
829-
// To support all unittests which are following the future trickle=true
830-
// setup while also support the old trickle=false synchronous gathering
831-
// process this is necessary to avoid calling Garther() in multiple
832-
// pleces; which causes race conditions. (issue-707)
833833
if err := pc.iceGatherer.SignalCandidates(); err != nil {
834834
return err
835835
}
836836
return nil
837837
}
838-
return pc.iceGatherer.Gather()
838+
839+
if desc.Type == SDPTypeAnswer {
840+
return pc.iceGatherer.Gather()
841+
}
842+
return nil
839843
}
840844

841845
// LocalDescription returns pendingLocalDescription if it is not null and
@@ -850,7 +854,7 @@ func (pc *PeerConnection) LocalDescription() *SessionDescription {
850854
}
851855

852856
// SetRemoteDescription sets the SessionDescription of the remote peer
853-
func (pc *PeerConnection) SetRemoteDescription(desc SessionDescription) error {
857+
func (pc *PeerConnection) SetRemoteDescription(desc SessionDescription) error { //nolint pion/webrtc#614
854858
if pc.currentRemoteDescription != nil { // pion/webrtc#207
855859
return fmt.Errorf("remoteDescription is already defined, SetRemoteDescription can only be called once")
856860
}
@@ -1027,6 +1031,9 @@ func (pc *PeerConnection) SetRemoteDescription(desc SessionDescription) error {
10271031
pc.mu.Unlock()
10281032
}()
10291033

1034+
if (desc.Type == SDPTypeAnswer || desc.Type == SDPTypePranswer) && pc.iceGatherer.agentIsTrickle {
1035+
return pc.iceGatherer.Gather()
1036+
}
10301037
return nil
10311038
}
10321039

0 commit comments

Comments
 (0)