Skip to content

Commit

Permalink
Fix OnICEGatheringStateChange Signature
Browse files Browse the repository at this point in the history
Return ICEGatheringState not ICEGathererState

Relates to #2557
  • Loading branch information
Sean-Der committed Sep 11, 2023
1 parent 6b22634 commit baec069
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
14 changes: 12 additions & 2 deletions peerconnection.go
Expand Up @@ -454,8 +454,18 @@ func (pc *PeerConnection) OnICECandidate(f func(*ICECandidate)) {

// OnICEGatheringStateChange sets an event handler which is invoked when the
// ICE candidate gathering state has changed.
func (pc *PeerConnection) OnICEGatheringStateChange(f func(ICEGathererState)) {
pc.iceGatherer.OnStateChange(f)
func (pc *PeerConnection) OnICEGatheringStateChange(f func(ICEGatheringState)) {
pc.iceGatherer.OnStateChange(
func(gathererState ICEGathererState) {
switch gathererState {
case ICEGathererStateNew:
f(ICEGatheringStateNew)
case ICEGathererStateGathering:
f(ICEGatheringStateGathering)
default:
f(ICEGatheringStateComplete)
}
})
}

// OnTrack sets an event handler which is called when remote track
Expand Down
25 changes: 4 additions & 21 deletions peerconnection_go_test.go
Expand Up @@ -619,31 +619,22 @@ func TestOnICEGatheringStateChange(t *testing.T) {
seenComplete := &atomicBool{}

seenGatheringAndComplete := make(chan interface{})
seenClosed := make(chan interface{})

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

var onStateChange func(s ICEGathererState)
onStateChange = func(s ICEGathererState) {
var onStateChange func(s ICEGatheringState)
onStateChange = func(s ICEGatheringState) {
// Access to ICEGatherer in the callback must not cause dead lock.
peerConn.OnICEGatheringStateChange(onStateChange)
if state := peerConn.iceGatherer.State(); state != s {
t.Errorf("State change callback argument (%s) and State() (%s) result differs",
s, state,
)
}

switch s { // nolint:exhaustive
case ICEGathererStateClosed:
close(seenClosed)
return
case ICEGathererStateGathering:
case ICEGatheringStateGathering:
if seenComplete.get() {
t.Error("Completed before gathering")
}
seenGathering.set(true)
case ICEGathererStateComplete:
case ICEGatheringStateComplete:
seenComplete.set(true)
}

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

assert.NoError(t, peerConn.Close())

select {
case <-time.After(time.Second * 10):
t.Fatal("Closed was never seen")
case <-seenClosed:
}
}

// Assert Trickle ICE behaviors
Expand Down

0 comments on commit baec069

Please sign in to comment.