Skip to content

Commit 5cf4168

Browse files
committed
Fix OnICEGatheringStateChange Signature
Return ICEGatheringState not ICEGathererState Relates to #2557
1 parent 6b22634 commit 5cf4168

File tree

3 files changed

+17
-23
lines changed

3 files changed

+17
-23
lines changed

AUTHORS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ Eric Daniels <[email protected]>
6969
Eric Fontaine <[email protected]>
7070
Evan Sonderegger <[email protected]>
7171
72+
7273
Forest Johnson <[email protected]>
7374
7475

peerconnection.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,18 @@ func (pc *PeerConnection) OnICECandidate(f func(*ICECandidate)) {
454454

455455
// OnICEGatheringStateChange sets an event handler which is invoked when the
456456
// ICE candidate gathering state has changed.
457-
func (pc *PeerConnection) OnICEGatheringStateChange(f func(ICEGathererState)) {
458-
pc.iceGatherer.OnStateChange(f)
457+
func (pc *PeerConnection) OnICEGatheringStateChange(f func(ICEGatheringState)) {
458+
pc.iceGatherer.OnStateChange(
459+
func(gathererState ICEGathererState) {
460+
switch gathererState {
461+
case ICEGathererStateGathering:
462+
f(ICEGatheringStateGathering)
463+
case ICEGathererStateComplete:
464+
f(ICEGatheringStateComplete)
465+
default:
466+
// Other states ignored
467+
}
468+
})
459469
}
460470

461471
// OnTrack sets an event handler which is called when remote track

peerconnection_go_test.go

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -619,31 +619,22 @@ func TestOnICEGatheringStateChange(t *testing.T) {
619619
seenComplete := &atomicBool{}
620620

621621
seenGatheringAndComplete := make(chan interface{})
622-
seenClosed := make(chan interface{})
623622

624623
peerConn, err := NewPeerConnection(Configuration{})
625624
assert.NoError(t, err)
626625

627-
var onStateChange func(s ICEGathererState)
628-
onStateChange = func(s ICEGathererState) {
626+
var onStateChange func(s ICEGatheringState)
627+
onStateChange = func(s ICEGatheringState) {
629628
// Access to ICEGatherer in the callback must not cause dead lock.
630629
peerConn.OnICEGatheringStateChange(onStateChange)
631-
if state := peerConn.iceGatherer.State(); state != s {
632-
t.Errorf("State change callback argument (%s) and State() (%s) result differs",
633-
s, state,
634-
)
635-
}
636630

637631
switch s { // nolint:exhaustive
638-
case ICEGathererStateClosed:
639-
close(seenClosed)
640-
return
641-
case ICEGathererStateGathering:
632+
case ICEGatheringStateGathering:
642633
if seenComplete.get() {
643634
t.Error("Completed before gathering")
644635
}
645636
seenGathering.set(true)
646-
case ICEGathererStateComplete:
637+
case ICEGatheringStateComplete:
647638
seenComplete.set(true)
648639
}
649640

@@ -660,18 +651,10 @@ func TestOnICEGatheringStateChange(t *testing.T) {
660651
select {
661652
case <-time.After(time.Second * 10):
662653
t.Fatal("Gathering and Complete were never seen")
663-
case <-seenClosed:
664-
t.Fatal("Closed before PeerConnection Close")
665654
case <-seenGatheringAndComplete:
666655
}
667656

668657
assert.NoError(t, peerConn.Close())
669-
670-
select {
671-
case <-time.After(time.Second * 10):
672-
t.Fatal("Closed was never seen")
673-
case <-seenClosed:
674-
}
675658
}
676659

677660
// Assert Trickle ICE behaviors

0 commit comments

Comments
 (0)