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 58bfbbc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Eric Daniels <[email protected]>
Eric Fontaine <[email protected]>
Evan Sonderegger <[email protected]>
feixiao <[email protected]>
forest <[email protected]>
Forest Johnson <[email protected]>
frank <[email protected]>
funvit <[email protected]>
Expand Down
14 changes: 12 additions & 2 deletions peerconnection.go
Original file line number Diff line number Diff line change
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 ICEGathererStateGathering:
f(ICEGatheringStateGathering)
case ICEGathererStateComplete:
f(ICEGatheringStateComplete)
default:
// Other states ignored
}
})
}

// OnTrack sets an event handler which is called when remote track
Expand Down
25 changes: 4 additions & 21 deletions peerconnection_go_test.go
Original file line number Diff line number Diff line change
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 58bfbbc

Please sign in to comment.