From 5cf4168432699aa28dd38765d93c18878b51f8bc Mon Sep 17 00:00:00 2001 From: Sean DuBois Date: Mon, 11 Sep 2023 10:06:54 -0400 Subject: [PATCH] Fix OnICEGatheringStateChange Signature Return ICEGatheringState not ICEGathererState Relates to #2557 --- AUTHORS.txt | 1 + peerconnection.go | 14 ++++++++++++-- peerconnection_go_test.go | 25 ++++--------------------- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/AUTHORS.txt b/AUTHORS.txt index 799ddfc2b68..e9ab3dc328d 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -69,6 +69,7 @@ Eric Daniels Eric Fontaine Evan Sonderegger feixiao +forest Forest Johnson frank funvit diff --git a/peerconnection.go b/peerconnection.go index ef61d9e0663..ec2425fba6c 100644 --- a/peerconnection.go +++ b/peerconnection.go @@ -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 diff --git a/peerconnection_go_test.go b/peerconnection_go_test.go index 8e672fd3613..146d7726cad 100644 --- a/peerconnection_go_test.go +++ b/peerconnection_go_test.go @@ -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) } @@ -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