mirror of
https://github.com/pion/webrtc.git
synced 2025-10-06 15:46:54 +08:00
API: Avoid exposing pkg/ice
OnICEConnectionStateChange now return a ICEConnectionState instead of ice.ConnectionState. Resolves #422
This commit is contained in:

committed by
Michiel De Backker

parent
ad647c28d7
commit
bf422e0c0a
@@ -8,7 +8,6 @@ import (
|
|||||||
"github.com/pions/webrtc"
|
"github.com/pions/webrtc"
|
||||||
"github.com/pions/webrtc/examples/util"
|
"github.com/pions/webrtc/examples/util"
|
||||||
"github.com/pions/webrtc/pkg/datachannel"
|
"github.com/pions/webrtc/pkg/datachannel"
|
||||||
"github.com/pions/webrtc/pkg/ice"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -32,7 +31,7 @@ func main() {
|
|||||||
|
|
||||||
// Set the handler for ICE connection state
|
// Set the handler for ICE connection state
|
||||||
// This will notify you when the peer has connected/disconnected
|
// This will notify you when the peer has connected/disconnected
|
||||||
peerConnection.OnICEConnectionStateChange(func(connectionState ice.ConnectionState) {
|
peerConnection.OnICEConnectionStateChange(func(connectionState webrtc.ICEConnectionState) {
|
||||||
fmt.Printf("ICE Connection State has changed: %s\n", connectionState.String())
|
fmt.Printf("ICE Connection State has changed: %s\n", connectionState.String())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -7,7 +7,6 @@ import (
|
|||||||
"github.com/pions/webrtc"
|
"github.com/pions/webrtc"
|
||||||
"github.com/pions/webrtc/examples/util"
|
"github.com/pions/webrtc/examples/util"
|
||||||
"github.com/pions/webrtc/pkg/datachannel"
|
"github.com/pions/webrtc/pkg/datachannel"
|
||||||
"github.com/pions/webrtc/pkg/ice"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -32,7 +31,7 @@ func main() {
|
|||||||
|
|
||||||
// Set the handler for ICE connection state
|
// Set the handler for ICE connection state
|
||||||
// This will notify you when the peer has connected/disconnected
|
// This will notify you when the peer has connected/disconnected
|
||||||
peerConnection.OnICEConnectionStateChange(func(connectionState ice.ConnectionState) {
|
peerConnection.OnICEConnectionStateChange(func(connectionState webrtc.ICEConnectionState) {
|
||||||
fmt.Printf("ICE Connection State has changed: %s\n", connectionState.String())
|
fmt.Printf("ICE Connection State has changed: %s\n", connectionState.String())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -7,7 +7,6 @@ import (
|
|||||||
"github.com/pions/datachannel"
|
"github.com/pions/datachannel"
|
||||||
"github.com/pions/webrtc"
|
"github.com/pions/webrtc"
|
||||||
"github.com/pions/webrtc/examples/util"
|
"github.com/pions/webrtc/examples/util"
|
||||||
"github.com/pions/webrtc/pkg/ice"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const messageSize = 15
|
const messageSize = 15
|
||||||
@@ -39,7 +38,7 @@ func main() {
|
|||||||
|
|
||||||
// Set the handler for ICE connection state
|
// Set the handler for ICE connection state
|
||||||
// This will notify you when the peer has connected/disconnected
|
// This will notify you when the peer has connected/disconnected
|
||||||
peerConnection.OnICEConnectionStateChange(func(connectionState ice.ConnectionState) {
|
peerConnection.OnICEConnectionStateChange(func(connectionState webrtc.ICEConnectionState) {
|
||||||
fmt.Printf("ICE Connection State has changed: %s\n", connectionState.String())
|
fmt.Printf("ICE Connection State has changed: %s\n", connectionState.String())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -7,7 +7,6 @@ import (
|
|||||||
"github.com/pions/datachannel"
|
"github.com/pions/datachannel"
|
||||||
"github.com/pions/webrtc"
|
"github.com/pions/webrtc"
|
||||||
"github.com/pions/webrtc/examples/util"
|
"github.com/pions/webrtc/examples/util"
|
||||||
"github.com/pions/webrtc/pkg/ice"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const messageSize = 15
|
const messageSize = 15
|
||||||
@@ -35,7 +34,7 @@ func main() {
|
|||||||
|
|
||||||
// Set the handler for ICE connection state
|
// Set the handler for ICE connection state
|
||||||
// This will notify you when the peer has connected/disconnected
|
// This will notify you when the peer has connected/disconnected
|
||||||
peerConnection.OnICEConnectionStateChange(func(connectionState ice.ConnectionState) {
|
peerConnection.OnICEConnectionStateChange(func(connectionState webrtc.ICEConnectionState) {
|
||||||
fmt.Printf("ICE Connection State has changed: %s\n", connectionState.String())
|
fmt.Printf("ICE Connection State has changed: %s\n", connectionState.String())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -7,7 +7,6 @@ import (
|
|||||||
"github.com/pions/webrtc"
|
"github.com/pions/webrtc"
|
||||||
"github.com/pions/webrtc/examples/util"
|
"github.com/pions/webrtc/examples/util"
|
||||||
"github.com/pions/webrtc/pkg/datachannel"
|
"github.com/pions/webrtc/pkg/datachannel"
|
||||||
"github.com/pions/webrtc/pkg/ice"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -28,7 +27,7 @@ func main() {
|
|||||||
|
|
||||||
// Set the handler for ICE connection state
|
// Set the handler for ICE connection state
|
||||||
// This will notify you when the peer has connected/disconnected
|
// This will notify you when the peer has connected/disconnected
|
||||||
peerConnection.OnICEConnectionStateChange(func(connectionState ice.ConnectionState) {
|
peerConnection.OnICEConnectionStateChange(func(connectionState webrtc.ICEConnectionState) {
|
||||||
fmt.Printf("ICE Connection State has changed: %s\n", connectionState.String())
|
fmt.Printf("ICE Connection State has changed: %s\n", connectionState.String())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -9,7 +9,6 @@ import (
|
|||||||
"github.com/pions/webrtc"
|
"github.com/pions/webrtc"
|
||||||
"github.com/pions/webrtc/examples/util"
|
"github.com/pions/webrtc/examples/util"
|
||||||
gst "github.com/pions/webrtc/examples/util/gstreamer-sink"
|
gst "github.com/pions/webrtc/examples/util/gstreamer-sink"
|
||||||
"github.com/pions/webrtc/pkg/ice"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// gstreamerReceiveMain is launched in a goroutine because the main thread is needed
|
// gstreamerReceiveMain is launched in a goroutine because the main thread is needed
|
||||||
@@ -61,7 +60,7 @@ func gstreamerReceiveMain() {
|
|||||||
|
|
||||||
// Set the handler for ICE connection state
|
// Set the handler for ICE connection state
|
||||||
// This will notify you when the peer has connected/disconnected
|
// This will notify you when the peer has connected/disconnected
|
||||||
peerConnection.OnICEConnectionStateChange(func(connectionState ice.ConnectionState) {
|
peerConnection.OnICEConnectionStateChange(func(connectionState webrtc.ICEConnectionState) {
|
||||||
fmt.Printf("Connection State has changed %s \n", connectionState.String())
|
fmt.Printf("Connection State has changed %s \n", connectionState.String())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -6,7 +6,6 @@ import (
|
|||||||
"github.com/pions/webrtc"
|
"github.com/pions/webrtc"
|
||||||
"github.com/pions/webrtc/examples/util"
|
"github.com/pions/webrtc/examples/util"
|
||||||
gst "github.com/pions/webrtc/examples/util/gstreamer-src"
|
gst "github.com/pions/webrtc/examples/util/gstreamer-src"
|
||||||
"github.com/pions/webrtc/pkg/ice"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -31,7 +30,7 @@ func main() {
|
|||||||
|
|
||||||
// Set the handler for ICE connection state
|
// Set the handler for ICE connection state
|
||||||
// This will notify you when the peer has connected/disconnected
|
// This will notify you when the peer has connected/disconnected
|
||||||
peerConnection.OnICEConnectionStateChange(func(connectionState ice.ConnectionState) {
|
peerConnection.OnICEConnectionStateChange(func(connectionState webrtc.ICEConnectionState) {
|
||||||
fmt.Printf("Connection State has changed %s \n", connectionState.String())
|
fmt.Printf("Connection State has changed %s \n", connectionState.String())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -7,7 +7,6 @@ import (
|
|||||||
"github.com/pions/webrtc"
|
"github.com/pions/webrtc"
|
||||||
"github.com/pions/webrtc/examples/util"
|
"github.com/pions/webrtc/examples/util"
|
||||||
gst "github.com/pions/webrtc/examples/util/gstreamer-src"
|
gst "github.com/pions/webrtc/examples/util/gstreamer-src"
|
||||||
"github.com/pions/webrtc/pkg/ice"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -36,7 +35,7 @@ func main() {
|
|||||||
|
|
||||||
// Set the handler for ICE connection state
|
// Set the handler for ICE connection state
|
||||||
// This will notify you when the peer has connected/disconnected
|
// This will notify you when the peer has connected/disconnected
|
||||||
peerConnection.OnICEConnectionStateChange(func(connectionState ice.ConnectionState) {
|
peerConnection.OnICEConnectionStateChange(func(connectionState webrtc.ICEConnectionState) {
|
||||||
fmt.Printf("Connection State has changed %s \n", connectionState.String())
|
fmt.Printf("Connection State has changed %s \n", connectionState.String())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -7,7 +7,6 @@ import (
|
|||||||
janus "github.com/notedit/janus-go"
|
janus "github.com/notedit/janus-go"
|
||||||
"github.com/pions/webrtc"
|
"github.com/pions/webrtc"
|
||||||
"github.com/pions/webrtc/examples/util"
|
"github.com/pions/webrtc/examples/util"
|
||||||
"github.com/pions/webrtc/pkg/ice"
|
|
||||||
"github.com/pions/webrtc/pkg/media/ivfwriter"
|
"github.com/pions/webrtc/pkg/media/ivfwriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -52,7 +51,7 @@ func main() {
|
|||||||
peerConnection, err := webrtc.NewPeerConnection(config)
|
peerConnection, err := webrtc.NewPeerConnection(config)
|
||||||
util.Check(err)
|
util.Check(err)
|
||||||
|
|
||||||
peerConnection.OnICEConnectionStateChange(func(connectionState ice.ConnectionState) {
|
peerConnection.OnICEConnectionStateChange(func(connectionState webrtc.ICEConnectionState) {
|
||||||
fmt.Printf("Connection State has changed %s \n", connectionState.String())
|
fmt.Printf("Connection State has changed %s \n", connectionState.String())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -8,7 +8,6 @@ import (
|
|||||||
"github.com/pions/webrtc"
|
"github.com/pions/webrtc"
|
||||||
"github.com/pions/webrtc/examples/util"
|
"github.com/pions/webrtc/examples/util"
|
||||||
gst "github.com/pions/webrtc/examples/util/gstreamer-src"
|
gst "github.com/pions/webrtc/examples/util/gstreamer-src"
|
||||||
"github.com/pions/webrtc/pkg/ice"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func watchHandle(handle *janus.Handle) {
|
func watchHandle(handle *janus.Handle) {
|
||||||
@@ -52,7 +51,7 @@ func main() {
|
|||||||
peerConnection, err := webrtc.NewPeerConnection(config)
|
peerConnection, err := webrtc.NewPeerConnection(config)
|
||||||
util.Check(err)
|
util.Check(err)
|
||||||
|
|
||||||
peerConnection.OnICEConnectionStateChange(func(connectionState ice.ConnectionState) {
|
peerConnection.OnICEConnectionStateChange(func(connectionState webrtc.ICEConnectionState) {
|
||||||
fmt.Printf("Connection State has changed %s \n", connectionState.String())
|
fmt.Printf("Connection State has changed %s \n", connectionState.String())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -10,7 +10,6 @@ import (
|
|||||||
"github.com/pions/webrtc"
|
"github.com/pions/webrtc"
|
||||||
"github.com/pions/webrtc/examples/util"
|
"github.com/pions/webrtc/examples/util"
|
||||||
"github.com/pions/webrtc/pkg/datachannel"
|
"github.com/pions/webrtc/pkg/datachannel"
|
||||||
"github.com/pions/webrtc/pkg/ice"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -34,7 +33,7 @@ func main() {
|
|||||||
|
|
||||||
// Set the handler for ICE connection state
|
// Set the handler for ICE connection state
|
||||||
// This will notify you when the peer has connected/disconnected
|
// This will notify you when the peer has connected/disconnected
|
||||||
peerConnection.OnICEConnectionStateChange(func(connectionState ice.ConnectionState) {
|
peerConnection.OnICEConnectionStateChange(func(connectionState webrtc.ICEConnectionState) {
|
||||||
fmt.Printf("ICE Connection State has changed: %s\n", connectionState.String())
|
fmt.Printf("ICE Connection State has changed: %s\n", connectionState.String())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -11,7 +11,6 @@ import (
|
|||||||
"github.com/pions/webrtc"
|
"github.com/pions/webrtc"
|
||||||
"github.com/pions/webrtc/examples/util"
|
"github.com/pions/webrtc/examples/util"
|
||||||
"github.com/pions/webrtc/pkg/datachannel"
|
"github.com/pions/webrtc/pkg/datachannel"
|
||||||
"github.com/pions/webrtc/pkg/ice"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -39,7 +38,7 @@ func main() {
|
|||||||
|
|
||||||
// Set the handler for ICE connection state
|
// Set the handler for ICE connection state
|
||||||
// This will notify you when the peer has connected/disconnected
|
// This will notify you when the peer has connected/disconnected
|
||||||
peerConnection.OnICEConnectionStateChange(func(connectionState ice.ConnectionState) {
|
peerConnection.OnICEConnectionStateChange(func(connectionState webrtc.ICEConnectionState) {
|
||||||
fmt.Printf("ICE Connection State has changed: %s\n", connectionState.String())
|
fmt.Printf("ICE Connection State has changed: %s\n", connectionState.String())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -7,7 +7,6 @@ import (
|
|||||||
"github.com/pions/rtcp"
|
"github.com/pions/rtcp"
|
||||||
"github.com/pions/webrtc"
|
"github.com/pions/webrtc"
|
||||||
"github.com/pions/webrtc/examples/util"
|
"github.com/pions/webrtc/examples/util"
|
||||||
"github.com/pions/webrtc/pkg/ice"
|
|
||||||
"github.com/pions/webrtc/pkg/media/ivfwriter"
|
"github.com/pions/webrtc/pkg/media/ivfwriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -61,7 +60,7 @@ func main() {
|
|||||||
|
|
||||||
// Set the handler for ICE connection state
|
// Set the handler for ICE connection state
|
||||||
// This will notify you when the peer has connected/disconnected
|
// This will notify you when the peer has connected/disconnected
|
||||||
peerConnection.OnICEConnectionStateChange(func(connectionState ice.ConnectionState) {
|
peerConnection.OnICEConnectionStateChange(func(connectionState webrtc.ICEConnectionState) {
|
||||||
fmt.Printf("Connection State has changed %s \n", connectionState.String())
|
fmt.Printf("Connection State has changed %s \n", connectionState.String())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
2
go.mod
2
go.mod
@@ -5,8 +5,8 @@ require (
|
|||||||
github.com/pions/dtls v1.2.1
|
github.com/pions/dtls v1.2.1
|
||||||
github.com/pions/rtcp v1.0.0
|
github.com/pions/rtcp v1.0.0
|
||||||
github.com/pions/rtp v1.0.0
|
github.com/pions/rtp v1.0.0
|
||||||
github.com/pions/sdp/v2 v2.0.0
|
|
||||||
github.com/pions/sctp v1.4.0
|
github.com/pions/sctp v1.4.0
|
||||||
|
github.com/pions/sdp/v2 v2.0.0
|
||||||
github.com/pions/srtp v1.0.3
|
github.com/pions/srtp v1.0.3
|
||||||
github.com/pions/stun v0.2.0
|
github.com/pions/stun v0.2.0
|
||||||
github.com/pions/transport v0.2.0
|
github.com/pions/transport v0.2.0
|
||||||
|
4
go.sum
4
go.sum
@@ -29,11 +29,11 @@ github.com/pions/rtcp v1.0.0 h1:kYGe6RegZ63yVDkqXaru1+kHZAqHEufP3zfRAGKPycI=
|
|||||||
github.com/pions/rtcp v1.0.0/go.mod h1:Q5twXlqiz775Yn37X0cl4lAsfSk8EiHgeNkte59jBY4=
|
github.com/pions/rtcp v1.0.0/go.mod h1:Q5twXlqiz775Yn37X0cl4lAsfSk8EiHgeNkte59jBY4=
|
||||||
github.com/pions/rtp v1.0.0 h1:H/TUg7bhgBT/mQsUx0adW3cmgwqPmygoYbbRTc3Y7Ek=
|
github.com/pions/rtp v1.0.0 h1:H/TUg7bhgBT/mQsUx0adW3cmgwqPmygoYbbRTc3Y7Ek=
|
||||||
github.com/pions/rtp v1.0.0/go.mod h1:GDIt4UYlSz7za4vfaLqihGJJ+yLvgPshnqrF/lm3vcM=
|
github.com/pions/rtp v1.0.0/go.mod h1:GDIt4UYlSz7za4vfaLqihGJJ+yLvgPshnqrF/lm3vcM=
|
||||||
github.com/pions/sdp/v2 v2.0.0 h1:tWh8ehKPtXTaFYF12sBAHqYmhV36Q7YTmm3O6ycNa6M=
|
|
||||||
github.com/pions/sdp/v2 v2.0.0/go.mod h1:KGRBcHfpkgJXjrzKJz2wj/Jf1KWnsHdoIiqtayQ5QmE=
|
|
||||||
github.com/pions/sctp v1.3.0/go.mod h1:GZTG/xApE7wdUFEQq2Rmzgxl/+YaB/L1k8xUl1D5bmo=
|
github.com/pions/sctp v1.3.0/go.mod h1:GZTG/xApE7wdUFEQq2Rmzgxl/+YaB/L1k8xUl1D5bmo=
|
||||||
github.com/pions/sctp v1.4.0 h1:U8SAVk+nWa2248SZGHCYsNyOqe/DM5+TKOAlh9Qdw8c=
|
github.com/pions/sctp v1.4.0 h1:U8SAVk+nWa2248SZGHCYsNyOqe/DM5+TKOAlh9Qdw8c=
|
||||||
github.com/pions/sctp v1.4.0/go.mod h1:dAna+Ct/aIIFiGW45yhGzuQjULWD7ni1vjoKHa9DsyU=
|
github.com/pions/sctp v1.4.0/go.mod h1:dAna+Ct/aIIFiGW45yhGzuQjULWD7ni1vjoKHa9DsyU=
|
||||||
|
github.com/pions/sdp/v2 v2.0.0 h1:tWh8ehKPtXTaFYF12sBAHqYmhV36Q7YTmm3O6ycNa6M=
|
||||||
|
github.com/pions/sdp/v2 v2.0.0/go.mod h1:KGRBcHfpkgJXjrzKJz2wj/Jf1KWnsHdoIiqtayQ5QmE=
|
||||||
github.com/pions/srtp v1.0.3 h1:0rlg7yUHQblFA1e451mhx50IkA7+e48ja5K8mljyMYY=
|
github.com/pions/srtp v1.0.3 h1:0rlg7yUHQblFA1e451mhx50IkA7+e48ja5K8mljyMYY=
|
||||||
github.com/pions/srtp v1.0.3/go.mod h1:egXe0STDyQDXLm7hjOMzuk7rkAhJ1SHOx+tTgtw/cQs=
|
github.com/pions/srtp v1.0.3/go.mod h1:egXe0STDyQDXLm7hjOMzuk7rkAhJ1SHOx+tTgtw/cQs=
|
||||||
github.com/pions/stun v0.2.0 h1:spIzpfkEg6HV+2iIo6qeOsAjtadZKzbXbrd2e9ZCCcs=
|
github.com/pions/stun v0.2.0 h1:spIzpfkEg6HV+2iIo6qeOsAjtadZKzbXbrd2e9ZCCcs=
|
||||||
|
@@ -75,8 +75,7 @@ type PeerConnection struct {
|
|||||||
|
|
||||||
// ICEConnectionState attribute returns the ICE connection state of the
|
// ICEConnectionState attribute returns the ICE connection state of the
|
||||||
// PeerConnection instance.
|
// PeerConnection instance.
|
||||||
// ICEConnectionState ICEConnectionState // FIXME SWAP-FOR-THIS
|
iceConnectionState ICEConnectionState
|
||||||
ICEConnectionState ice.ConnectionState // FIXME REMOVE
|
|
||||||
|
|
||||||
// ConnectionState attribute returns the connection state of the
|
// ConnectionState attribute returns the connection state of the
|
||||||
// PeerConnection instance.
|
// PeerConnection instance.
|
||||||
@@ -103,7 +102,7 @@ type PeerConnection struct {
|
|||||||
// OnConnectionStateChange func() // FIXME NOT-USED
|
// OnConnectionStateChange func() // FIXME NOT-USED
|
||||||
|
|
||||||
onSignalingStateChangeHandler func(SignalingState)
|
onSignalingStateChangeHandler func(SignalingState)
|
||||||
onICEConnectionStateChangeHandler func(ice.ConnectionState)
|
onICEConnectionStateChangeHandler func(ICEConnectionState)
|
||||||
onTrackHandler func(*Track)
|
onTrackHandler func(*Track)
|
||||||
onDataChannelHandler func(*DataChannel)
|
onDataChannelHandler func(*DataChannel)
|
||||||
|
|
||||||
@@ -130,13 +129,12 @@ func (api *API) NewPeerConnection(configuration Configuration) (*PeerConnection,
|
|||||||
Certificates: []Certificate{},
|
Certificates: []Certificate{},
|
||||||
ICECandidatePoolSize: 0,
|
ICECandidatePoolSize: 0,
|
||||||
},
|
},
|
||||||
isClosed: false,
|
isClosed: false,
|
||||||
negotiationNeeded: false,
|
negotiationNeeded: false,
|
||||||
lastOffer: "",
|
lastOffer: "",
|
||||||
lastAnswer: "",
|
lastAnswer: "",
|
||||||
SignalingState: SignalingStateStable,
|
SignalingState: SignalingStateStable,
|
||||||
// ICEConnectionState: ICEConnectionStateNew, // FIXME SWAP-FOR-THIS
|
iceConnectionState: ICEConnectionStateNew,
|
||||||
ICEConnectionState: ice.ConnectionStateNew, // FIXME REMOVE
|
|
||||||
ICEGatheringState: ICEGatheringStateNew,
|
ICEGatheringState: ICEGatheringStateNew,
|
||||||
ConnectionState: PeerConnectionStateNew,
|
ConnectionState: PeerConnectionStateNew,
|
||||||
dataChannels: make(map[uint16]*DataChannel),
|
dataChannels: make(map[uint16]*DataChannel),
|
||||||
@@ -300,13 +298,13 @@ func (pc *PeerConnection) onTrack(t *Track) (done chan struct{}) {
|
|||||||
|
|
||||||
// OnICEConnectionStateChange sets an event handler which is called
|
// OnICEConnectionStateChange sets an event handler which is called
|
||||||
// when an ICE connection state is changed.
|
// when an ICE connection state is changed.
|
||||||
func (pc *PeerConnection) OnICEConnectionStateChange(f func(ice.ConnectionState)) {
|
func (pc *PeerConnection) OnICEConnectionStateChange(f func(ICEConnectionState)) {
|
||||||
pc.mu.Lock()
|
pc.mu.Lock()
|
||||||
defer pc.mu.Unlock()
|
defer pc.mu.Unlock()
|
||||||
pc.onICEConnectionStateChangeHandler = f
|
pc.onICEConnectionStateChangeHandler = f
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pc *PeerConnection) onICEConnectionStateChange(cs ice.ConnectionState) (done chan struct{}) {
|
func (pc *PeerConnection) onICEConnectionStateChange(cs ICEConnectionState) (done chan struct{}) {
|
||||||
pc.mu.RLock()
|
pc.mu.RLock()
|
||||||
hdlr := pc.onICEConnectionStateChangeHandler
|
hdlr := pc.onICEConnectionStateChangeHandler
|
||||||
pc.mu.RUnlock()
|
pc.mu.RUnlock()
|
||||||
@@ -481,10 +479,27 @@ func (pc *PeerConnection) createICETransport() *ICETransport {
|
|||||||
t := pc.api.NewICETransport(pc.iceGatherer)
|
t := pc.api.NewICETransport(pc.iceGatherer)
|
||||||
|
|
||||||
t.OnConnectionStateChange(func(state ICETransportState) {
|
t.OnConnectionStateChange(func(state ICETransportState) {
|
||||||
// We convert the state back to the ICE state to not brake the
|
cs := ICEConnectionStateNew
|
||||||
// existing public API at this point.
|
switch state {
|
||||||
iceState := state.toICE()
|
case ICETransportStateNew:
|
||||||
pc.iceStateChange(iceState)
|
cs = ICEConnectionStateNew
|
||||||
|
case ICETransportStateChecking:
|
||||||
|
cs = ICEConnectionStateChecking
|
||||||
|
case ICETransportStateConnected:
|
||||||
|
cs = ICEConnectionStateConnected
|
||||||
|
case ICETransportStateCompleted:
|
||||||
|
cs = ICEConnectionStateCompleted
|
||||||
|
case ICETransportStateFailed:
|
||||||
|
cs = ICEConnectionStateFailed
|
||||||
|
case ICETransportStateDisconnected:
|
||||||
|
cs = ICEConnectionStateDisconnected
|
||||||
|
case ICETransportStateClosed:
|
||||||
|
cs = ICEConnectionStateClosed
|
||||||
|
default:
|
||||||
|
pcLog.Warnf("OnConnectionStateChange: unhandled ICE state: %s", state)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
pc.iceStateChange(cs)
|
||||||
})
|
})
|
||||||
|
|
||||||
return t
|
return t
|
||||||
@@ -1037,6 +1052,15 @@ func (pc *PeerConnection) AddICECandidate(s string) error {
|
|||||||
return pc.iceTransport.AddRemoteCandidate(candidate)
|
return pc.iceTransport.AddRemoteCandidate(candidate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ICEConnectionState returns the ICE connection state of the
|
||||||
|
// PeerConnection instance.
|
||||||
|
func (pc *PeerConnection) ICEConnectionState() ICEConnectionState {
|
||||||
|
pc.mu.RLock()
|
||||||
|
defer pc.mu.RUnlock()
|
||||||
|
|
||||||
|
return pc.iceConnectionState
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// --- FIXME - BELOW CODE NEEDS RE-ORGANIZATION - https://w3c.github.io/webrtc-pc/#rtp-media-api
|
// --- FIXME - BELOW CODE NEEDS RE-ORGANIZATION - https://w3c.github.io/webrtc-pc/#rtp-media-api
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
@@ -1333,9 +1357,9 @@ func flattenErrs(errs []error) error {
|
|||||||
return fmt.Errorf(strings.Join(errstrings, "\n"))
|
return fmt.Errorf(strings.Join(errstrings, "\n"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pc *PeerConnection) iceStateChange(newState ice.ConnectionState) {
|
func (pc *PeerConnection) iceStateChange(newState ICEConnectionState) {
|
||||||
pc.mu.Lock()
|
pc.mu.Lock()
|
||||||
pc.ICEConnectionState = newState
|
pc.iceConnectionState = newState
|
||||||
pc.mu.Unlock()
|
pc.mu.Unlock()
|
||||||
|
|
||||||
pc.onICEConnectionStateChange(newState)
|
pc.onICEConnectionStateChange(newState)
|
||||||
|
@@ -8,7 +8,6 @@ import (
|
|||||||
|
|
||||||
"github.com/pions/rtcp"
|
"github.com/pions/rtcp"
|
||||||
"github.com/pions/transport/test"
|
"github.com/pions/transport/test"
|
||||||
"github.com/pions/webrtc/pkg/ice"
|
|
||||||
"github.com/pions/webrtc/pkg/media"
|
"github.com/pions/webrtc/pkg/media"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -196,8 +195,8 @@ func TestPeerConnection_Media_Shutdown(t *testing.T) {
|
|||||||
onTrackFired = true
|
onTrackFired = true
|
||||||
})
|
})
|
||||||
|
|
||||||
pcAnswer.OnICEConnectionStateChange(func(iceState ice.ConnectionState) {
|
pcAnswer.OnICEConnectionStateChange(func(iceState ICEConnectionState) {
|
||||||
if iceState == ice.ConnectionStateConnected {
|
if iceState == ICEConnectionStateConnected {
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(3 * time.Second) // TODO PeerConnection.Close() doesn't block for all subsystems
|
time.Sleep(3 * time.Second) // TODO PeerConnection.Close() doesn't block for all subsystems
|
||||||
close(iceComplete)
|
close(iceComplete)
|
||||||
|
@@ -497,7 +497,7 @@ func TestPeerConnection_EventHandlers(t *testing.T) {
|
|||||||
onTrackCalled <- true
|
onTrackCalled <- true
|
||||||
})
|
})
|
||||||
|
|
||||||
pc.OnICEConnectionStateChange(func(cs ice.ConnectionState) {
|
pc.OnICEConnectionStateChange(func(cs ICEConnectionState) {
|
||||||
onICEConnectionStateChangeCalled <- true
|
onICEConnectionStateChangeCalled <- true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user