From baec06907f9cd53dc7dd0e80d7bca6739c124ff6 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 --- peerconnection.go | 14 ++++++++++++-- peerconnection_go_test.go | 25 ++++--------------------- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/peerconnection.go b/peerconnection.go index ef61d9e0663..cf4fdcdede2 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 ICEGathererStateNew: + f(ICEGatheringStateNew) + case ICEGathererStateGathering: + f(ICEGatheringStateGathering) + default: + f(ICEGatheringStateComplete) + } + }) } // 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