mirror of
https://github.com/pion/webrtc.git
synced 2025-10-04 14:53:05 +08:00
Remove RTC prefix from all names
Let's pull off the bandaid! * Reduces studdering: webrtc.RTCTrack -> webrtc.Track * Makes it easier to find types by editor autocomplete * Makes code read more fluently (less repetition) Since we're breaking the API in 2.0, our only chance to do this is now. Relates to #408
This commit is contained in:
@@ -74,7 +74,7 @@ Check out the **[contributing wiki](https://github.com/pions/webrtc/wiki/Contrib
|
||||
* [Tobias Fridén](https://github.com/tobiasfriden) *SRTP authentication verification*
|
||||
* [Yutaka Takeda](https://github.com/enobufs) *Fix ICE connection timeout*
|
||||
* [Hugo Arregui](https://github.com/hugoArregui) *Fix connection timeout*
|
||||
* [Rob Deutsch](https://github.com/rob-deutsch) *RTCRtpReceiver graceful shutdown*
|
||||
* [Rob Deutsch](https://github.com/rob-deutsch) *RTPReceiver graceful shutdown*
|
||||
* [Jin Lei](https://github.com/jinleileiking) - *SFU example use http*
|
||||
|
||||
### License
|
||||
|
8
api.go
8
api.go
@@ -77,7 +77,7 @@ func SetConnectionTimeout(connectionTimeout, keepAlive time.Duration) {
|
||||
|
||||
// RegisterCodec on the default API.
|
||||
// See MediaEngine for details.
|
||||
func RegisterCodec(codec *RTCRtpCodec) {
|
||||
func RegisterCodec(codec *RTPCodec) {
|
||||
defaultAPI.mediaEngine.RegisterCodec(codec)
|
||||
}
|
||||
|
||||
@@ -89,8 +89,8 @@ func RegisterDefaultCodecs() {
|
||||
|
||||
// PeerConnection API
|
||||
|
||||
// NewRTCPeerConnection using the default API.
|
||||
// NewPeerConnection using the default API.
|
||||
// See API.NewRTCPeerConnection for details.
|
||||
func NewRTCPeerConnection(configuration RTCConfiguration) (*RTCPeerConnection, error) {
|
||||
return defaultAPI.NewRTCPeerConnection(configuration)
|
||||
func NewPeerConnection(configuration Configuration) (*PeerConnection, error) {
|
||||
return defaultAPI.NewPeerConnection(configuration)
|
||||
}
|
||||
|
18
errors.go
18
errors.go
@@ -35,24 +35,24 @@ var (
|
||||
ErrPrivateKeyType = errors.New("private key type not supported")
|
||||
|
||||
// ErrModifyingPeerIdentity indicates that an attempt to modify
|
||||
// PeerIdentity was made after RTCPeerConnection has been initialized.
|
||||
// PeerIdentity was made after PeerConnection has been initialized.
|
||||
ErrModifyingPeerIdentity = errors.New("peerIdentity cannot be modified")
|
||||
|
||||
// ErrModifyingCertificates indicates that an attempt to modify
|
||||
// Certificates was made after RTCPeerConnection has been initialized.
|
||||
// Certificates was made after PeerConnection has been initialized.
|
||||
ErrModifyingCertificates = errors.New("certificates cannot be modified")
|
||||
|
||||
// ErrModifyingBundlePolicy indicates that an attempt to modify
|
||||
// BundlePolicy was made after RTCPeerConnection has been initialized.
|
||||
// BundlePolicy was made after PeerConnection has been initialized.
|
||||
ErrModifyingBundlePolicy = errors.New("bundle policy cannot be modified")
|
||||
|
||||
// ErrModifyingRtcpMuxPolicy indicates that an attempt to modify
|
||||
// RtcpMuxPolicy was made after RTCPeerConnection has been initialized.
|
||||
ErrModifyingRtcpMuxPolicy = errors.New("rtcp mux policy cannot be modified")
|
||||
// ErrModifyingRTCPMuxPolicy indicates that an attempt to modify
|
||||
// RTCPMuxPolicy was made after PeerConnection has been initialized.
|
||||
ErrModifyingRTCPMuxPolicy = errors.New("rtcp mux policy cannot be modified")
|
||||
|
||||
// ErrModifyingIceCandidatePoolSize indicates that an attempt to modify
|
||||
// IceCandidatePoolSize was made after RTCPeerConnection has been initialized.
|
||||
ErrModifyingIceCandidatePoolSize = errors.New("ice candidate pool size cannot be modified")
|
||||
// ErrModifyingICECandidatePoolSize indicates that an attempt to modify
|
||||
// ICECandidatePoolSize was made after PeerConnection has been initialized.
|
||||
ErrModifyingICECandidatePoolSize = errors.New("ice candidate pool size cannot be modified")
|
||||
|
||||
// ErrStringSizeLimit indicates that the character size limit of string is
|
||||
// exceeded. The limit is hardcoded to 65535 according to specifications.
|
||||
|
@@ -18,8 +18,8 @@ func main() {
|
||||
// Everything below is the pion-WebRTC API! Thanks for using it ❤️.
|
||||
|
||||
// Prepare the configuration
|
||||
config := webrtc.RTCConfiguration{
|
||||
IceServers: []webrtc.RTCIceServer{
|
||||
config := webrtc.Configuration{
|
||||
ICEServers: []webrtc.ICEServer{
|
||||
{
|
||||
URLs: []string{"stun:stun.l.google.com:19302"},
|
||||
},
|
||||
@@ -27,7 +27,7 @@ func main() {
|
||||
}
|
||||
|
||||
// Create a new RTCPeerConnection
|
||||
peerConnection, err := webrtc.NewRTCPeerConnection(config)
|
||||
peerConnection, err := webrtc.NewPeerConnection(config)
|
||||
util.Check(err)
|
||||
|
||||
// Set the handler for ICE connection state
|
||||
@@ -37,7 +37,7 @@ func main() {
|
||||
})
|
||||
|
||||
// Register data channel creation handling
|
||||
peerConnection.OnDataChannel(func(d *webrtc.RTCDataChannel) {
|
||||
peerConnection.OnDataChannel(func(d *webrtc.DataChannel) {
|
||||
fmt.Printf("New DataChannel %s %d\n", d.Label, d.ID)
|
||||
|
||||
// Register channel opening handling
|
||||
@@ -83,7 +83,7 @@ func main() {
|
||||
})
|
||||
|
||||
// Wait for the offer to be pasted
|
||||
offer := webrtc.RTCSessionDescription{}
|
||||
offer := webrtc.SessionDescription{}
|
||||
util.Decode(util.MustReadStdin(), &offer)
|
||||
|
||||
// Set the remote SessionDescription
|
||||
|
@@ -14,8 +14,8 @@ func main() {
|
||||
// Everything below is the pion-WebRTC API! Thanks for using it ❤️.
|
||||
|
||||
// Prepare the configuration
|
||||
config := webrtc.RTCConfiguration{
|
||||
IceServers: []webrtc.RTCIceServer{
|
||||
config := webrtc.Configuration{
|
||||
ICEServers: []webrtc.ICEServer{
|
||||
{
|
||||
URLs: []string{"stun:stun.l.google.com:19302"},
|
||||
},
|
||||
@@ -23,7 +23,7 @@ func main() {
|
||||
}
|
||||
|
||||
// Create a new RTCPeerConnection
|
||||
peerConnection, err := webrtc.NewRTCPeerConnection(config)
|
||||
peerConnection, err := webrtc.NewPeerConnection(config)
|
||||
util.Check(err)
|
||||
|
||||
// Create a datachannel with label 'data'
|
||||
@@ -73,7 +73,7 @@ func main() {
|
||||
fmt.Println(util.Encode(offer))
|
||||
|
||||
// Wait for the answer to be pasted
|
||||
answer := webrtc.RTCSessionDescription{}
|
||||
answer := webrtc.SessionDescription{}
|
||||
util.Decode(util.MustReadStdin(), &answer)
|
||||
|
||||
// Apply the answer as the remote description
|
||||
|
@@ -21,8 +21,8 @@ func main() {
|
||||
// Everything below is the pion-WebRTC API! Thanks for using it ❤️.
|
||||
|
||||
// Prepare the configuration
|
||||
config := webrtc.RTCConfiguration{
|
||||
IceServers: []webrtc.RTCIceServer{
|
||||
config := webrtc.Configuration{
|
||||
ICEServers: []webrtc.ICEServer{
|
||||
{
|
||||
URLs: []string{"stun:stun.l.google.com:19302"},
|
||||
},
|
||||
@@ -30,7 +30,7 @@ func main() {
|
||||
}
|
||||
|
||||
// Create a new RTCPeerConnection
|
||||
peerConnection, err := webrtc.NewRTCPeerConnection(config)
|
||||
peerConnection, err := webrtc.NewPeerConnection(config)
|
||||
util.Check(err)
|
||||
|
||||
// Create a datachannel with label 'data'
|
||||
@@ -70,7 +70,7 @@ func main() {
|
||||
fmt.Println(util.Encode(offer))
|
||||
|
||||
// Wait for the answer to be pasted
|
||||
answer := webrtc.RTCSessionDescription{}
|
||||
answer := webrtc.SessionDescription{}
|
||||
util.Decode(util.MustReadStdin(), answer)
|
||||
|
||||
// Apply the answer as the remote description
|
||||
|
@@ -21,8 +21,8 @@ func main() {
|
||||
// Everything below is the pion-WebRTC API! Thanks for using it ❤️.
|
||||
|
||||
// Prepare the configuration
|
||||
config := webrtc.RTCConfiguration{
|
||||
IceServers: []webrtc.RTCIceServer{
|
||||
config := webrtc.Configuration{
|
||||
ICEServers: []webrtc.ICEServer{
|
||||
{
|
||||
URLs: []string{"stun:stun.l.google.com:19302"},
|
||||
},
|
||||
@@ -30,7 +30,7 @@ func main() {
|
||||
}
|
||||
|
||||
// Create a new RTCPeerConnection
|
||||
peerConnection, err := webrtc.NewRTCPeerConnection(config)
|
||||
peerConnection, err := webrtc.NewPeerConnection(config)
|
||||
util.Check(err)
|
||||
|
||||
// Set the handler for ICE connection state
|
||||
@@ -40,7 +40,7 @@ func main() {
|
||||
})
|
||||
|
||||
// Register data channel creation handling
|
||||
peerConnection.OnDataChannel(func(d *webrtc.RTCDataChannel) {
|
||||
peerConnection.OnDataChannel(func(d *webrtc.DataChannel) {
|
||||
fmt.Printf("New DataChannel %s %d\n", d.Label, d.ID)
|
||||
|
||||
// Register channel opening handling
|
||||
@@ -60,7 +60,7 @@ func main() {
|
||||
})
|
||||
|
||||
// Wait for the offer to be pasted
|
||||
offer := webrtc.RTCSessionDescription{}
|
||||
offer := webrtc.SessionDescription{}
|
||||
util.Decode(util.MustReadStdin(), offer)
|
||||
|
||||
// Set the remote SessionDescription
|
||||
|
@@ -14,8 +14,8 @@ func main() {
|
||||
// Everything below is the pion-WebRTC API! Thanks for using it ❤️.
|
||||
|
||||
// Prepare the configuration
|
||||
config := webrtc.RTCConfiguration{
|
||||
IceServers: []webrtc.RTCIceServer{
|
||||
config := webrtc.Configuration{
|
||||
ICEServers: []webrtc.ICEServer{
|
||||
{
|
||||
URLs: []string{"stun:stun.l.google.com:19302"},
|
||||
},
|
||||
@@ -23,7 +23,7 @@ func main() {
|
||||
}
|
||||
|
||||
// Create a new RTCPeerConnection
|
||||
peerConnection, err := webrtc.NewRTCPeerConnection(config)
|
||||
peerConnection, err := webrtc.NewPeerConnection(config)
|
||||
util.Check(err)
|
||||
|
||||
// Set the handler for ICE connection state
|
||||
@@ -33,7 +33,7 @@ func main() {
|
||||
})
|
||||
|
||||
// Register data channel creation handling
|
||||
peerConnection.OnDataChannel(func(d *webrtc.RTCDataChannel) {
|
||||
peerConnection.OnDataChannel(func(d *webrtc.DataChannel) {
|
||||
fmt.Printf("New DataChannel %s %d\n", d.Label, d.ID)
|
||||
|
||||
// Register channel opening handling
|
||||
@@ -63,7 +63,7 @@ func main() {
|
||||
})
|
||||
|
||||
// Wait for the offer to be pasted
|
||||
offer := webrtc.RTCSessionDescription{}
|
||||
offer := webrtc.SessionDescription{}
|
||||
util.Decode(util.MustReadStdin(), &offer)
|
||||
|
||||
// Set the remote SessionDescription
|
||||
|
@@ -22,8 +22,8 @@ func gstreamerReceiveMain() {
|
||||
webrtc.RegisterDefaultCodecs()
|
||||
|
||||
// Prepare the configuration
|
||||
config := webrtc.RTCConfiguration{
|
||||
IceServers: []webrtc.RTCIceServer{
|
||||
config := webrtc.Configuration{
|
||||
ICEServers: []webrtc.ICEServer{
|
||||
{
|
||||
URLs: []string{"stun:stun.l.google.com:19302"},
|
||||
},
|
||||
@@ -31,12 +31,12 @@ func gstreamerReceiveMain() {
|
||||
}
|
||||
|
||||
// Create a new RTCPeerConnection
|
||||
peerConnection, err := webrtc.NewRTCPeerConnection(config)
|
||||
peerConnection, err := webrtc.NewPeerConnection(config)
|
||||
util.Check(err)
|
||||
|
||||
// Set a handler for when a new remote track starts, this handler creates a gstreamer pipeline
|
||||
// for the given codec
|
||||
peerConnection.OnTrack(func(track *webrtc.RTCTrack) {
|
||||
peerConnection.OnTrack(func(track *webrtc.Track) {
|
||||
// Send a PLI on an interval so that the publisher is pushing a keyframe every rtcpPLIInterval
|
||||
// This is a temporary fix until we implement incoming RTCP events, then we would push a PLI only when a viewer requests it
|
||||
go func() {
|
||||
@@ -66,7 +66,7 @@ func gstreamerReceiveMain() {
|
||||
})
|
||||
|
||||
// Wait for the offer to be pasted
|
||||
offer := webrtc.RTCSessionDescription{}
|
||||
offer := webrtc.SessionDescription{}
|
||||
util.Decode(util.MustReadStdin(), &offer)
|
||||
|
||||
// Set the remote SessionDescription
|
||||
|
@@ -17,8 +17,8 @@ func main() {
|
||||
webrtc.RegisterDefaultCodecs()
|
||||
|
||||
// Prepare the configuration
|
||||
config := webrtc.RTCConfiguration{
|
||||
IceServers: []webrtc.RTCIceServer{
|
||||
config := webrtc.Configuration{
|
||||
ICEServers: []webrtc.ICEServer{
|
||||
{
|
||||
URLs: []string{"stun:stun.l.google.com:19302"},
|
||||
},
|
||||
@@ -26,7 +26,7 @@ func main() {
|
||||
}
|
||||
|
||||
// Create a new RTCPeerConnection
|
||||
peerConnection, err := webrtc.NewRTCPeerConnection(config)
|
||||
peerConnection, err := webrtc.NewPeerConnection(config)
|
||||
util.Check(err)
|
||||
|
||||
// Set the handler for ICE connection state
|
||||
@@ -36,13 +36,13 @@ func main() {
|
||||
})
|
||||
|
||||
// Create a audio track
|
||||
opusTrack, err := peerConnection.NewRTCSampleTrack(webrtc.DefaultPayloadTypeOpus, "audio", "pion1")
|
||||
opusTrack, err := peerConnection.NewSampleTrack(webrtc.DefaultPayloadTypeOpus, "audio", "pion1")
|
||||
util.Check(err)
|
||||
_, err = peerConnection.AddTrack(opusTrack)
|
||||
util.Check(err)
|
||||
|
||||
// Create a video track
|
||||
vp8Track, err := peerConnection.NewRTCSampleTrack(webrtc.DefaultPayloadTypeVP8, "video", "pion2")
|
||||
vp8Track, err := peerConnection.NewSampleTrack(webrtc.DefaultPayloadTypeVP8, "video", "pion2")
|
||||
util.Check(err)
|
||||
_, err = peerConnection.AddTrack(vp8Track)
|
||||
util.Check(err)
|
||||
@@ -59,7 +59,7 @@ func main() {
|
||||
fmt.Println(util.Encode(offer))
|
||||
|
||||
// Wait for the answer to be pasted
|
||||
answer := webrtc.RTCSessionDescription{}
|
||||
answer := webrtc.SessionDescription{}
|
||||
util.Decode(util.MustReadStdin(), &answer)
|
||||
|
||||
// Set the remote SessionDescription
|
||||
|
@@ -22,8 +22,8 @@ func main() {
|
||||
webrtc.RegisterDefaultCodecs()
|
||||
|
||||
// Prepare the configuration
|
||||
config := webrtc.RTCConfiguration{
|
||||
IceServers: []webrtc.RTCIceServer{
|
||||
config := webrtc.Configuration{
|
||||
ICEServers: []webrtc.ICEServer{
|
||||
{
|
||||
URLs: []string{"stun:stun.l.google.com:19302"},
|
||||
},
|
||||
@@ -31,7 +31,7 @@ func main() {
|
||||
}
|
||||
|
||||
// Create a new RTCPeerConnection
|
||||
peerConnection, err := webrtc.NewRTCPeerConnection(config)
|
||||
peerConnection, err := webrtc.NewPeerConnection(config)
|
||||
util.Check(err)
|
||||
|
||||
// Set the handler for ICE connection state
|
||||
@@ -41,19 +41,19 @@ func main() {
|
||||
})
|
||||
|
||||
// Create a audio track
|
||||
opusTrack, err := peerConnection.NewRTCSampleTrack(webrtc.DefaultPayloadTypeOpus, "audio", "pion1")
|
||||
opusTrack, err := peerConnection.NewSampleTrack(webrtc.DefaultPayloadTypeOpus, "audio", "pion1")
|
||||
util.Check(err)
|
||||
_, err = peerConnection.AddTrack(opusTrack)
|
||||
util.Check(err)
|
||||
|
||||
// Create a video track
|
||||
vp8Track, err := peerConnection.NewRTCSampleTrack(webrtc.DefaultPayloadTypeVP8, "video", "pion2")
|
||||
vp8Track, err := peerConnection.NewSampleTrack(webrtc.DefaultPayloadTypeVP8, "video", "pion2")
|
||||
util.Check(err)
|
||||
_, err = peerConnection.AddTrack(vp8Track)
|
||||
util.Check(err)
|
||||
|
||||
// Wait for the offer to be pasted
|
||||
offer := webrtc.RTCSessionDescription{}
|
||||
offer := webrtc.SessionDescription{}
|
||||
util.Decode(util.MustReadStdin(), &offer)
|
||||
|
||||
// Set the remote SessionDescription
|
||||
|
@@ -40,8 +40,8 @@ func main() {
|
||||
webrtc.RegisterDefaultCodecs()
|
||||
|
||||
// Prepare the configuration
|
||||
config := webrtc.RTCConfiguration{
|
||||
IceServers: []webrtc.RTCIceServer{
|
||||
config := webrtc.Configuration{
|
||||
ICEServers: []webrtc.ICEServer{
|
||||
{
|
||||
URLs: []string{"stun:stun.l.google.com:19302"},
|
||||
},
|
||||
@@ -49,14 +49,14 @@ func main() {
|
||||
}
|
||||
|
||||
// Create a new RTCPeerConnection
|
||||
peerConnection, err := webrtc.NewRTCPeerConnection(config)
|
||||
peerConnection, err := webrtc.NewPeerConnection(config)
|
||||
util.Check(err)
|
||||
|
||||
peerConnection.OnICEConnectionStateChange(func(connectionState ice.ConnectionState) {
|
||||
fmt.Printf("Connection State has changed %s \n", connectionState.String())
|
||||
})
|
||||
|
||||
peerConnection.OnTrack(func(track *webrtc.RTCTrack) {
|
||||
peerConnection.OnTrack(func(track *webrtc.Track) {
|
||||
if track.Codec.Name == webrtc.Opus {
|
||||
return
|
||||
}
|
||||
@@ -98,8 +98,8 @@ func main() {
|
||||
util.Check(err)
|
||||
|
||||
if msg.Jsep != nil {
|
||||
err = peerConnection.SetRemoteDescription(webrtc.RTCSessionDescription{
|
||||
Type: webrtc.RTCSdpTypeOffer,
|
||||
err = peerConnection.SetRemoteDescription(webrtc.SessionDescription{
|
||||
Type: webrtc.SDPTypeOffer,
|
||||
Sdp: msg.Jsep["sdp"].(string),
|
||||
})
|
||||
util.Check(err)
|
||||
|
@@ -40,8 +40,8 @@ func main() {
|
||||
webrtc.RegisterDefaultCodecs()
|
||||
|
||||
// Prepare the configuration
|
||||
config := webrtc.RTCConfiguration{
|
||||
IceServers: []webrtc.RTCIceServer{
|
||||
config := webrtc.Configuration{
|
||||
ICEServers: []webrtc.ICEServer{
|
||||
{
|
||||
URLs: []string{"stun:stun.l.google.com:19302"},
|
||||
},
|
||||
@@ -49,7 +49,7 @@ func main() {
|
||||
}
|
||||
|
||||
// Create a new RTCPeerConnection
|
||||
peerConnection, err := webrtc.NewRTCPeerConnection(config)
|
||||
peerConnection, err := webrtc.NewPeerConnection(config)
|
||||
util.Check(err)
|
||||
|
||||
peerConnection.OnICEConnectionStateChange(func(connectionState ice.ConnectionState) {
|
||||
@@ -57,13 +57,13 @@ func main() {
|
||||
})
|
||||
|
||||
// Create a audio track
|
||||
opusTrack, err := peerConnection.NewRTCSampleTrack(webrtc.DefaultPayloadTypeOpus, "audio", "pion1")
|
||||
opusTrack, err := peerConnection.NewSampleTrack(webrtc.DefaultPayloadTypeOpus, "audio", "pion1")
|
||||
util.Check(err)
|
||||
_, err = peerConnection.AddTrack(opusTrack)
|
||||
util.Check(err)
|
||||
|
||||
// Create a video track
|
||||
vp8Track, err := peerConnection.NewRTCSampleTrack(webrtc.DefaultPayloadTypeVP8, "video", "pion2")
|
||||
vp8Track, err := peerConnection.NewSampleTrack(webrtc.DefaultPayloadTypeVP8, "video", "pion2")
|
||||
util.Check(err)
|
||||
_, err = peerConnection.AddTrack(vp8Track)
|
||||
util.Check(err)
|
||||
@@ -106,8 +106,8 @@ func main() {
|
||||
util.Check(err)
|
||||
|
||||
if msg.Jsep != nil {
|
||||
err = peerConnection.SetRemoteDescription(webrtc.RTCSessionDescription{
|
||||
Type: webrtc.RTCSdpTypeAnswer,
|
||||
err = peerConnection.SetRemoteDescription(webrtc.SessionDescription{
|
||||
Type: webrtc.SDPTypeAnswer,
|
||||
Sdp: msg.Jsep["sdp"].(string),
|
||||
})
|
||||
util.Check(err)
|
||||
|
@@ -25,21 +25,21 @@ func main() {
|
||||
api := webrtc.NewAPI()
|
||||
|
||||
// Prepare ICE gathering options
|
||||
iceOptions := webrtc.RTCIceGatherOptions{
|
||||
ICEServers: []webrtc.RTCIceServer{
|
||||
iceOptions := webrtc.ICEGatherOptions{
|
||||
ICEServers: []webrtc.ICEServer{
|
||||
{URLs: []string{"stun:stun.l.google.com:19302"}},
|
||||
},
|
||||
}
|
||||
|
||||
// Create the ICE gatherer
|
||||
gatherer, err := api.NewRTCIceGatherer(iceOptions)
|
||||
gatherer, err := api.NewICEGatherer(iceOptions)
|
||||
util.Check(err)
|
||||
|
||||
// Construct the ICE transport
|
||||
ice := api.NewRTCIceTransport(gatherer)
|
||||
ice := api.NewICETransport(gatherer)
|
||||
|
||||
// Construct the Quic transport
|
||||
qt, err := api.NewRTCQuicTransport(ice, nil)
|
||||
qt, err := api.NewQUICTransport(ice, nil)
|
||||
util.Check(err)
|
||||
|
||||
// Handle incoming streams
|
||||
@@ -76,9 +76,9 @@ func main() {
|
||||
remoteSignal := Signal{}
|
||||
util.Decode(util.MustReadStdin(), &remoteSignal)
|
||||
|
||||
iceRole := webrtc.RTCIceRoleControlled
|
||||
iceRole := webrtc.ICERoleControlled
|
||||
if *isOffer {
|
||||
iceRole = webrtc.RTCIceRoleControlling
|
||||
iceRole = webrtc.ICERoleControlling
|
||||
}
|
||||
|
||||
err = ice.SetRemoteCandidates(remoteSignal.ICECandidates)
|
||||
@@ -112,9 +112,9 @@ func main() {
|
||||
// This is not part of the ORTC spec. You are free
|
||||
// to exchange this information any way you want.
|
||||
type Signal struct {
|
||||
ICECandidates []webrtc.RTCIceCandidate `json:"iceCandidates"`
|
||||
ICEParameters webrtc.RTCIceParameters `json:"iceParameters"`
|
||||
QuicParameters webrtc.RTCQuicParameters `json:"quicParameters"`
|
||||
ICECandidates []webrtc.ICECandidate `json:"iceCandidates"`
|
||||
ICEParameters webrtc.ICEParameters `json:"iceParameters"`
|
||||
QuicParameters webrtc.QUICParameters `json:"quicParameters"`
|
||||
}
|
||||
|
||||
// ReadLoop reads from the stream
|
||||
|
@@ -17,8 +17,8 @@ func main() {
|
||||
// Everything below is the pion-WebRTC (ORTC) API! Thanks for using it ❤️.
|
||||
|
||||
// Prepare ICE gathering options
|
||||
iceOptions := webrtc.RTCIceGatherOptions{
|
||||
ICEServers: []webrtc.RTCIceServer{
|
||||
iceOptions := webrtc.ICEGatherOptions{
|
||||
ICEServers: []webrtc.ICEServer{
|
||||
{URLs: []string{"stun:stun.l.google.com:19302"}},
|
||||
},
|
||||
}
|
||||
@@ -27,21 +27,21 @@ func main() {
|
||||
api := webrtc.NewAPI()
|
||||
|
||||
// Create the ICE gatherer
|
||||
gatherer, err := api.NewRTCIceGatherer(iceOptions)
|
||||
gatherer, err := api.NewICEGatherer(iceOptions)
|
||||
util.Check(err)
|
||||
|
||||
// Construct the ICE transport
|
||||
ice := api.NewRTCIceTransport(gatherer)
|
||||
ice := api.NewICETransport(gatherer)
|
||||
|
||||
// Construct the DTLS transport
|
||||
dtls, err := api.NewRTCDtlsTransport(ice, nil)
|
||||
dtls, err := api.NewDTLSTransport(ice, nil)
|
||||
util.Check(err)
|
||||
|
||||
// Construct the SCTP transport
|
||||
sctp := api.NewRTCSctpTransport(dtls)
|
||||
sctp := api.NewSCTPTransport(dtls)
|
||||
|
||||
// Handle incoming data channels
|
||||
sctp.OnDataChannel(func(channel *webrtc.RTCDataChannel) {
|
||||
sctp.OnDataChannel(func(channel *webrtc.DataChannel) {
|
||||
fmt.Printf("New DataChannel %s %d\n", channel.Label, channel.ID)
|
||||
|
||||
// Register the handlers
|
||||
@@ -66,7 +66,7 @@ func main() {
|
||||
signal := Signal{
|
||||
ICECandidates: iceCandidates,
|
||||
ICEParameters: iceParams,
|
||||
DtlsParameters: dtlsParams,
|
||||
DTLSParameters: dtlsParams,
|
||||
SCTPCapabilities: sctpCapabilities,
|
||||
}
|
||||
|
||||
@@ -75,9 +75,9 @@ func main() {
|
||||
remoteSignal := Signal{}
|
||||
util.Decode(util.MustReadStdin(), &remoteSignal)
|
||||
|
||||
iceRole := webrtc.RTCIceRoleControlled
|
||||
iceRole := webrtc.ICERoleControlled
|
||||
if *isOffer {
|
||||
iceRole = webrtc.RTCIceRoleControlling
|
||||
iceRole = webrtc.ICERoleControlling
|
||||
}
|
||||
|
||||
err = ice.SetRemoteCandidates(remoteSignal.ICECandidates)
|
||||
@@ -88,7 +88,7 @@ func main() {
|
||||
util.Check(err)
|
||||
|
||||
// Start the DTLS transport
|
||||
err = dtls.Start(remoteSignal.DtlsParameters)
|
||||
err = dtls.Start(remoteSignal.DTLSParameters)
|
||||
util.Check(err)
|
||||
|
||||
// Start the SCTP transport
|
||||
@@ -97,12 +97,12 @@ func main() {
|
||||
|
||||
// Construct the data channel as the offerer
|
||||
if *isOffer {
|
||||
dcParams := &webrtc.RTCDataChannelParameters{
|
||||
dcParams := &webrtc.DataChannelParameters{
|
||||
Label: "Foo",
|
||||
ID: 1,
|
||||
}
|
||||
var channel *webrtc.RTCDataChannel
|
||||
channel, err = api.NewRTCDataChannel(sctp, dcParams)
|
||||
var channel *webrtc.DataChannel
|
||||
channel, err = api.NewDataChannel(sctp, dcParams)
|
||||
util.Check(err)
|
||||
|
||||
// Register the handlers
|
||||
@@ -118,13 +118,13 @@ func main() {
|
||||
// This is not part of the ORTC spec. You are free
|
||||
// to exchange this information any way you want.
|
||||
type Signal struct {
|
||||
ICECandidates []webrtc.RTCIceCandidate `json:"iceCandidates"`
|
||||
ICEParameters webrtc.RTCIceParameters `json:"iceParameters"`
|
||||
DtlsParameters webrtc.RTCDtlsParameters `json:"dtlsParameters"`
|
||||
SCTPCapabilities webrtc.RTCSctpCapabilities `json:"sctpCapabilities"`
|
||||
ICECandidates []webrtc.ICECandidate `json:"iceCandidates"`
|
||||
ICEParameters webrtc.ICEParameters `json:"iceParameters"`
|
||||
DTLSParameters webrtc.DTLSParameters `json:"dtlsParameters"`
|
||||
SCTPCapabilities webrtc.SCTPCapabilities `json:"sctpCapabilities"`
|
||||
}
|
||||
|
||||
func handleOnOpen(channel *webrtc.RTCDataChannel) func() {
|
||||
func handleOnOpen(channel *webrtc.DataChannel) func() {
|
||||
return func() {
|
||||
fmt.Printf("Data channel '%s'-'%d' open. Random messages will now be sent to any connected DataChannels every 5 seconds\n", channel.Label, channel.ID)
|
||||
|
||||
@@ -138,7 +138,7 @@ func handleOnOpen(channel *webrtc.RTCDataChannel) func() {
|
||||
}
|
||||
}
|
||||
|
||||
func handleMessage(channel *webrtc.RTCDataChannel) func(datachannel.Payload) {
|
||||
func handleMessage(channel *webrtc.DataChannel) func(datachannel.Payload) {
|
||||
return func(payload datachannel.Payload) {
|
||||
switch p := payload.(type) {
|
||||
case *datachannel.PayloadString:
|
||||
|
@@ -20,8 +20,8 @@ func main() {
|
||||
// Everything below is the pion-WebRTC API! Thanks for using it ❤️.
|
||||
|
||||
// Prepare the configuration
|
||||
config := webrtc.RTCConfiguration{
|
||||
IceServers: []webrtc.RTCIceServer{
|
||||
config := webrtc.Configuration{
|
||||
ICEServers: []webrtc.ICEServer{
|
||||
{
|
||||
URLs: []string{"stun:stun.l.google.com:19302"},
|
||||
},
|
||||
@@ -29,7 +29,7 @@ func main() {
|
||||
}
|
||||
|
||||
// Create a new RTCPeerConnection
|
||||
peerConnection, err := webrtc.NewRTCPeerConnection(config)
|
||||
peerConnection, err := webrtc.NewPeerConnection(config)
|
||||
util.Check(err)
|
||||
|
||||
// Set the handler for ICE connection state
|
||||
@@ -39,7 +39,7 @@ func main() {
|
||||
})
|
||||
|
||||
// Register data channel creation handling
|
||||
peerConnection.OnDataChannel(func(d *webrtc.RTCDataChannel) {
|
||||
peerConnection.OnDataChannel(func(d *webrtc.DataChannel) {
|
||||
fmt.Printf("New DataChannel %s %d\n", d.Label, d.ID)
|
||||
|
||||
// Register channel opening handling
|
||||
@@ -93,12 +93,12 @@ func main() {
|
||||
}
|
||||
|
||||
// mustSignalViaHTTP exchange the SDP offer and answer using an HTTP server.
|
||||
func mustSignalViaHTTP(address string) (offerOut chan webrtc.RTCSessionDescription, answerIn chan webrtc.RTCSessionDescription) {
|
||||
offerOut = make(chan webrtc.RTCSessionDescription)
|
||||
answerIn = make(chan webrtc.RTCSessionDescription)
|
||||
func mustSignalViaHTTP(address string) (offerOut chan webrtc.SessionDescription, answerIn chan webrtc.SessionDescription) {
|
||||
offerOut = make(chan webrtc.SessionDescription)
|
||||
answerIn = make(chan webrtc.SessionDescription)
|
||||
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
var offer webrtc.RTCSessionDescription
|
||||
var offer webrtc.SessionDescription
|
||||
err := json.NewDecoder(r.Body).Decode(&offer)
|
||||
util.Check(err)
|
||||
|
||||
|
@@ -21,8 +21,8 @@ func main() {
|
||||
// Everything below is the pion-WebRTC API! Thanks for using it ❤️.
|
||||
|
||||
// Prepare the configuration
|
||||
config := webrtc.RTCConfiguration{
|
||||
IceServers: []webrtc.RTCIceServer{
|
||||
config := webrtc.Configuration{
|
||||
ICEServers: []webrtc.ICEServer{
|
||||
{
|
||||
URLs: []string{"stun:stun.l.google.com:19302"},
|
||||
},
|
||||
@@ -30,7 +30,7 @@ func main() {
|
||||
}
|
||||
|
||||
// Create a new RTCPeerConnection
|
||||
peerConnection, err := webrtc.NewRTCPeerConnection(config)
|
||||
peerConnection, err := webrtc.NewPeerConnection(config)
|
||||
util.Check(err)
|
||||
|
||||
// Create a datachannel with label 'data'
|
||||
@@ -88,7 +88,7 @@ func main() {
|
||||
}
|
||||
|
||||
// mustSignalViaHTTP exchange the SDP offer and answer using an HTTP Post request.
|
||||
func mustSignalViaHTTP(offer webrtc.RTCSessionDescription, address string) webrtc.RTCSessionDescription {
|
||||
func mustSignalViaHTTP(offer webrtc.SessionDescription, address string) webrtc.SessionDescription {
|
||||
b := new(bytes.Buffer)
|
||||
err := json.NewEncoder(b).Encode(offer)
|
||||
util.Check(err)
|
||||
@@ -97,7 +97,7 @@ func mustSignalViaHTTP(offer webrtc.RTCSessionDescription, address string) webrt
|
||||
util.Check(err)
|
||||
defer resp.Body.Close()
|
||||
|
||||
var answer webrtc.RTCSessionDescription
|
||||
var answer webrtc.SessionDescription
|
||||
err = json.NewDecoder(resp.Body).Decode(&answer)
|
||||
util.Check(err)
|
||||
|
||||
|
@@ -16,12 +16,12 @@ func main() {
|
||||
|
||||
// Setup the codecs you want to use.
|
||||
// We'll use a VP8 codec but you can also define your own
|
||||
webrtc.RegisterCodec(webrtc.NewRTCRtpOpusCodec(webrtc.DefaultPayloadTypeOpus, 48000, 2))
|
||||
webrtc.RegisterCodec(webrtc.NewRTCRtpVP8Codec(webrtc.DefaultPayloadTypeVP8, 90000))
|
||||
webrtc.RegisterCodec(webrtc.NewRTPOpusCodec(webrtc.DefaultPayloadTypeOpus, 48000, 2))
|
||||
webrtc.RegisterCodec(webrtc.NewRTPVP8Codec(webrtc.DefaultPayloadTypeVP8, 90000))
|
||||
|
||||
// Prepare the configuration
|
||||
config := webrtc.RTCConfiguration{
|
||||
IceServers: []webrtc.RTCIceServer{
|
||||
config := webrtc.Configuration{
|
||||
ICEServers: []webrtc.ICEServer{
|
||||
{
|
||||
URLs: []string{"stun:stun.l.google.com:19302"},
|
||||
},
|
||||
@@ -29,13 +29,13 @@ func main() {
|
||||
}
|
||||
|
||||
// Create a new RTCPeerConnection
|
||||
peerConnection, err := webrtc.NewRTCPeerConnection(config)
|
||||
peerConnection, err := webrtc.NewPeerConnection(config)
|
||||
util.Check(err)
|
||||
|
||||
// Set a handler for when a new remote track starts, this handler saves buffers to disk as
|
||||
// an ivf file, since we could have multiple video tracks we provide a counter.
|
||||
// In your application this is where you would handle/process video
|
||||
peerConnection.OnTrack(func(track *webrtc.RTCTrack) {
|
||||
peerConnection.OnTrack(func(track *webrtc.Track) {
|
||||
// Send a PLI on an interval so that the publisher is pushing a keyframe every rtcpPLIInterval
|
||||
// This is a temporary fix until we implement incoming RTCP events, then we would push a PLI only when a viewer requests it
|
||||
go func() {
|
||||
@@ -66,7 +66,7 @@ func main() {
|
||||
})
|
||||
|
||||
// Wait for the offer to be pasted
|
||||
offer := webrtc.RTCSessionDescription{}
|
||||
offer := webrtc.SessionDescription{}
|
||||
util.Decode(util.MustReadStdin(), &offer)
|
||||
|
||||
// Set the remote SessionDescription
|
||||
|
@@ -16,8 +16,8 @@ import (
|
||||
"github.com/pions/webrtc/examples/util"
|
||||
)
|
||||
|
||||
var peerConnectionConfig = webrtc.RTCConfiguration{
|
||||
IceServers: []webrtc.RTCIceServer{
|
||||
var peerConnectionConfig = webrtc.Configuration{
|
||||
ICEServers: []webrtc.ICEServer{
|
||||
{
|
||||
URLs: []string{"stun:stun.l.google.com:19302"},
|
||||
},
|
||||
@@ -57,17 +57,17 @@ func main() {
|
||||
util.Check(err)
|
||||
}()
|
||||
|
||||
offer := webrtc.RTCSessionDescription{}
|
||||
offer := webrtc.SessionDescription{}
|
||||
util.Decode(mustReadHTTP(sdp), &offer)
|
||||
fmt.Println("")
|
||||
|
||||
/* Everything below is the pion-WebRTC API, thanks for using it! */
|
||||
|
||||
// Only support VP8, this makes our proxying code simpler
|
||||
webrtc.RegisterCodec(webrtc.NewRTCRtpVP8Codec(webrtc.DefaultPayloadTypeVP8, 90000))
|
||||
webrtc.RegisterCodec(webrtc.NewRTPVP8Codec(webrtc.DefaultPayloadTypeVP8, 90000))
|
||||
|
||||
// Create a new RTCPeerConnection
|
||||
peerConnection, err := webrtc.NewRTCPeerConnection(peerConnectionConfig)
|
||||
peerConnection, err := webrtc.NewPeerConnection(peerConnectionConfig)
|
||||
util.Check(err)
|
||||
|
||||
inboundSSRC := make(chan uint32)
|
||||
@@ -77,7 +77,7 @@ func main() {
|
||||
var outboundRTPLock sync.RWMutex
|
||||
// Set a handler for when a new remote track starts, this just distributes all our packets
|
||||
// to connected peers
|
||||
peerConnection.OnTrack(func(track *webrtc.RTCTrack) {
|
||||
peerConnection.OnTrack(func(track *webrtc.Track) {
|
||||
// Send a PLI on an interval so that the publisher is pushing a keyframe every rtcpPLIInterval
|
||||
// This can be less wasteful by processing incoming RTCP events, then we would emit a NACK/PLI when a viewer requests it
|
||||
go func() {
|
||||
@@ -128,11 +128,11 @@ func main() {
|
||||
fmt.Println("")
|
||||
fmt.Println("Curl an base64 SDP to start sendonly peer connection")
|
||||
|
||||
recvOnlyOffer := webrtc.RTCSessionDescription{}
|
||||
recvOnlyOffer := webrtc.SessionDescription{}
|
||||
util.Decode(mustReadHTTP(sdp), &recvOnlyOffer)
|
||||
|
||||
// Create a new RTCPeerConnection
|
||||
peerConnection, err := webrtc.NewRTCPeerConnection(peerConnectionConfig)
|
||||
// Create a new PeerConnection
|
||||
peerConnection, err := webrtc.NewPeerConnection(peerConnectionConfig)
|
||||
util.Check(err)
|
||||
|
||||
// Create a single VP8 Track to send videa
|
||||
|
@@ -23,7 +23,7 @@ func init() {
|
||||
// Pipeline is a wrapper for a GStreamer Pipeline
|
||||
type Pipeline struct {
|
||||
Pipeline *C.GstElement
|
||||
in chan<- media.RTCSample
|
||||
in chan<- media.Sample
|
||||
// stop acts as a signal that this pipeline is stopped
|
||||
// any pending sends to Pipeline.in should be cancelled
|
||||
stop chan interface{}
|
||||
@@ -35,7 +35,7 @@ var pipelines = make(map[int]*Pipeline)
|
||||
var pipelinesLock sync.Mutex
|
||||
|
||||
// CreatePipeline creates a GStreamer Pipeline
|
||||
func CreatePipeline(codecName string, in chan<- media.RTCSample, pipelineSrc string) *Pipeline {
|
||||
func CreatePipeline(codecName string, in chan<- media.Sample, pipelineSrc string) *Pipeline {
|
||||
pipelineStr := "appsink name=appsink"
|
||||
switch codecName {
|
||||
case webrtc.VP8:
|
||||
@@ -106,7 +106,7 @@ func goHandlePipelineBuffer(buffer unsafe.Pointer, bufferLen C.int, duration C.i
|
||||
// We need to be able to cancel this function even f pipeline.in isn't being serviced
|
||||
// When pipeline.stop is closed the sending of data will be cancelled.
|
||||
select {
|
||||
case pipeline.in <- media.RTCSample{Data: C.GoBytes(buffer, bufferLen), Samples: samples}:
|
||||
case pipeline.in <- media.Sample{Data: C.GoBytes(buffer, bufferLen), Samples: samples}:
|
||||
case <-pipeline.stop:
|
||||
}
|
||||
} else {
|
||||
|
108
mediaengine.go
108
mediaengine.go
@@ -17,13 +17,13 @@ const (
|
||||
DefaultPayloadTypeH264 = 100
|
||||
)
|
||||
|
||||
// MediaEngine defines the codecs supported by a RTCPeerConnection
|
||||
// MediaEngine defines the codecs supported by a PeerConnection
|
||||
type MediaEngine struct {
|
||||
codecs []*RTCRtpCodec
|
||||
codecs []*RTPCodec
|
||||
}
|
||||
|
||||
// RegisterCodec registers a codec to a media engine
|
||||
func (m *MediaEngine) RegisterCodec(codec *RTCRtpCodec) uint8 {
|
||||
func (m *MediaEngine) RegisterCodec(codec *RTPCodec) uint8 {
|
||||
// TODO: generate PayloadType if not set
|
||||
m.codecs = append(m.codecs, codec)
|
||||
return codec.PayloadType
|
||||
@@ -31,14 +31,14 @@ func (m *MediaEngine) RegisterCodec(codec *RTCRtpCodec) uint8 {
|
||||
|
||||
// RegisterDefaultCodecs is a helper that registers the default codecs supported by pions-webrtc
|
||||
func (m *MediaEngine) RegisterDefaultCodecs() {
|
||||
m.RegisterCodec(NewRTCRtpOpusCodec(DefaultPayloadTypeOpus, 48000, 2))
|
||||
m.RegisterCodec(NewRTCRtpG722Codec(DefaultPayloadTypeG722, 8000))
|
||||
m.RegisterCodec(NewRTCRtpVP8Codec(DefaultPayloadTypeVP8, 90000))
|
||||
m.RegisterCodec(NewRTCRtpH264Codec(DefaultPayloadTypeH264, 90000))
|
||||
m.RegisterCodec(NewRTCRtpVP9Codec(DefaultPayloadTypeVP9, 90000))
|
||||
m.RegisterCodec(NewRTPOpusCodec(DefaultPayloadTypeOpus, 48000, 2))
|
||||
m.RegisterCodec(NewRTPG722Codec(DefaultPayloadTypeG722, 8000))
|
||||
m.RegisterCodec(NewRTPVP8Codec(DefaultPayloadTypeVP8, 90000))
|
||||
m.RegisterCodec(NewRTPH264Codec(DefaultPayloadTypeH264, 90000))
|
||||
m.RegisterCodec(NewRTPVP9Codec(DefaultPayloadTypeVP9, 90000))
|
||||
}
|
||||
|
||||
func (m *MediaEngine) getCodec(payloadType uint8) (*RTCRtpCodec, error) {
|
||||
func (m *MediaEngine) getCodec(payloadType uint8) (*RTPCodec, error) {
|
||||
for _, codec := range m.codecs {
|
||||
if codec.PayloadType == payloadType {
|
||||
return codec, nil
|
||||
@@ -47,7 +47,7 @@ func (m *MediaEngine) getCodec(payloadType uint8) (*RTCRtpCodec, error) {
|
||||
return nil, ErrCodecNotFound
|
||||
}
|
||||
|
||||
func (m *MediaEngine) getCodecSDP(sdpCodec sdp.Codec) (*RTCRtpCodec, error) {
|
||||
func (m *MediaEngine) getCodecSDP(sdpCodec sdp.Codec) (*RTPCodec, error) {
|
||||
for _, codec := range m.codecs {
|
||||
if codec.Name == sdpCodec.Name &&
|
||||
codec.ClockRate == sdpCodec.ClockRate &&
|
||||
@@ -60,8 +60,8 @@ func (m *MediaEngine) getCodecSDP(sdpCodec sdp.Codec) (*RTCRtpCodec, error) {
|
||||
return nil, ErrCodecNotFound
|
||||
}
|
||||
|
||||
func (m *MediaEngine) getCodecsByKind(kind RTCRtpCodecType) []*RTCRtpCodec {
|
||||
var codecs []*RTCRtpCodec
|
||||
func (m *MediaEngine) getCodecsByKind(kind RTPCodecType) []*RTPCodec {
|
||||
var codecs []*RTPCodec
|
||||
for _, codec := range m.codecs {
|
||||
if codec.Type == kind {
|
||||
codecs = append(codecs, codec)
|
||||
@@ -79,9 +79,9 @@ const (
|
||||
H264 = "H264"
|
||||
)
|
||||
|
||||
// NewRTCRtpG722Codec is a helper to create a G722 codec
|
||||
func NewRTCRtpG722Codec(payloadType uint8, clockrate uint32) *RTCRtpCodec {
|
||||
c := NewRTCRtpCodec(RTCRtpCodecTypeAudio,
|
||||
// NewRTPG722Codec is a helper to create a G722 codec
|
||||
func NewRTPG722Codec(payloadType uint8, clockrate uint32) *RTPCodec {
|
||||
c := NewRTPCodec(RTPCodecTypeAudio,
|
||||
G722,
|
||||
clockrate,
|
||||
0,
|
||||
@@ -91,9 +91,9 @@ func NewRTCRtpG722Codec(payloadType uint8, clockrate uint32) *RTCRtpCodec {
|
||||
return c
|
||||
}
|
||||
|
||||
// NewRTCRtpOpusCodec is a helper to create an Opus codec
|
||||
func NewRTCRtpOpusCodec(payloadType uint8, clockrate uint32, channels uint16) *RTCRtpCodec {
|
||||
c := NewRTCRtpCodec(RTCRtpCodecTypeAudio,
|
||||
// NewRTPOpusCodec is a helper to create an Opus codec
|
||||
func NewRTPOpusCodec(payloadType uint8, clockrate uint32, channels uint16) *RTPCodec {
|
||||
c := NewRTPCodec(RTPCodecTypeAudio,
|
||||
Opus,
|
||||
clockrate,
|
||||
channels,
|
||||
@@ -103,9 +103,9 @@ func NewRTCRtpOpusCodec(payloadType uint8, clockrate uint32, channels uint16) *R
|
||||
return c
|
||||
}
|
||||
|
||||
// NewRTCRtpVP8Codec is a helper to create an VP8 codec
|
||||
func NewRTCRtpVP8Codec(payloadType uint8, clockrate uint32) *RTCRtpCodec {
|
||||
c := NewRTCRtpCodec(RTCRtpCodecTypeVideo,
|
||||
// NewRTPVP8Codec is a helper to create an VP8 codec
|
||||
func NewRTPVP8Codec(payloadType uint8, clockrate uint32) *RTPCodec {
|
||||
c := NewRTPCodec(RTPCodecTypeVideo,
|
||||
VP8,
|
||||
clockrate,
|
||||
0,
|
||||
@@ -115,9 +115,9 @@ func NewRTCRtpVP8Codec(payloadType uint8, clockrate uint32) *RTCRtpCodec {
|
||||
return c
|
||||
}
|
||||
|
||||
// NewRTCRtpVP9Codec is a helper to create an VP9 codec
|
||||
func NewRTCRtpVP9Codec(payloadType uint8, clockrate uint32) *RTCRtpCodec {
|
||||
c := NewRTCRtpCodec(RTCRtpCodecTypeVideo,
|
||||
// NewRTPVP9Codec is a helper to create an VP9 codec
|
||||
func NewRTPVP9Codec(payloadType uint8, clockrate uint32) *RTPCodec {
|
||||
c := NewRTPCodec(RTPCodecTypeVideo,
|
||||
VP9,
|
||||
clockrate,
|
||||
0,
|
||||
@@ -127,9 +127,9 @@ func NewRTCRtpVP9Codec(payloadType uint8, clockrate uint32) *RTCRtpCodec {
|
||||
return c
|
||||
}
|
||||
|
||||
// NewRTCRtpH264Codec is a helper to create an H264 codec
|
||||
func NewRTCRtpH264Codec(payloadType uint8, clockrate uint32) *RTCRtpCodec {
|
||||
c := NewRTCRtpCodec(RTCRtpCodecTypeVideo,
|
||||
// NewRTPH264Codec is a helper to create an H264 codec
|
||||
func NewRTPH264Codec(payloadType uint8, clockrate uint32) *RTPCodec {
|
||||
c := NewRTPCodec(RTPCodecTypeVideo,
|
||||
H264,
|
||||
clockrate,
|
||||
0,
|
||||
@@ -139,50 +139,50 @@ func NewRTCRtpH264Codec(payloadType uint8, clockrate uint32) *RTCRtpCodec {
|
||||
return c
|
||||
}
|
||||
|
||||
// RTCRtpCodecType determines the type of a codec
|
||||
type RTCRtpCodecType int
|
||||
// RTPCodecType determines the type of a codec
|
||||
type RTPCodecType int
|
||||
|
||||
const (
|
||||
|
||||
// RTCRtpCodecTypeAudio indicates this is an audio codec
|
||||
RTCRtpCodecTypeAudio RTCRtpCodecType = iota + 1
|
||||
// RTPCodecTypeAudio indicates this is an audio codec
|
||||
RTPCodecTypeAudio RTPCodecType = iota + 1
|
||||
|
||||
// RTCRtpCodecTypeVideo indicates this is a video codec
|
||||
RTCRtpCodecTypeVideo
|
||||
// RTPCodecTypeVideo indicates this is a video codec
|
||||
RTPCodecTypeVideo
|
||||
)
|
||||
|
||||
func (t RTCRtpCodecType) String() string {
|
||||
func (t RTPCodecType) String() string {
|
||||
switch t {
|
||||
case RTCRtpCodecTypeAudio:
|
||||
case RTPCodecTypeAudio:
|
||||
return "audio"
|
||||
case RTCRtpCodecTypeVideo:
|
||||
case RTPCodecTypeVideo:
|
||||
return "video"
|
||||
default:
|
||||
return ErrUnknownType.Error()
|
||||
}
|
||||
}
|
||||
|
||||
// RTCRtpCodec represents a codec supported by the PeerConnection
|
||||
type RTCRtpCodec struct {
|
||||
RTCRtpCodecCapability
|
||||
Type RTCRtpCodecType
|
||||
// RTPCodec represents a codec supported by the PeerConnection
|
||||
type RTPCodec struct {
|
||||
RTPCodecCapability
|
||||
Type RTPCodecType
|
||||
Name string
|
||||
PayloadType uint8
|
||||
Payloader rtp.Payloader
|
||||
}
|
||||
|
||||
// NewRTCRtpCodec is used to define a new codec
|
||||
func NewRTCRtpCodec(
|
||||
codecType RTCRtpCodecType,
|
||||
// NewRTPCodec is used to define a new codec
|
||||
func NewRTPCodec(
|
||||
codecType RTPCodecType,
|
||||
name string,
|
||||
clockrate uint32,
|
||||
channels uint16,
|
||||
fmtp string,
|
||||
payloadType uint8,
|
||||
payloader rtp.Payloader,
|
||||
) *RTCRtpCodec {
|
||||
return &RTCRtpCodec{
|
||||
RTCRtpCodecCapability: RTCRtpCodecCapability{
|
||||
) *RTPCodec {
|
||||
return &RTPCodec{
|
||||
RTPCodecCapability: RTPCodecCapability{
|
||||
MimeType: codecType.String() + "/" + name,
|
||||
ClockRate: clockrate,
|
||||
Channels: channels,
|
||||
@@ -195,21 +195,21 @@ func NewRTCRtpCodec(
|
||||
}
|
||||
}
|
||||
|
||||
// RTCRtpCodecCapability provides information about codec capabilities.
|
||||
type RTCRtpCodecCapability struct {
|
||||
// RTPCodecCapability provides information about codec capabilities.
|
||||
type RTPCodecCapability struct {
|
||||
MimeType string
|
||||
ClockRate uint32
|
||||
Channels uint16
|
||||
SdpFmtpLine string
|
||||
}
|
||||
|
||||
// RTCRtpHeaderExtensionCapability is used to define a RFC5285 RTP header extension supported by the codec.
|
||||
type RTCRtpHeaderExtensionCapability struct {
|
||||
// RTPHeaderExtensionCapability is used to define a RFC5285 RTP header extension supported by the codec.
|
||||
type RTPHeaderExtensionCapability struct {
|
||||
URI string
|
||||
}
|
||||
|
||||
// RTCRtpCapabilities represents the capabilities of a transceiver
|
||||
type RTCRtpCapabilities struct {
|
||||
Codecs []RTCRtpCodecCapability
|
||||
HeaderExtensions []RTCRtpHeaderExtensionCapability
|
||||
// RTPCapabilities represents the capabilities of a transceiver
|
||||
type RTPCapabilities struct {
|
||||
Codecs []RTPCodecCapability
|
||||
HeaderExtensions []RTPHeaderExtensionCapability
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package media
|
||||
|
||||
// RTCSample contains media, and the amount of samples in it
|
||||
type RTCSample struct {
|
||||
// Sample contains media, and the amount of samples in it
|
||||
type Sample struct {
|
||||
Data []byte
|
||||
Samples uint32
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
// SampleBuilder contains all packets
|
||||
// maxLate determines how long we should wait until we get a valid RTCSample
|
||||
// maxLate determines how long we should wait until we get a valid Sample
|
||||
// The larger the value the less packet loss you will see, but higher latency
|
||||
type SampleBuilder struct {
|
||||
maxLate uint16
|
||||
@@ -41,7 +41,7 @@ func (s *SampleBuilder) Push(p *rtp.Packet) {
|
||||
|
||||
// We have a valid collection of RTP Packets
|
||||
// walk forwards building a sample if everything looks good clear and update buffer+values
|
||||
func (s *SampleBuilder) buildSample(firstBuffer uint16) *media.RTCSample {
|
||||
func (s *SampleBuilder) buildSample(firstBuffer uint16) *media.Sample {
|
||||
data := []byte{}
|
||||
|
||||
for i := firstBuffer; s.buffer[i] != nil; i++ {
|
||||
@@ -59,7 +59,7 @@ func (s *SampleBuilder) buildSample(firstBuffer uint16) *media.RTCSample {
|
||||
for j := firstBuffer; j < i; j++ {
|
||||
s.buffer[j] = nil
|
||||
}
|
||||
return &media.RTCSample{Data: data, Samples: samples}
|
||||
return &media.Sample{Data: data, Samples: samples}
|
||||
}
|
||||
|
||||
p, err := s.depacketizer.Unmarshal(s.buffer[i])
|
||||
@@ -82,7 +82,7 @@ func seqnumDistance(x, y uint16) uint16 {
|
||||
}
|
||||
|
||||
// Pop scans buffer for valid samples, returns nil when no valid samples have been found
|
||||
func (s *SampleBuilder) Pop() *media.RTCSample {
|
||||
func (s *SampleBuilder) Pop() *media.Sample {
|
||||
var i uint16
|
||||
if !s.isContiguous {
|
||||
i = s.lastPush - s.maxLate
|
||||
|
@@ -11,7 +11,7 @@ import (
|
||||
type sampleBuilderTest struct {
|
||||
message string
|
||||
packets []*rtp.Packet
|
||||
samples []*media.RTCSample
|
||||
samples []*media.Sample
|
||||
maxLate uint16
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ var testCases = []sampleBuilderTest{
|
||||
packets: []*rtp.Packet{
|
||||
{Header: rtp.Header{SequenceNumber: 5000, Timestamp: 5}, Payload: []byte{0x01}},
|
||||
},
|
||||
samples: []*media.RTCSample{},
|
||||
samples: []*media.Sample{},
|
||||
maxLate: 50,
|
||||
},
|
||||
{
|
||||
@@ -38,7 +38,7 @@ var testCases = []sampleBuilderTest{
|
||||
{Header: rtp.Header{SequenceNumber: 5001, Timestamp: 6}, Payload: []byte{0x02}},
|
||||
{Header: rtp.Header{SequenceNumber: 5002, Timestamp: 7}, Payload: []byte{0x03}},
|
||||
},
|
||||
samples: []*media.RTCSample{
|
||||
samples: []*media.Sample{
|
||||
{Data: []byte{0x02}, Samples: 1},
|
||||
},
|
||||
maxLate: 50,
|
||||
@@ -51,7 +51,7 @@ var testCases = []sampleBuilderTest{
|
||||
{Header: rtp.Header{SequenceNumber: 5002, Timestamp: 6}, Payload: []byte{0x03}},
|
||||
{Header: rtp.Header{SequenceNumber: 5003, Timestamp: 7}, Payload: []byte{0x04}},
|
||||
},
|
||||
samples: []*media.RTCSample{
|
||||
samples: []*media.Sample{
|
||||
{Data: []byte{0x02, 0x03}, Samples: 1},
|
||||
},
|
||||
maxLate: 50,
|
||||
@@ -63,7 +63,7 @@ var testCases = []sampleBuilderTest{
|
||||
{Header: rtp.Header{SequenceNumber: 5007, Timestamp: 6}, Payload: []byte{0x02}},
|
||||
{Header: rtp.Header{SequenceNumber: 5008, Timestamp: 7}, Payload: []byte{0x03}},
|
||||
},
|
||||
samples: []*media.RTCSample{},
|
||||
samples: []*media.Sample{},
|
||||
maxLate: 50,
|
||||
},
|
||||
{
|
||||
@@ -76,7 +76,7 @@ var testCases = []sampleBuilderTest{
|
||||
{Header: rtp.Header{SequenceNumber: 5004, Timestamp: 5}, Payload: []byte{0x05}},
|
||||
{Header: rtp.Header{SequenceNumber: 5005, Timestamp: 6}, Payload: []byte{0x06}},
|
||||
},
|
||||
samples: []*media.RTCSample{
|
||||
samples: []*media.Sample{
|
||||
{Data: []byte{0x02}, Samples: 1},
|
||||
{Data: []byte{0x03}, Samples: 1},
|
||||
{Data: []byte{0x04}, Samples: 1},
|
||||
@@ -91,7 +91,7 @@ func TestSampleBuilder(t *testing.T) {
|
||||
|
||||
for _, t := range testCases {
|
||||
s := New(t.maxLate, &fakeDepacketizer{})
|
||||
samples := []*media.RTCSample{}
|
||||
samples := []*media.Sample{}
|
||||
|
||||
for _, p := range t.packets {
|
||||
s.Push(p)
|
||||
@@ -112,10 +112,10 @@ func TestSampleBuilderMaxLate(t *testing.T) {
|
||||
s.Push(&rtp.Packet{Header: rtp.Header{SequenceNumber: 0, Timestamp: 1}, Payload: []byte{0x01}})
|
||||
s.Push(&rtp.Packet{Header: rtp.Header{SequenceNumber: 1, Timestamp: 2}, Payload: []byte{0x01}})
|
||||
s.Push(&rtp.Packet{Header: rtp.Header{SequenceNumber: 2, Timestamp: 3}, Payload: []byte{0x01}})
|
||||
assert.Equal(s.Pop(), &media.RTCSample{Data: []byte{0x01}, Samples: 1}, "Failed to build samples before gap")
|
||||
assert.Equal(s.Pop(), &media.Sample{Data: []byte{0x01}, Samples: 1}, "Failed to build samples before gap")
|
||||
|
||||
s.Push(&rtp.Packet{Header: rtp.Header{SequenceNumber: 5000, Timestamp: 500}, Payload: []byte{0x02}})
|
||||
s.Push(&rtp.Packet{Header: rtp.Header{SequenceNumber: 5001, Timestamp: 501}, Payload: []byte{0x02}})
|
||||
s.Push(&rtp.Packet{Header: rtp.Header{SequenceNumber: 5002, Timestamp: 502}, Payload: []byte{0x02}})
|
||||
assert.Equal(s.Pop(), &media.RTCSample{Data: []byte{0x02}, Samples: 1}, "Failed to build samples after large gap")
|
||||
assert.Equal(s.Pop(), &media.Sample{Data: []byte{0x02}, Samples: 1}, "Failed to build samples after large gap")
|
||||
}
|
||||
|
@@ -29,7 +29,7 @@ type Config struct {
|
||||
|
||||
// StartBase is used to start the TransportBase. Most implementations
|
||||
// should instead use the methods on quic.Transport or
|
||||
// webrtc.RTCQuicTransport to setup a Quic connection.
|
||||
// webrtc.QUICTransport to setup a Quic connection.
|
||||
func (b *TransportBase) StartBase(conn net.Conn, config *Config) error {
|
||||
cfg := config.clone()
|
||||
cfg.SkipVerify = true // Using self signed certificates; WebRTC will check the fingerprint
|
||||
|
@@ -1,57 +1,57 @@
|
||||
package webrtc
|
||||
|
||||
// RTCBundlePolicy affects which media tracks are negotiated if the remote
|
||||
// BundlePolicy affects which media tracks are negotiated if the remote
|
||||
// endpoint is not bundle-aware, and what ICE candidates are gathered. If the
|
||||
// remote endpoint is bundle-aware, all media tracks and data channels are
|
||||
// bundled onto the same transport.
|
||||
type RTCBundlePolicy int
|
||||
type BundlePolicy int
|
||||
|
||||
const (
|
||||
// RTCBundlePolicyBalanced indicates to gather ICE candidates for each
|
||||
// BundlePolicyBalanced indicates to gather ICE candidates for each
|
||||
// media type in use (audio, video, and data). If the remote endpoint is
|
||||
// not bundle-aware, negotiate only one audio and video track on separate
|
||||
// transports.
|
||||
RTCBundlePolicyBalanced RTCBundlePolicy = iota + 1
|
||||
BundlePolicyBalanced BundlePolicy = iota + 1
|
||||
|
||||
// RTCBundlePolicyMaxCompat indicates to gather ICE candidates for each
|
||||
// BundlePolicyMaxCompat indicates to gather ICE candidates for each
|
||||
// track. If the remote endpoint is not bundle-aware, negotiate all media
|
||||
// tracks on separate transports.
|
||||
RTCBundlePolicyMaxCompat
|
||||
BundlePolicyMaxCompat
|
||||
|
||||
// RTCBundlePolicyMaxBundle indicates to gather ICE candidates for only
|
||||
// BundlePolicyMaxBundle indicates to gather ICE candidates for only
|
||||
// one track. If the remote endpoint is not bundle-aware, negotiate only
|
||||
// one media track.
|
||||
RTCBundlePolicyMaxBundle
|
||||
BundlePolicyMaxBundle
|
||||
)
|
||||
|
||||
// This is done this way because of a linter.
|
||||
const (
|
||||
rtcBundlePolicyBalancedStr = "balanced"
|
||||
rtcBundlePolicyMaxCompatStr = "max-compat"
|
||||
rtcBundlePolicyMaxBundleStr = "max-bundle"
|
||||
bundlePolicyBalancedStr = "balanced"
|
||||
bundlePolicyMaxCompatStr = "max-compat"
|
||||
bundlePolicyMaxBundleStr = "max-bundle"
|
||||
)
|
||||
|
||||
func newRTCBundlePolicy(raw string) RTCBundlePolicy {
|
||||
func newBundlePolicy(raw string) BundlePolicy {
|
||||
switch raw {
|
||||
case rtcBundlePolicyBalancedStr:
|
||||
return RTCBundlePolicyBalanced
|
||||
case rtcBundlePolicyMaxCompatStr:
|
||||
return RTCBundlePolicyMaxCompat
|
||||
case rtcBundlePolicyMaxBundleStr:
|
||||
return RTCBundlePolicyMaxBundle
|
||||
case bundlePolicyBalancedStr:
|
||||
return BundlePolicyBalanced
|
||||
case bundlePolicyMaxCompatStr:
|
||||
return BundlePolicyMaxCompat
|
||||
case bundlePolicyMaxBundleStr:
|
||||
return BundlePolicyMaxBundle
|
||||
default:
|
||||
return RTCBundlePolicy(Unknown)
|
||||
return BundlePolicy(Unknown)
|
||||
}
|
||||
}
|
||||
|
||||
func (t RTCBundlePolicy) String() string {
|
||||
func (t BundlePolicy) String() string {
|
||||
switch t {
|
||||
case RTCBundlePolicyBalanced:
|
||||
return rtcBundlePolicyBalancedStr
|
||||
case RTCBundlePolicyMaxCompat:
|
||||
return rtcBundlePolicyMaxCompatStr
|
||||
case RTCBundlePolicyMaxBundle:
|
||||
return rtcBundlePolicyMaxBundleStr
|
||||
case BundlePolicyBalanced:
|
||||
return bundlePolicyBalancedStr
|
||||
case BundlePolicyMaxCompat:
|
||||
return bundlePolicyMaxCompatStr
|
||||
case BundlePolicyMaxBundle:
|
||||
return bundlePolicyMaxBundleStr
|
||||
default:
|
||||
return ErrUnknownType.Error()
|
||||
}
|
||||
|
@@ -6,35 +6,35 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewRTCBundlePolicy(t *testing.T) {
|
||||
func TestNewBundlePolicy(t *testing.T) {
|
||||
testCases := []struct {
|
||||
policyString string
|
||||
expectedPolicy RTCBundlePolicy
|
||||
expectedPolicy BundlePolicy
|
||||
}{
|
||||
{unknownStr, RTCBundlePolicy(Unknown)},
|
||||
{"balanced", RTCBundlePolicyBalanced},
|
||||
{"max-compat", RTCBundlePolicyMaxCompat},
|
||||
{"max-bundle", RTCBundlePolicyMaxBundle},
|
||||
{unknownStr, BundlePolicy(Unknown)},
|
||||
{"balanced", BundlePolicyBalanced},
|
||||
{"max-compat", BundlePolicyMaxCompat},
|
||||
{"max-bundle", BundlePolicyMaxBundle},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
assert.Equal(t,
|
||||
testCase.expectedPolicy,
|
||||
newRTCBundlePolicy(testCase.policyString),
|
||||
newBundlePolicy(testCase.policyString),
|
||||
"testCase: %d %v", i, testCase,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRTCBundlePolicy_String(t *testing.T) {
|
||||
func TestBundlePolicy_String(t *testing.T) {
|
||||
testCases := []struct {
|
||||
policy RTCBundlePolicy
|
||||
policy BundlePolicy
|
||||
expectedString string
|
||||
}{
|
||||
{RTCBundlePolicy(Unknown), unknownStr},
|
||||
{RTCBundlePolicyBalanced, "balanced"},
|
||||
{RTCBundlePolicyMaxCompat, "max-compat"},
|
||||
{RTCBundlePolicyMaxBundle, "max-bundle"},
|
||||
{BundlePolicy(Unknown), unknownStr},
|
||||
{BundlePolicyBalanced, "balanced"},
|
||||
{BundlePolicyMaxCompat, "max-compat"},
|
||||
{BundlePolicyMaxBundle, "max-bundle"},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
|
@@ -16,17 +16,17 @@ import (
|
||||
"github.com/pions/webrtc/pkg/rtcerr"
|
||||
)
|
||||
|
||||
// RTCCertificate represents a x509Cert used to authenticate WebRTC communications.
|
||||
type RTCCertificate struct {
|
||||
// Certificate represents a x509Cert used to authenticate WebRTC communications.
|
||||
type Certificate struct {
|
||||
privateKey crypto.PrivateKey
|
||||
x509Cert *x509.Certificate
|
||||
}
|
||||
|
||||
// NewRTCCertificate generates a new x509 compliant RTCCertificate to be used
|
||||
// NewCertificate generates a new x509 compliant Certificate to be used
|
||||
// by DTLS for encrypting data sent over the wire. This method differs from
|
||||
// GenerateCertificate by allowing to specify a template x509.Certificate to
|
||||
// be used in order to define certificate parameters.
|
||||
func NewRTCCertificate(key crypto.PrivateKey, tpl x509.Certificate) (*RTCCertificate, error) {
|
||||
func NewCertificate(key crypto.PrivateKey, tpl x509.Certificate) (*Certificate, error) {
|
||||
var err error
|
||||
var certDER []byte
|
||||
switch sk := key.(type) {
|
||||
@@ -53,12 +53,12 @@ func NewRTCCertificate(key crypto.PrivateKey, tpl x509.Certificate) (*RTCCertifi
|
||||
return nil, &rtcerr.UnknownError{Err: err}
|
||||
}
|
||||
|
||||
return &RTCCertificate{privateKey: key, x509Cert: cert}, nil
|
||||
return &Certificate{privateKey: key, x509Cert: cert}, nil
|
||||
}
|
||||
|
||||
// Equals determines if two certificates are identical by comparing both the
|
||||
// secretKeys and x509Certificates.
|
||||
func (c RTCCertificate) Equals(o RTCCertificate) bool {
|
||||
func (c Certificate) Equals(o Certificate) bool {
|
||||
switch cSK := c.privateKey.(type) {
|
||||
case *rsa.PrivateKey:
|
||||
if oSK, ok := o.privateKey.(*rsa.PrivateKey); ok {
|
||||
@@ -82,7 +82,7 @@ func (c RTCCertificate) Equals(o RTCCertificate) bool {
|
||||
}
|
||||
|
||||
// Expires returns the timestamp after which this certificate is no longer valid.
|
||||
func (c RTCCertificate) Expires() time.Time {
|
||||
func (c Certificate) Expires() time.Time {
|
||||
if c.x509Cert == nil {
|
||||
return time.Time{}
|
||||
}
|
||||
@@ -93,8 +93,8 @@ var fingerprintAlgorithms = []dtls.HashAlgorithm{dtls.HashAlgorithmSHA256}
|
||||
|
||||
// GetFingerprints returns the list of certificate fingerprints, one of which
|
||||
// is computed with the digest algorithm used in the certificate signature.
|
||||
func (c RTCCertificate) GetFingerprints() []RTCDtlsFingerprint {
|
||||
res := make([]RTCDtlsFingerprint, len(fingerprintAlgorithms))
|
||||
func (c Certificate) GetFingerprints() []DTLSFingerprint {
|
||||
res := make([]DTLSFingerprint, len(fingerprintAlgorithms))
|
||||
|
||||
i := 0
|
||||
for _, algo := range fingerprintAlgorithms {
|
||||
@@ -103,7 +103,7 @@ func (c RTCCertificate) GetFingerprints() []RTCDtlsFingerprint {
|
||||
fmt.Printf("Failed to create fingerprint: %v\n", err)
|
||||
continue
|
||||
}
|
||||
res[i] = RTCDtlsFingerprint{
|
||||
res[i] = DTLSFingerprint{
|
||||
Algorithm: algo.String(),
|
||||
Value: value,
|
||||
}
|
||||
@@ -114,7 +114,7 @@ func (c RTCCertificate) GetFingerprints() []RTCDtlsFingerprint {
|
||||
|
||||
// GenerateCertificate causes the creation of an X.509 certificate and
|
||||
// corresponding private key.
|
||||
func GenerateCertificate(secretKey crypto.PrivateKey) (*RTCCertificate, error) {
|
||||
func GenerateCertificate(secretKey crypto.PrivateKey) (*Certificate, error) {
|
||||
origin := make([]byte, 16)
|
||||
/* #nosec */
|
||||
if _, err := rand.Read(origin); err != nil {
|
||||
@@ -131,7 +131,7 @@ func GenerateCertificate(secretKey crypto.PrivateKey) (*RTCCertificate, error) {
|
||||
return nil, &rtcerr.UnknownError{Err: err}
|
||||
}
|
||||
|
||||
return NewRTCCertificate(secretKey, x509.Certificate{
|
||||
return NewCertificate(secretKey, x509.Certificate{
|
||||
ExtKeyUsage: []x509.ExtKeyUsage{
|
||||
x509.ExtKeyUsageClientAuth,
|
||||
x509.ExtKeyUsageServerAuth,
|
||||
|
@@ -4,51 +4,51 @@ import (
|
||||
"github.com/pions/webrtc/pkg/ice"
|
||||
)
|
||||
|
||||
// RTCConfiguration defines a set of parameters to configure how the
|
||||
// peer-to-peer communication via RTCPeerConnection is established or
|
||||
// Configuration defines a set of parameters to configure how the
|
||||
// peer-to-peer communication via PeerConnection is established or
|
||||
// re-established.
|
||||
type RTCConfiguration struct {
|
||||
// IceServers defines a slice describing servers available to be used by
|
||||
type Configuration struct {
|
||||
// ICEServers defines a slice describing servers available to be used by
|
||||
// ICE, such as STUN and TURN servers.
|
||||
IceServers []RTCIceServer
|
||||
ICEServers []ICEServer
|
||||
|
||||
// IceTransportPolicy indicates which candidates the IceAgent is allowed
|
||||
// ICETransportPolicy indicates which candidates the ICEAgent is allowed
|
||||
// to use.
|
||||
IceTransportPolicy RTCIceTransportPolicy
|
||||
ICETransportPolicy ICETransportPolicy
|
||||
|
||||
// BundlePolicy indicates which media-bundling policy to use when gathering
|
||||
// ICE candidates.
|
||||
BundlePolicy RTCBundlePolicy
|
||||
BundlePolicy BundlePolicy
|
||||
|
||||
// RtcpMuxPolicy indicates which rtcp-mux policy to use when gathering ICE
|
||||
// RTCPMuxPolicy indicates which rtcp-mux policy to use when gathering ICE
|
||||
// candidates.
|
||||
RtcpMuxPolicy RTCRtcpMuxPolicy
|
||||
RTCPMuxPolicy RTCPMuxPolicy
|
||||
|
||||
// PeerIdentity sets the target peer identity for the RTCPeerConnection.
|
||||
// The RTCPeerConnection will not establish a connection to a remote peer
|
||||
// PeerIdentity sets the target peer identity for the PeerConnection.
|
||||
// The PeerConnection will not establish a connection to a remote peer
|
||||
// unless it can be successfully authenticated with the provided name.
|
||||
PeerIdentity string
|
||||
|
||||
// Certificates describes a set of certificates that the RTCPeerConnection
|
||||
// Certificates describes a set of certificates that the PeerConnection
|
||||
// uses to authenticate. Valid values for this parameter are created
|
||||
// through calls to the GenerateCertificate function. Although any given
|
||||
// DTLS connection will use only one certificate, this attribute allows the
|
||||
// caller to provide multiple certificates that support different
|
||||
// algorithms. The final certificate will be selected based on the DTLS
|
||||
// handshake, which establishes which certificates are allowed. The
|
||||
// RTCPeerConnection implementation selects which of the certificates is
|
||||
// PeerConnection implementation selects which of the certificates is
|
||||
// used for a given connection; how certificates are selected is outside
|
||||
// the scope of this specification. If this value is absent, then a default
|
||||
// set of certificates is generated for each RTCPeerConnection instance.
|
||||
Certificates []RTCCertificate
|
||||
// set of certificates is generated for each PeerConnection instance.
|
||||
Certificates []Certificate
|
||||
|
||||
// IceCandidatePoolSize describes the size of the prefetched ICE pool.
|
||||
IceCandidatePoolSize uint8
|
||||
// ICECandidatePoolSize describes the size of the prefetched ICE pool.
|
||||
ICECandidatePoolSize uint8
|
||||
}
|
||||
|
||||
func (c RTCConfiguration) getIceServers() (*[]*ice.URL, error) {
|
||||
func (c Configuration) getICEServers() (*[]*ice.URL, error) {
|
||||
var iceServers []*ice.URL
|
||||
for _, server := range c.IceServers {
|
||||
for _, server := range c.ICEServers {
|
||||
for _, rawURL := range server.URLs {
|
||||
url, err := ice.ParseURL(rawURL)
|
||||
if err != nil {
|
||||
|
@@ -6,33 +6,33 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRTCConfiguration_getIceServers(t *testing.T) {
|
||||
func TestConfiguration_getICEServers(t *testing.T) {
|
||||
t.Run("Success", func(t *testing.T) {
|
||||
expectedServerStr := "stun:stun.l.google.com:19302"
|
||||
cfg := RTCConfiguration{
|
||||
IceServers: []RTCIceServer{
|
||||
cfg := Configuration{
|
||||
ICEServers: []ICEServer{
|
||||
{
|
||||
URLs: []string{expectedServerStr},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
parsedURLs, err := cfg.getIceServers()
|
||||
parsedURLs, err := cfg.getICEServers()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, expectedServerStr, (*parsedURLs)[0].String())
|
||||
})
|
||||
|
||||
t.Run("Failure", func(t *testing.T) {
|
||||
expectedServerStr := "stun.l.google.com:19302"
|
||||
cfg := RTCConfiguration{
|
||||
IceServers: []RTCIceServer{
|
||||
cfg := Configuration{
|
||||
ICEServers: []ICEServer{
|
||||
{
|
||||
URLs: []string{expectedServerStr},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
_, err := cfg.getIceServers()
|
||||
_, err := cfg.getICEServers()
|
||||
assert.NotNil(t, err)
|
||||
})
|
||||
}
|
||||
|
@@ -13,18 +13,18 @@ import (
|
||||
|
||||
const dataChannelBufferSize = 16384 // Lowest common denominator among browsers
|
||||
|
||||
// RTCDataChannel represents a WebRTC DataChannel
|
||||
// The RTCDataChannel interface represents a network channel
|
||||
// DataChannel represents a WebRTC DataChannel
|
||||
// The DataChannel interface represents a network channel
|
||||
// which can be used for bidirectional peer-to-peer transfers of arbitrary data
|
||||
type RTCDataChannel struct {
|
||||
type DataChannel struct {
|
||||
mu sync.RWMutex
|
||||
|
||||
// Label represents a label that can be used to distinguish this
|
||||
// RTCDataChannel object from other RTCDataChannel objects. Scripts are
|
||||
// allowed to create multiple RTCDataChannel objects with the same label.
|
||||
// DataChannel object from other DataChannel objects. Scripts are
|
||||
// allowed to create multiple DataChannel objects with the same label.
|
||||
Label string
|
||||
|
||||
// Ordered represents if the RTCDataChannel is ordered, and false if
|
||||
// Ordered represents if the DataChannel is ordered, and false if
|
||||
// out-of-order delivery is allowed.
|
||||
Ordered bool
|
||||
|
||||
@@ -37,14 +37,14 @@ type RTCDataChannel struct {
|
||||
MaxRetransmits *uint16
|
||||
|
||||
// Protocol represents the name of the sub-protocol used with this
|
||||
// RTCDataChannel.
|
||||
// DataChannel.
|
||||
Protocol string
|
||||
|
||||
// Negotiated represents whether this RTCDataChannel was negotiated by the
|
||||
// Negotiated represents whether this DataChannel was negotiated by the
|
||||
// application (true), or not (false).
|
||||
Negotiated bool
|
||||
|
||||
// ID represents the ID for this RTCDataChannel. The value is initially
|
||||
// ID represents the ID for this DataChannel. The value is initially
|
||||
// null, which is what will be returned if the ID was not provided at
|
||||
// channel creation time, and the DTLS role of the SCTP transport has not
|
||||
// yet been negotiated. Otherwise, it will return the ID that was either
|
||||
@@ -52,12 +52,12 @@ type RTCDataChannel struct {
|
||||
// value, it will not change.
|
||||
ID *uint16
|
||||
|
||||
// Priority represents the priority for this RTCDataChannel. The priority is
|
||||
// Priority represents the priority for this DataChannel. The priority is
|
||||
// assigned at channel creation time.
|
||||
Priority RTCPriorityType
|
||||
Priority PriorityType
|
||||
|
||||
// ReadyState represents the state of the RTCDataChannel object.
|
||||
ReadyState RTCDataChannelState
|
||||
// ReadyState represents the state of the DataChannel object.
|
||||
ReadyState DataChannelState
|
||||
|
||||
// BufferedAmount represents the number of bytes of application data
|
||||
// (UTF-8 text and binary data) that have been queued using send(). Even
|
||||
@@ -75,13 +75,13 @@ type RTCDataChannel struct {
|
||||
// bufferedAmount is considered to be low. When the bufferedAmount decreases
|
||||
// from above this threshold to equal or below it, the bufferedamountlow
|
||||
// event fires. BufferedAmountLowThreshold is initially zero on each new
|
||||
// RTCDataChannel, but the application may change its value at any time.
|
||||
// DataChannel, but the application may change its value at any time.
|
||||
BufferedAmountLowThreshold uint64
|
||||
|
||||
// The binaryType represents attribute MUST, on getting, return the value to
|
||||
// which it was last set. On setting, if the new value is either the string
|
||||
// "blob" or the string "arraybuffer", then set the IDL attribute to this
|
||||
// new value. Otherwise, throw a SyntaxError. When an RTCDataChannel object
|
||||
// new value. Otherwise, throw a SyntaxError. When an DataChannel object
|
||||
// is created, the binaryType attribute MUST be initialized to the string
|
||||
// "blob". This attribute controls how binary data is exposed to scripts.
|
||||
// binaryType string
|
||||
@@ -95,18 +95,18 @@ type RTCDataChannel struct {
|
||||
onOpenHandler func()
|
||||
onCloseHandler func()
|
||||
|
||||
sctpTransport *RTCSctpTransport
|
||||
sctpTransport *SCTPTransport
|
||||
dataChannel *datachannel.DataChannel
|
||||
|
||||
// A reference to the associated api object used by this datachannel
|
||||
api *API
|
||||
}
|
||||
|
||||
// NewRTCDataChannel creates a new RTCDataChannel.
|
||||
// NewDataChannel creates a new DataChannel.
|
||||
// This constructor is part of the ORTC API. It is not
|
||||
// meant to be used together with the basic WebRTC API.
|
||||
func (api *API) NewRTCDataChannel(transport *RTCSctpTransport, params *RTCDataChannelParameters) (*RTCDataChannel, error) {
|
||||
d, err := api.newRTCDataChannel(params)
|
||||
func (api *API) NewDataChannel(transport *SCTPTransport, params *DataChannelParameters) (*DataChannel, error) {
|
||||
d, err := api.newDataChannel(params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -119,18 +119,18 @@ func (api *API) NewRTCDataChannel(transport *RTCSctpTransport, params *RTCDataCh
|
||||
return d, nil
|
||||
}
|
||||
|
||||
// newRTCDataChannel is an internal constructor for the data channel used to
|
||||
// create the RTCDataChannel object before the networking is set up.
|
||||
func (api *API) newRTCDataChannel(params *RTCDataChannelParameters) (*RTCDataChannel, error) {
|
||||
// newDataChannel is an internal constructor for the data channel used to
|
||||
// create the DataChannel object before the networking is set up.
|
||||
func (api *API) newDataChannel(params *DataChannelParameters) (*DataChannel, error) {
|
||||
// https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #5)
|
||||
if len(params.Label) > 65535 {
|
||||
return nil, &rtcerr.TypeError{Err: ErrStringSizeLimit}
|
||||
}
|
||||
|
||||
d := &RTCDataChannel{
|
||||
d := &DataChannel{
|
||||
Label: params.Label,
|
||||
ID: ¶ms.ID,
|
||||
ReadyState: RTCDataChannelStateConnecting,
|
||||
ReadyState: DataChannelStateConnecting,
|
||||
api: api,
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ func (api *API) newRTCDataChannel(params *RTCDataChannelParameters) (*RTCDataCha
|
||||
}
|
||||
|
||||
// open opens the datachannel over the sctp transport
|
||||
func (d *RTCDataChannel) open(sctpTransport *RTCSctpTransport) error {
|
||||
func (d *DataChannel) open(sctpTransport *SCTPTransport) error {
|
||||
d.mu.RLock()
|
||||
d.sctpTransport = sctpTransport
|
||||
|
||||
@@ -160,14 +160,14 @@ func (d *RTCDataChannel) open(sctpTransport *RTCSctpTransport) error {
|
||||
return err
|
||||
}
|
||||
|
||||
d.ReadyState = RTCDataChannelStateOpen
|
||||
d.ReadyState = DataChannelStateOpen
|
||||
d.mu.RUnlock()
|
||||
|
||||
d.handleOpen(dc)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *RTCDataChannel) ensureSCTP() error {
|
||||
func (d *DataChannel) ensureSCTP() error {
|
||||
if d.sctpTransport == nil ||
|
||||
d.sctpTransport.association == nil {
|
||||
return errors.New("SCTP not establisched")
|
||||
@@ -175,8 +175,8 @@ func (d *RTCDataChannel) ensureSCTP() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Transport returns the RTCSctpTransport instance the RTCDataChannel is sending over.
|
||||
func (d *RTCDataChannel) Transport() *RTCSctpTransport {
|
||||
// Transport returns the SCTPTransport instance the DataChannel is sending over.
|
||||
func (d *DataChannel) Transport() *SCTPTransport {
|
||||
d.mu.RLock()
|
||||
defer d.mu.RUnlock()
|
||||
|
||||
@@ -185,13 +185,13 @@ func (d *RTCDataChannel) Transport() *RTCSctpTransport {
|
||||
|
||||
// OnOpen sets an event handler which is invoked when
|
||||
// the underlying data transport has been established (or re-established).
|
||||
func (d *RTCDataChannel) OnOpen(f func()) {
|
||||
func (d *DataChannel) OnOpen(f func()) {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
d.onOpenHandler = f
|
||||
}
|
||||
|
||||
func (d *RTCDataChannel) onOpen() (done chan struct{}) {
|
||||
func (d *DataChannel) onOpen() (done chan struct{}) {
|
||||
d.mu.RLock()
|
||||
hdlr := d.onOpenHandler
|
||||
d.mu.RUnlock()
|
||||
@@ -212,13 +212,13 @@ func (d *RTCDataChannel) onOpen() (done chan struct{}) {
|
||||
|
||||
// OnClose sets an event handler which is invoked when
|
||||
// the underlying data transport has been closed.
|
||||
func (d *RTCDataChannel) OnClose(f func()) {
|
||||
func (d *DataChannel) OnClose(f func()) {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
d.onCloseHandler = f
|
||||
}
|
||||
|
||||
func (d *RTCDataChannel) onClose() (done chan struct{}) {
|
||||
func (d *DataChannel) onClose() (done chan struct{}) {
|
||||
d.mu.RLock()
|
||||
hdlr := d.onCloseHandler
|
||||
d.mu.RUnlock()
|
||||
@@ -243,13 +243,13 @@ func (d *RTCDataChannel) onClose() (done chan struct{}) {
|
||||
// in size. Check out the detach API if you want to use larger
|
||||
// message sizes. Note that browser support for larger messages
|
||||
// is also limited.
|
||||
func (d *RTCDataChannel) OnMessage(f func(p sugar.Payload)) {
|
||||
func (d *DataChannel) OnMessage(f func(p sugar.Payload)) {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
d.onMessageHandler = f
|
||||
}
|
||||
|
||||
func (d *RTCDataChannel) onMessage(p sugar.Payload) {
|
||||
func (d *DataChannel) onMessage(p sugar.Payload) {
|
||||
d.mu.RLock()
|
||||
hdlr := d.onMessageHandler
|
||||
d.mu.RUnlock()
|
||||
@@ -264,11 +264,11 @@ func (d *RTCDataChannel) onMessage(p sugar.Payload) {
|
||||
// arrival over the sctp transport from a remote peer.
|
||||
//
|
||||
// Deprecated: use OnMessage instead.
|
||||
func (d *RTCDataChannel) Onmessage(f func(p sugar.Payload)) {
|
||||
func (d *DataChannel) Onmessage(f func(p sugar.Payload)) {
|
||||
d.OnMessage(f)
|
||||
}
|
||||
|
||||
func (d *RTCDataChannel) handleOpen(dc *datachannel.DataChannel) {
|
||||
func (d *DataChannel) handleOpen(dc *datachannel.DataChannel) {
|
||||
d.mu.Lock()
|
||||
d.dataChannel = dc
|
||||
d.mu.Unlock()
|
||||
@@ -283,7 +283,7 @@ func (d *RTCDataChannel) handleOpen(dc *datachannel.DataChannel) {
|
||||
}
|
||||
}
|
||||
|
||||
func (d *RTCDataChannel) readLoop() {
|
||||
func (d *DataChannel) readLoop() {
|
||||
for {
|
||||
buffer := make([]byte, dataChannelBufferSize)
|
||||
n, isString, err := d.dataChannel.ReadDataChannel(buffer)
|
||||
@@ -293,7 +293,7 @@ func (d *RTCDataChannel) readLoop() {
|
||||
}
|
||||
if err != nil {
|
||||
d.mu.Lock()
|
||||
d.ReadyState = RTCDataChannelStateClosed
|
||||
d.ReadyState = DataChannelStateClosed
|
||||
d.mu.Unlock()
|
||||
if err != io.EOF {
|
||||
// TODO: Throw OnError
|
||||
@@ -312,7 +312,7 @@ func (d *RTCDataChannel) readLoop() {
|
||||
}
|
||||
|
||||
// Send sends the passed message to the DataChannel peer
|
||||
func (d *RTCDataChannel) Send(payload sugar.Payload) error {
|
||||
func (d *DataChannel) Send(payload sugar.Payload) error {
|
||||
err := d.ensureOpen()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -339,10 +339,10 @@ func (d *RTCDataChannel) Send(payload sugar.Payload) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *RTCDataChannel) ensureOpen() error {
|
||||
func (d *DataChannel) ensureOpen() error {
|
||||
d.mu.RLock()
|
||||
defer d.mu.RUnlock()
|
||||
if d.ReadyState != RTCDataChannelStateOpen {
|
||||
if d.ReadyState != DataChannelStateOpen {
|
||||
return &rtcerr.InvalidStateError{Err: ErrDataChannelNotOpen}
|
||||
}
|
||||
return nil
|
||||
@@ -356,7 +356,7 @@ func (d *RTCDataChannel) ensureOpen() error {
|
||||
// Please reffer to the data-channels-detach example and the
|
||||
// pions/datachannel documentation for the correct way to handle the
|
||||
// resulting DataChannel object.
|
||||
func (d *RTCDataChannel) Detach() (*datachannel.DataChannel, error) {
|
||||
func (d *DataChannel) Detach() (*datachannel.DataChannel, error) {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
|
||||
@@ -371,18 +371,18 @@ func (d *RTCDataChannel) Detach() (*datachannel.DataChannel, error) {
|
||||
return d.dataChannel, nil
|
||||
}
|
||||
|
||||
// Close Closes the RTCDataChannel. It may be called regardless of whether
|
||||
// the RTCDataChannel object was created by this peer or the remote peer.
|
||||
func (d *RTCDataChannel) Close() error {
|
||||
// Close Closes the DataChannel. It may be called regardless of whether
|
||||
// the DataChannel object was created by this peer or the remote peer.
|
||||
func (d *DataChannel) Close() error {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
|
||||
if d.ReadyState == RTCDataChannelStateClosing ||
|
||||
d.ReadyState == RTCDataChannelStateClosed {
|
||||
if d.ReadyState == DataChannelStateClosing ||
|
||||
d.ReadyState == DataChannelStateClosed {
|
||||
return nil
|
||||
}
|
||||
|
||||
d.ReadyState = RTCDataChannelStateClosing
|
||||
d.ReadyState = DataChannelStateClosing
|
||||
|
||||
return d.dataChannel.Close()
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/pions/webrtc/pkg/datachannel"
|
||||
)
|
||||
|
||||
func TestRTCDataChannel_ORTCE2E(t *testing.T) {
|
||||
func TestDataChannel_ORTCE2E(t *testing.T) {
|
||||
// Limit runtime in case of deadlocks
|
||||
lim := test.TimeOut(time.Second * 20)
|
||||
defer lim.Stop()
|
||||
@@ -24,7 +24,7 @@ func TestRTCDataChannel_ORTCE2E(t *testing.T) {
|
||||
awaitSetup := make(chan struct{})
|
||||
awaitString := make(chan struct{})
|
||||
awaitBinary := make(chan struct{})
|
||||
stackB.sctp.OnDataChannel(func(d *RTCDataChannel) {
|
||||
stackB.sctp.OnDataChannel(func(d *DataChannel) {
|
||||
close(awaitSetup)
|
||||
d.OnMessage(func(payload datachannel.Payload) {
|
||||
switch payload.(type) {
|
||||
@@ -41,11 +41,11 @@ func TestRTCDataChannel_ORTCE2E(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
dcParams := &RTCDataChannelParameters{
|
||||
dcParams := &DataChannelParameters{
|
||||
Label: "Foo",
|
||||
ID: 1,
|
||||
}
|
||||
channelA, err := stackA.api.NewRTCDataChannel(stackA.sctp, dcParams)
|
||||
channelA, err := stackA.api.NewDataChannel(stackA.sctp, dcParams)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -76,16 +76,16 @@ func TestRTCDataChannel_ORTCE2E(t *testing.T) {
|
||||
|
||||
type testORTCStack struct {
|
||||
api *API
|
||||
gatherer *RTCIceGatherer
|
||||
ice *RTCIceTransport
|
||||
dtls *RTCDtlsTransport
|
||||
sctp *RTCSctpTransport
|
||||
gatherer *ICEGatherer
|
||||
ice *ICETransport
|
||||
dtls *DTLSTransport
|
||||
sctp *SCTPTransport
|
||||
}
|
||||
|
||||
func (s *testORTCStack) setSignal(sig *testORTCSignal, isOffer bool) error {
|
||||
iceRole := RTCIceRoleControlled
|
||||
iceRole := ICERoleControlled
|
||||
if isOffer {
|
||||
iceRole = RTCIceRoleControlling
|
||||
iceRole = ICERoleControlling
|
||||
}
|
||||
|
||||
err := s.ice.SetRemoteCandidates(sig.ICECandidates)
|
||||
@@ -100,7 +100,7 @@ func (s *testORTCStack) setSignal(sig *testORTCSignal, isOffer bool) error {
|
||||
}
|
||||
|
||||
// Start the DTLS transport
|
||||
err = s.dtls.Start(sig.DtlsParameters)
|
||||
err = s.dtls.Start(sig.DTLSParameters)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -138,7 +138,7 @@ func (s *testORTCStack) getSignal() (*testORTCSignal, error) {
|
||||
return &testORTCSignal{
|
||||
ICECandidates: iceCandidates,
|
||||
ICEParameters: iceParams,
|
||||
DtlsParameters: dtlsParams,
|
||||
DTLSParameters: dtlsParams,
|
||||
SCTPCapabilities: sctpCapabilities,
|
||||
}, nil
|
||||
}
|
||||
@@ -158,10 +158,10 @@ func (s *testORTCStack) close() error {
|
||||
}
|
||||
|
||||
type testORTCSignal struct {
|
||||
ICECandidates []RTCIceCandidate `json:"iceCandidates"`
|
||||
ICEParameters RTCIceParameters `json:"iceParameters"`
|
||||
DtlsParameters RTCDtlsParameters `json:"dtlsParameters"`
|
||||
SCTPCapabilities RTCSctpCapabilities `json:"sctpCapabilities"`
|
||||
ICECandidates []ICECandidate `json:"iceCandidates"`
|
||||
ICEParameters ICEParameters `json:"iceParameters"`
|
||||
DTLSParameters DTLSParameters `json:"dtlsParameters"`
|
||||
SCTPCapabilities SCTPCapabilities `json:"sctpCapabilities"`
|
||||
}
|
||||
|
||||
func newORTCPair() (stackA *testORTCStack, stackB *testORTCStack, err error) {
|
||||
@@ -183,22 +183,22 @@ func newORTCStack() (*testORTCStack, error) {
|
||||
api := NewAPI()
|
||||
|
||||
// Create the ICE gatherer
|
||||
gatherer, err := api.NewRTCIceGatherer(RTCIceGatherOptions{})
|
||||
gatherer, err := api.NewICEGatherer(ICEGatherOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Construct the ICE transport
|
||||
ice := api.NewRTCIceTransport(gatherer)
|
||||
ice := api.NewICETransport(gatherer)
|
||||
|
||||
// Construct the DTLS transport
|
||||
dtls, err := api.NewRTCDtlsTransport(ice, nil)
|
||||
dtls, err := api.NewDTLSTransport(ice, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Construct the SCTP transport
|
||||
sctp := api.NewRTCSctpTransport(dtls)
|
||||
sctp := api.NewSCTPTransport(dtls)
|
||||
|
||||
return &testORTCStack{
|
||||
api: api,
|
||||
|
@@ -18,19 +18,19 @@ func TestGenerateDataChannelID(t *testing.T) {
|
||||
|
||||
testCases := []struct {
|
||||
client bool
|
||||
c *RTCPeerConnection
|
||||
c *PeerConnection
|
||||
result uint16
|
||||
}{
|
||||
{true, &RTCPeerConnection{sctpTransport: api.NewRTCSctpTransport(nil), dataChannels: map[uint16]*RTCDataChannel{}, api: api}, 0},
|
||||
{true, &RTCPeerConnection{sctpTransport: api.NewRTCSctpTransport(nil), dataChannels: map[uint16]*RTCDataChannel{1: nil}, api: api}, 0},
|
||||
{true, &RTCPeerConnection{sctpTransport: api.NewRTCSctpTransport(nil), dataChannels: map[uint16]*RTCDataChannel{0: nil}, api: api}, 2},
|
||||
{true, &RTCPeerConnection{sctpTransport: api.NewRTCSctpTransport(nil), dataChannels: map[uint16]*RTCDataChannel{0: nil, 2: nil}, api: api}, 4},
|
||||
{true, &RTCPeerConnection{sctpTransport: api.NewRTCSctpTransport(nil), dataChannels: map[uint16]*RTCDataChannel{0: nil, 4: nil}, api: api}, 2},
|
||||
{false, &RTCPeerConnection{sctpTransport: api.NewRTCSctpTransport(nil), dataChannels: map[uint16]*RTCDataChannel{}, api: api}, 1},
|
||||
{false, &RTCPeerConnection{sctpTransport: api.NewRTCSctpTransport(nil), dataChannels: map[uint16]*RTCDataChannel{0: nil}, api: api}, 1},
|
||||
{false, &RTCPeerConnection{sctpTransport: api.NewRTCSctpTransport(nil), dataChannels: map[uint16]*RTCDataChannel{1: nil}, api: api}, 3},
|
||||
{false, &RTCPeerConnection{sctpTransport: api.NewRTCSctpTransport(nil), dataChannels: map[uint16]*RTCDataChannel{1: nil, 3: nil}, api: api}, 5},
|
||||
{false, &RTCPeerConnection{sctpTransport: api.NewRTCSctpTransport(nil), dataChannels: map[uint16]*RTCDataChannel{1: nil, 5: nil}, api: api}, 3},
|
||||
{true, &PeerConnection{sctpTransport: api.NewSCTPTransport(nil), dataChannels: map[uint16]*DataChannel{}, api: api}, 0},
|
||||
{true, &PeerConnection{sctpTransport: api.NewSCTPTransport(nil), dataChannels: map[uint16]*DataChannel{1: nil}, api: api}, 0},
|
||||
{true, &PeerConnection{sctpTransport: api.NewSCTPTransport(nil), dataChannels: map[uint16]*DataChannel{0: nil}, api: api}, 2},
|
||||
{true, &PeerConnection{sctpTransport: api.NewSCTPTransport(nil), dataChannels: map[uint16]*DataChannel{0: nil, 2: nil}, api: api}, 4},
|
||||
{true, &PeerConnection{sctpTransport: api.NewSCTPTransport(nil), dataChannels: map[uint16]*DataChannel{0: nil, 4: nil}, api: api}, 2},
|
||||
{false, &PeerConnection{sctpTransport: api.NewSCTPTransport(nil), dataChannels: map[uint16]*DataChannel{}, api: api}, 1},
|
||||
{false, &PeerConnection{sctpTransport: api.NewSCTPTransport(nil), dataChannels: map[uint16]*DataChannel{0: nil}, api: api}, 1},
|
||||
{false, &PeerConnection{sctpTransport: api.NewSCTPTransport(nil), dataChannels: map[uint16]*DataChannel{1: nil}, api: api}, 3},
|
||||
{false, &PeerConnection{sctpTransport: api.NewSCTPTransport(nil), dataChannels: map[uint16]*DataChannel{1: nil, 3: nil}, api: api}, 5},
|
||||
{false, &PeerConnection{sctpTransport: api.NewSCTPTransport(nil), dataChannels: map[uint16]*DataChannel{1: nil, 5: nil}, api: api}, 3},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
@@ -45,7 +45,7 @@ func TestGenerateDataChannelID(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRTCDataChannel_Send(t *testing.T) {
|
||||
func TestDataChannel_Send(t *testing.T) {
|
||||
report := test.CheckRoutines(t)
|
||||
defer report()
|
||||
|
||||
@@ -74,7 +74,7 @@ func TestRTCDataChannel_Send(t *testing.T) {
|
||||
done <- true
|
||||
})
|
||||
|
||||
answerPC.OnDataChannel(func(d *RTCDataChannel) {
|
||||
answerPC.OnDataChannel(func(d *DataChannel) {
|
||||
d.OnMessage(func(payload sugar.Payload) {
|
||||
e := d.Send(sugar.PayloadBinary{Data: []byte("Pong")})
|
||||
if e != nil {
|
||||
@@ -104,7 +104,7 @@ func TestRTCDataChannel_Send(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRTCDataChannel_EventHandlers(t *testing.T) {
|
||||
func TestDataChannel_EventHandlers(t *testing.T) {
|
||||
to := test.TimeOut(time.Second * 20)
|
||||
defer to.Stop()
|
||||
|
||||
@@ -112,7 +112,7 @@ func TestRTCDataChannel_EventHandlers(t *testing.T) {
|
||||
defer report()
|
||||
|
||||
api := NewAPI()
|
||||
dc := &RTCDataChannel{api: api}
|
||||
dc := &DataChannel{api: api}
|
||||
|
||||
onOpenCalled := make(chan bool)
|
||||
onMessageCalled := make(chan bool)
|
||||
@@ -153,12 +153,12 @@ func TestRTCDataChannel_EventHandlers(t *testing.T) {
|
||||
}))
|
||||
}
|
||||
|
||||
func TestRTCDataChannel_MessagesAreOrdered(t *testing.T) {
|
||||
func TestDataChannel_MessagesAreOrdered(t *testing.T) {
|
||||
report := test.CheckRoutines(t)
|
||||
defer report()
|
||||
|
||||
api := NewAPI()
|
||||
dc := &RTCDataChannel{api: api}
|
||||
dc := &DataChannel{api: api}
|
||||
|
||||
max := 512
|
||||
out := make(chan int)
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package webrtc
|
||||
|
||||
// RTCDataChannelInit can be used to configure properties of the underlying
|
||||
// DataChannelInit can be used to configure properties of the underlying
|
||||
// channel such as data reliability.
|
||||
type RTCDataChannelInit struct {
|
||||
type DataChannelInit struct {
|
||||
// Ordered indicates if data is allowed to be delivered out of order. The
|
||||
// default value of true, guarantees that data will be delivered in order.
|
||||
Ordered *bool
|
||||
@@ -23,8 +23,8 @@ type RTCDataChannelInit struct {
|
||||
// Negotiated describes if the data channel is created by the local peer or
|
||||
// the remote peer. The default value of false tells the user agent to
|
||||
// announce the channel in-band and instruct the other peer to dispatch a
|
||||
// corresponding RTCDataChannel. If set to true, it is up to the application
|
||||
// to negotiate the channel and create an RTCDataChannel with the same id
|
||||
// corresponding DataChannel. If set to true, it is up to the application
|
||||
// to negotiate the channel and create an DataChannel with the same id
|
||||
// at the other peer.
|
||||
Negotiated *bool
|
||||
|
||||
@@ -32,5 +32,5 @@ type RTCDataChannelInit struct {
|
||||
ID *uint16
|
||||
|
||||
// Priority describes the priority of this channel.
|
||||
Priority *RTCPriorityType
|
||||
Priority *PriorityType
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package webrtc
|
||||
|
||||
// RTCDataChannelParameters describes the configuration of the RTCDataChannel.
|
||||
type RTCDataChannelParameters struct {
|
||||
// DataChannelParameters describes the configuration of the DataChannel.
|
||||
type DataChannelParameters struct {
|
||||
Label string `json:"label"`
|
||||
ID uint16 `json:"id"`
|
||||
}
|
||||
|
@@ -1,60 +1,60 @@
|
||||
package webrtc
|
||||
|
||||
// RTCDataChannelState indicates the state of a data channel.
|
||||
type RTCDataChannelState int
|
||||
// DataChannelState indicates the state of a data channel.
|
||||
type DataChannelState int
|
||||
|
||||
const (
|
||||
// RTCDataChannelStateConnecting indicates that the data channel is being
|
||||
// established. This is the initial state of RTCDataChannel, whether created
|
||||
// with CreateDataChannel, or dispatched as a part of an RTCDataChannelEvent.
|
||||
RTCDataChannelStateConnecting RTCDataChannelState = iota + 1
|
||||
// DataChannelStateConnecting indicates that the data channel is being
|
||||
// established. This is the initial state of DataChannel, whether created
|
||||
// with CreateDataChannel, or dispatched as a part of an DataChannelEvent.
|
||||
DataChannelStateConnecting DataChannelState = iota + 1
|
||||
|
||||
// RTCDataChannelStateOpen indicates that the underlying data transport is
|
||||
// DataChannelStateOpen indicates that the underlying data transport is
|
||||
// established and communication is possible.
|
||||
RTCDataChannelStateOpen
|
||||
DataChannelStateOpen
|
||||
|
||||
// RTCDataChannelStateClosing indicates that the procedure to close down the
|
||||
// DataChannelStateClosing indicates that the procedure to close down the
|
||||
// underlying data transport has started.
|
||||
RTCDataChannelStateClosing
|
||||
DataChannelStateClosing
|
||||
|
||||
// RTCDataChannelStateClosed indicates that the underlying data transport
|
||||
// DataChannelStateClosed indicates that the underlying data transport
|
||||
// has been closed or could not be established.
|
||||
RTCDataChannelStateClosed
|
||||
DataChannelStateClosed
|
||||
)
|
||||
|
||||
// This is done this way because of a linter.
|
||||
const (
|
||||
rtcDataChannelStateConnectingStr = "connecting"
|
||||
rtcDataChannelStateOpenStr = "open"
|
||||
rtcDataChannelStateClosingStr = "closing"
|
||||
rtcDataChannelStateClosedStr = "closed"
|
||||
dataChannelStateConnectingStr = "connecting"
|
||||
dataChannelStateOpenStr = "open"
|
||||
dataChannelStateClosingStr = "closing"
|
||||
dataChannelStateClosedStr = "closed"
|
||||
)
|
||||
|
||||
func newRTCDataChannelState(raw string) RTCDataChannelState {
|
||||
func newDataChannelState(raw string) DataChannelState {
|
||||
switch raw {
|
||||
case rtcDataChannelStateConnectingStr:
|
||||
return RTCDataChannelStateConnecting
|
||||
case rtcDataChannelStateOpenStr:
|
||||
return RTCDataChannelStateOpen
|
||||
case rtcDataChannelStateClosingStr:
|
||||
return RTCDataChannelStateClosing
|
||||
case rtcDataChannelStateClosedStr:
|
||||
return RTCDataChannelStateClosed
|
||||
case dataChannelStateConnectingStr:
|
||||
return DataChannelStateConnecting
|
||||
case dataChannelStateOpenStr:
|
||||
return DataChannelStateOpen
|
||||
case dataChannelStateClosingStr:
|
||||
return DataChannelStateClosing
|
||||
case dataChannelStateClosedStr:
|
||||
return DataChannelStateClosed
|
||||
default:
|
||||
return RTCDataChannelState(Unknown)
|
||||
return DataChannelState(Unknown)
|
||||
}
|
||||
}
|
||||
|
||||
func (t RTCDataChannelState) String() string {
|
||||
func (t DataChannelState) String() string {
|
||||
switch t {
|
||||
case RTCDataChannelStateConnecting:
|
||||
return rtcDataChannelStateConnectingStr
|
||||
case RTCDataChannelStateOpen:
|
||||
return rtcDataChannelStateOpenStr
|
||||
case RTCDataChannelStateClosing:
|
||||
return rtcDataChannelStateClosingStr
|
||||
case RTCDataChannelStateClosed:
|
||||
return rtcDataChannelStateClosedStr
|
||||
case DataChannelStateConnecting:
|
||||
return dataChannelStateConnectingStr
|
||||
case DataChannelStateOpen:
|
||||
return dataChannelStateOpenStr
|
||||
case DataChannelStateClosing:
|
||||
return dataChannelStateClosingStr
|
||||
case DataChannelStateClosed:
|
||||
return dataChannelStateClosedStr
|
||||
default:
|
||||
return ErrUnknownType.Error()
|
||||
}
|
||||
|
@@ -6,37 +6,37 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewRTCDataChannelState(t *testing.T) {
|
||||
func TestNewDataChannelState(t *testing.T) {
|
||||
testCases := []struct {
|
||||
stateString string
|
||||
expectedState RTCDataChannelState
|
||||
expectedState DataChannelState
|
||||
}{
|
||||
{unknownStr, RTCDataChannelState(Unknown)},
|
||||
{"connecting", RTCDataChannelStateConnecting},
|
||||
{"open", RTCDataChannelStateOpen},
|
||||
{"closing", RTCDataChannelStateClosing},
|
||||
{"closed", RTCDataChannelStateClosed},
|
||||
{unknownStr, DataChannelState(Unknown)},
|
||||
{"connecting", DataChannelStateConnecting},
|
||||
{"open", DataChannelStateOpen},
|
||||
{"closing", DataChannelStateClosing},
|
||||
{"closed", DataChannelStateClosed},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
assert.Equal(t,
|
||||
testCase.expectedState,
|
||||
newRTCDataChannelState(testCase.stateString),
|
||||
newDataChannelState(testCase.stateString),
|
||||
"testCase: %d %v", i, testCase,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRTCDataChannelState_String(t *testing.T) {
|
||||
func TestDataChannelState_String(t *testing.T) {
|
||||
testCases := []struct {
|
||||
state RTCDataChannelState
|
||||
state DataChannelState
|
||||
expectedString string
|
||||
}{
|
||||
{RTCDataChannelState(Unknown), unknownStr},
|
||||
{RTCDataChannelStateConnecting, "connecting"},
|
||||
{RTCDataChannelStateOpen, "open"},
|
||||
{RTCDataChannelStateClosing, "closing"},
|
||||
{RTCDataChannelStateClosed, "closed"},
|
||||
{DataChannelState(Unknown), unknownStr},
|
||||
{DataChannelStateConnecting, "connecting"},
|
||||
{DataChannelStateOpen, "open"},
|
||||
{DataChannelStateClosing, "closing"},
|
||||
{DataChannelStateClosed, "closed"},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package webrtc
|
||||
|
||||
// RTCDtlsFingerprint specifies the hash function algorithm and certificate
|
||||
// DTLSFingerprint specifies the hash function algorithm and certificate
|
||||
// fingerprint as described in https://tools.ietf.org/html/rfc4572.
|
||||
type RTCDtlsFingerprint struct {
|
||||
type DTLSFingerprint struct {
|
||||
// Algorithm specifies one of the the hash function algorithms defined in
|
||||
// the 'Hash function Textual Names' registry.
|
||||
Algorithm string `json:"algorithm"`
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package webrtc
|
||||
|
||||
// RTCDtlsParameters holds information relating to DTLS configuration.
|
||||
type RTCDtlsParameters struct {
|
||||
Role RTCDtlsRole `json:"role"`
|
||||
Fingerprints []RTCDtlsFingerprint `json:"fingerprints"`
|
||||
// DTLSParameters holds information relating to DTLS configuration.
|
||||
type DTLSParameters struct {
|
||||
Role DTLSRole `json:"role"`
|
||||
Fingerprints []DTLSFingerprint `json:"fingerprints"`
|
||||
}
|
||||
|
@@ -1,28 +1,28 @@
|
||||
package webrtc
|
||||
|
||||
// RTCDtlsRole indicates the role of the DTLS transport.
|
||||
type RTCDtlsRole byte
|
||||
// DTLSRole indicates the role of the DTLS transport.
|
||||
type DTLSRole byte
|
||||
|
||||
const (
|
||||
// RTCDtlsRoleAuto defines the DLTS role is determined based on
|
||||
// DTLSRoleAuto defines the DLTS role is determined based on
|
||||
// the resolved ICE role: the ICE controlled role acts as the DTLS
|
||||
// client and the ICE controlling role acts as the DTLS server.
|
||||
RTCDtlsRoleAuto RTCDtlsRole = iota + 1
|
||||
DTLSRoleAuto DTLSRole = iota + 1
|
||||
|
||||
// RTCDtlsRoleClient defines the DTLS client role.
|
||||
RTCDtlsRoleClient
|
||||
// DTLSRoleClient defines the DTLS client role.
|
||||
DTLSRoleClient
|
||||
|
||||
// RTCDtlsRoleServer defines the DTLS server role.
|
||||
RTCDtlsRoleServer
|
||||
// DTLSRoleServer defines the DTLS server role.
|
||||
DTLSRoleServer
|
||||
)
|
||||
|
||||
func (r RTCDtlsRole) String() string {
|
||||
func (r DTLSRole) String() string {
|
||||
switch r {
|
||||
case RTCDtlsRoleAuto:
|
||||
case DTLSRoleAuto:
|
||||
return "auto"
|
||||
case RTCDtlsRoleClient:
|
||||
case DTLSRoleClient:
|
||||
return "client"
|
||||
case RTCDtlsRoleServer:
|
||||
case DTLSRoleServer:
|
||||
return "server"
|
||||
default:
|
||||
return unknownStr
|
||||
|
@@ -6,15 +6,15 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRTCDtlsRole_String(t *testing.T) {
|
||||
func TestDTLSRole_String(t *testing.T) {
|
||||
testCases := []struct {
|
||||
role RTCDtlsRole
|
||||
role DTLSRole
|
||||
expectedString string
|
||||
}{
|
||||
{RTCDtlsRole(Unknown), unknownStr},
|
||||
{RTCDtlsRoleAuto, "auto"},
|
||||
{RTCDtlsRoleClient, "client"},
|
||||
{RTCDtlsRoleServer, "server"},
|
||||
{DTLSRole(Unknown), unknownStr},
|
||||
{DTLSRoleAuto, "auto"},
|
||||
{DTLSRoleClient, "client"},
|
||||
{DTLSRoleServer, "server"},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
|
@@ -17,17 +17,17 @@ import (
|
||||
"github.com/pions/webrtc/pkg/rtcerr"
|
||||
)
|
||||
|
||||
// RTCDtlsTransport allows an application access to information about the DTLS
|
||||
// DTLSTransport allows an application access to information about the DTLS
|
||||
// transport over which RTP and RTCP packets are sent and received by
|
||||
// RTCRtpSender and RTCRtpReceiver, as well other data such as SCTP packets sent
|
||||
// RTPSender and RTPReceiver, as well other data such as SCTP packets sent
|
||||
// and received by data channels.
|
||||
type RTCDtlsTransport struct {
|
||||
type DTLSTransport struct {
|
||||
lock sync.RWMutex
|
||||
|
||||
iceTransport *RTCIceTransport
|
||||
certificates []RTCCertificate
|
||||
remoteParameters RTCDtlsParameters
|
||||
// State RTCDtlsTransportState
|
||||
iceTransport *ICETransport
|
||||
certificates []Certificate
|
||||
remoteParameters DTLSParameters
|
||||
// State DTLSTransportState
|
||||
|
||||
// OnStateChange func()
|
||||
// OnError func()
|
||||
@@ -40,11 +40,11 @@ type RTCDtlsTransport struct {
|
||||
srtcpEndpoint *mux.Endpoint
|
||||
}
|
||||
|
||||
// NewRTCDtlsTransport creates a new RTCDtlsTransport.
|
||||
// NewDTLSTransport creates a new DTLSTransport.
|
||||
// This constructor is part of the ORTC API. It is not
|
||||
// meant to be used together with the basic WebRTC API.
|
||||
func (api *API) NewRTCDtlsTransport(transport *RTCIceTransport, certificates []RTCCertificate) (*RTCDtlsTransport, error) {
|
||||
t := &RTCDtlsTransport{iceTransport: transport}
|
||||
func (api *API) NewDTLSTransport(transport *ICETransport, certificates []Certificate) (*DTLSTransport, error) {
|
||||
t := &DTLSTransport{iceTransport: transport}
|
||||
|
||||
if len(certificates) > 0 {
|
||||
now := time.Now()
|
||||
@@ -63,28 +63,28 @@ func (api *API) NewRTCDtlsTransport(transport *RTCIceTransport, certificates []R
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
t.certificates = []RTCCertificate{*certificate}
|
||||
t.certificates = []Certificate{*certificate}
|
||||
}
|
||||
|
||||
return t, nil
|
||||
}
|
||||
|
||||
// GetLocalParameters returns the DTLS parameters of the local RTCDtlsTransport upon construction.
|
||||
func (t *RTCDtlsTransport) GetLocalParameters() RTCDtlsParameters {
|
||||
fingerprints := []RTCDtlsFingerprint{}
|
||||
// GetLocalParameters returns the DTLS parameters of the local DTLSTransport upon construction.
|
||||
func (t *DTLSTransport) GetLocalParameters() DTLSParameters {
|
||||
fingerprints := []DTLSFingerprint{}
|
||||
|
||||
for _, c := range t.certificates {
|
||||
prints := c.GetFingerprints() // TODO: Should be only one?
|
||||
fingerprints = append(fingerprints, prints...)
|
||||
}
|
||||
|
||||
return RTCDtlsParameters{
|
||||
Role: RTCDtlsRoleAuto, // always returns the default role
|
||||
return DTLSParameters{
|
||||
Role: DTLSRoleAuto, // always returns the default role
|
||||
Fingerprints: fingerprints,
|
||||
}
|
||||
}
|
||||
|
||||
func (t *RTCDtlsTransport) startSRTP() error {
|
||||
func (t *DTLSTransport) startSRTP() error {
|
||||
t.lock.Lock()
|
||||
defer t.lock.Unlock()
|
||||
|
||||
@@ -118,7 +118,7 @@ func (t *RTCDtlsTransport) startSRTP() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *RTCDtlsTransport) getSRTPSession() (*srtp.SessionSRTP, error) {
|
||||
func (t *DTLSTransport) getSRTPSession() (*srtp.SessionSRTP, error) {
|
||||
t.lock.RLock()
|
||||
if t.srtpSession != nil {
|
||||
t.lock.RUnlock()
|
||||
@@ -133,7 +133,7 @@ func (t *RTCDtlsTransport) getSRTPSession() (*srtp.SessionSRTP, error) {
|
||||
return t.srtpSession, nil
|
||||
}
|
||||
|
||||
func (t *RTCDtlsTransport) getSRTCPSession() (*srtp.SessionSRTCP, error) {
|
||||
func (t *DTLSTransport) getSRTCPSession() (*srtp.SessionSRTCP, error) {
|
||||
t.lock.RLock()
|
||||
if t.srtcpSession != nil {
|
||||
t.lock.RUnlock()
|
||||
@@ -148,15 +148,15 @@ func (t *RTCDtlsTransport) getSRTCPSession() (*srtp.SessionSRTCP, error) {
|
||||
return t.srtcpSession, nil
|
||||
}
|
||||
|
||||
func (t *RTCDtlsTransport) isClient() bool {
|
||||
func (t *DTLSTransport) isClient() bool {
|
||||
isClient := true
|
||||
switch t.remoteParameters.Role {
|
||||
case RTCDtlsRoleClient:
|
||||
case DTLSRoleClient:
|
||||
isClient = true
|
||||
case RTCDtlsRoleServer:
|
||||
case DTLSRoleServer:
|
||||
isClient = false
|
||||
default:
|
||||
if t.iceTransport.Role() == RTCIceRoleControlling {
|
||||
if t.iceTransport.Role() == ICERoleControlling {
|
||||
isClient = false
|
||||
}
|
||||
}
|
||||
@@ -165,7 +165,7 @@ func (t *RTCDtlsTransport) isClient() bool {
|
||||
}
|
||||
|
||||
// Start DTLS transport negotiation with the parameters of the remote DTLS transport
|
||||
func (t *RTCDtlsTransport) Start(remoteParameters RTCDtlsParameters) error {
|
||||
func (t *DTLSTransport) Start(remoteParameters DTLSParameters) error {
|
||||
t.lock.Lock()
|
||||
defer t.lock.Unlock()
|
||||
|
||||
@@ -212,8 +212,8 @@ func (t *RTCDtlsTransport) Start(remoteParameters RTCDtlsParameters) error {
|
||||
return t.validateFingerPrint(remoteParameters, remoteCert)
|
||||
}
|
||||
|
||||
// Stop stops and closes the RTCDtlsTransport object.
|
||||
func (t *RTCDtlsTransport) Stop() error {
|
||||
// Stop stops and closes the DTLSTransport object.
|
||||
func (t *DTLSTransport) Stop() error {
|
||||
t.lock.Lock()
|
||||
defer t.lock.Unlock()
|
||||
|
||||
@@ -240,7 +240,7 @@ func (t *RTCDtlsTransport) Stop() error {
|
||||
return flattenErrs(closeErrs)
|
||||
}
|
||||
|
||||
func (t *RTCDtlsTransport) validateFingerPrint(remoteParameters RTCDtlsParameters, remoteCert *x509.Certificate) error {
|
||||
func (t *DTLSTransport) validateFingerPrint(remoteParameters DTLSParameters, remoteCert *x509.Certificate) error {
|
||||
for _, fp := range remoteParameters.Fingerprints {
|
||||
hashAlgo, err := dtls.HashAlgorithmString(fp.Algorithm)
|
||||
if err != nil {
|
||||
@@ -260,7 +260,7 @@ func (t *RTCDtlsTransport) validateFingerPrint(remoteParameters RTCDtlsParameter
|
||||
return errors.New("No matching fingerprint")
|
||||
}
|
||||
|
||||
func (t *RTCDtlsTransport) ensureICEConn() error {
|
||||
func (t *DTLSTransport) ensureICEConn() error {
|
||||
if t.iceTransport == nil ||
|
||||
t.iceTransport.conn == nil ||
|
||||
t.iceTransport.mux == nil {
|
||||
|
@@ -1,70 +1,70 @@
|
||||
package webrtc
|
||||
|
||||
// RTCDtlsTransportState indicates the dtsl transport establishment state.
|
||||
type RTCDtlsTransportState int
|
||||
// DTLSTransportState indicates the dtsl transport establishment state.
|
||||
type DTLSTransportState int
|
||||
|
||||
const (
|
||||
// RTCDtlsTransportStateNew indicates that DTLS has not started negotiating
|
||||
// DTLSTransportStateNew indicates that DTLS has not started negotiating
|
||||
// yet.
|
||||
RTCDtlsTransportStateNew RTCDtlsTransportState = iota + 1
|
||||
DTLSTransportStateNew DTLSTransportState = iota + 1
|
||||
|
||||
// RTCDtlsTransportStateConnecting indicates that DTLS is in the process of
|
||||
// DTLSTransportStateConnecting indicates that DTLS is in the process of
|
||||
// negotiating a secure connection and verifying the remote fingerprint.
|
||||
RTCDtlsTransportStateConnecting
|
||||
DTLSTransportStateConnecting
|
||||
|
||||
// RTCDtlsTransportStateConnected indicates that DTLS has completed
|
||||
// DTLSTransportStateConnected indicates that DTLS has completed
|
||||
// negotiation of a secure connection and verified the remote fingerprint.
|
||||
RTCDtlsTransportStateConnected
|
||||
DTLSTransportStateConnected
|
||||
|
||||
// RTCDtlsTransportStateClosed indicates that the transport has been closed
|
||||
// DTLSTransportStateClosed indicates that the transport has been closed
|
||||
// intentionally as the result of receipt of a close_notify alert, or
|
||||
// calling close().
|
||||
RTCDtlsTransportStateClosed
|
||||
DTLSTransportStateClosed
|
||||
|
||||
// RTCDtlsTransportStateFailed indicates that the transport has failed as
|
||||
// DTLSTransportStateFailed indicates that the transport has failed as
|
||||
// the result of an error (such as receipt of an error alert or failure to
|
||||
// validate the remote fingerprint).
|
||||
RTCDtlsTransportStateFailed
|
||||
DTLSTransportStateFailed
|
||||
)
|
||||
|
||||
// This is done this way because of a linter.
|
||||
const (
|
||||
rtcDtlsTransportStateNewStr = "new"
|
||||
rtcDtlsTransportStateConnectingStr = "connecting"
|
||||
rtcDtlsTransportStateConnectedStr = "connected"
|
||||
rtcDtlsTransportStateClosedStr = "closed"
|
||||
rtcDtlsTransportStateFailedStr = "failed"
|
||||
dtlsTransportStateNewStr = "new"
|
||||
dtlsTransportStateConnectingStr = "connecting"
|
||||
dtlsTransportStateConnectedStr = "connected"
|
||||
dtlsTransportStateClosedStr = "closed"
|
||||
dtlsTransportStateFailedStr = "failed"
|
||||
)
|
||||
|
||||
func newRTCDtlsTransportState(raw string) RTCDtlsTransportState {
|
||||
func newDTLSTransportState(raw string) DTLSTransportState {
|
||||
switch raw {
|
||||
case rtcDtlsTransportStateNewStr:
|
||||
return RTCDtlsTransportStateNew
|
||||
case rtcDtlsTransportStateConnectingStr:
|
||||
return RTCDtlsTransportStateConnecting
|
||||
case rtcDtlsTransportStateConnectedStr:
|
||||
return RTCDtlsTransportStateConnected
|
||||
case rtcDtlsTransportStateClosedStr:
|
||||
return RTCDtlsTransportStateClosed
|
||||
case rtcDtlsTransportStateFailedStr:
|
||||
return RTCDtlsTransportStateFailed
|
||||
case dtlsTransportStateNewStr:
|
||||
return DTLSTransportStateNew
|
||||
case dtlsTransportStateConnectingStr:
|
||||
return DTLSTransportStateConnecting
|
||||
case dtlsTransportStateConnectedStr:
|
||||
return DTLSTransportStateConnected
|
||||
case dtlsTransportStateClosedStr:
|
||||
return DTLSTransportStateClosed
|
||||
case dtlsTransportStateFailedStr:
|
||||
return DTLSTransportStateFailed
|
||||
default:
|
||||
return RTCDtlsTransportState(Unknown)
|
||||
return DTLSTransportState(Unknown)
|
||||
}
|
||||
}
|
||||
|
||||
func (t RTCDtlsTransportState) String() string {
|
||||
func (t DTLSTransportState) String() string {
|
||||
switch t {
|
||||
case RTCDtlsTransportStateNew:
|
||||
return rtcDtlsTransportStateNewStr
|
||||
case RTCDtlsTransportStateConnecting:
|
||||
return rtcDtlsTransportStateConnectingStr
|
||||
case RTCDtlsTransportStateConnected:
|
||||
return rtcDtlsTransportStateConnectedStr
|
||||
case RTCDtlsTransportStateClosed:
|
||||
return rtcDtlsTransportStateClosedStr
|
||||
case RTCDtlsTransportStateFailed:
|
||||
return rtcDtlsTransportStateFailedStr
|
||||
case DTLSTransportStateNew:
|
||||
return dtlsTransportStateNewStr
|
||||
case DTLSTransportStateConnecting:
|
||||
return dtlsTransportStateConnectingStr
|
||||
case DTLSTransportStateConnected:
|
||||
return dtlsTransportStateConnectedStr
|
||||
case DTLSTransportStateClosed:
|
||||
return dtlsTransportStateClosedStr
|
||||
case DTLSTransportStateFailed:
|
||||
return dtlsTransportStateFailedStr
|
||||
default:
|
||||
return ErrUnknownType.Error()
|
||||
}
|
||||
|
@@ -6,39 +6,39 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewRTCDtlsTransportState(t *testing.T) {
|
||||
func TestNewDTLSTransportState(t *testing.T) {
|
||||
testCases := []struct {
|
||||
stateString string
|
||||
expectedState RTCDtlsTransportState
|
||||
expectedState DTLSTransportState
|
||||
}{
|
||||
{unknownStr, RTCDtlsTransportState(Unknown)},
|
||||
{"new", RTCDtlsTransportStateNew},
|
||||
{"connecting", RTCDtlsTransportStateConnecting},
|
||||
{"connected", RTCDtlsTransportStateConnected},
|
||||
{"closed", RTCDtlsTransportStateClosed},
|
||||
{"failed", RTCDtlsTransportStateFailed},
|
||||
{unknownStr, DTLSTransportState(Unknown)},
|
||||
{"new", DTLSTransportStateNew},
|
||||
{"connecting", DTLSTransportStateConnecting},
|
||||
{"connected", DTLSTransportStateConnected},
|
||||
{"closed", DTLSTransportStateClosed},
|
||||
{"failed", DTLSTransportStateFailed},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
assert.Equal(t,
|
||||
testCase.expectedState,
|
||||
newRTCDtlsTransportState(testCase.stateString),
|
||||
newDTLSTransportState(testCase.stateString),
|
||||
"testCase: %d %v", i, testCase,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRTCDtlsTransportState_String(t *testing.T) {
|
||||
func TestDTLSTransportState_String(t *testing.T) {
|
||||
testCases := []struct {
|
||||
state RTCDtlsTransportState
|
||||
state DTLSTransportState
|
||||
expectedString string
|
||||
}{
|
||||
{RTCDtlsTransportState(Unknown), unknownStr},
|
||||
{RTCDtlsTransportStateNew, "new"},
|
||||
{RTCDtlsTransportStateConnecting, "connecting"},
|
||||
{RTCDtlsTransportStateConnected, "connected"},
|
||||
{RTCDtlsTransportStateClosed, "closed"},
|
||||
{RTCDtlsTransportStateFailed, "failed"},
|
||||
{DTLSTransportState(Unknown), unknownStr},
|
||||
{DTLSTransportStateNew, "new"},
|
||||
{DTLSTransportStateConnecting, "connecting"},
|
||||
{DTLSTransportStateConnected, "connected"},
|
||||
{DTLSTransportStateClosed, "closed"},
|
||||
{DTLSTransportStateFailed, "failed"},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
|
@@ -9,14 +9,14 @@ import (
|
||||
"github.com/pions/webrtc/pkg/ice"
|
||||
)
|
||||
|
||||
// RTCIceCandidate represents a ice candidate
|
||||
type RTCIceCandidate struct {
|
||||
// ICECandidate represents a ice candidate
|
||||
type ICECandidate struct {
|
||||
Foundation string `json:"foundation"`
|
||||
Priority uint32 `json:"priority"`
|
||||
IP string `json:"ip"`
|
||||
Protocol RTCIceProtocol `json:"protocol"`
|
||||
Protocol ICEProtocol `json:"protocol"`
|
||||
Port uint16 `json:"port"`
|
||||
Typ RTCIceCandidateType `json:"type"`
|
||||
Typ ICECandidateType `json:"type"`
|
||||
Component uint16 `json:"component"`
|
||||
RelatedAddress string `json:"relatedAddress"`
|
||||
RelatedPort uint16 `json:"relatedPort"`
|
||||
@@ -24,16 +24,16 @@ type RTCIceCandidate struct {
|
||||
|
||||
// Conversion for package sdp
|
||||
|
||||
func newRTCIceCandidateFromSDP(c sdp.ICECandidate) (RTCIceCandidate, error) {
|
||||
typ, err := newRTCIceCandidateType(c.Typ)
|
||||
func newICECandidateFromSDP(c sdp.ICECandidate) (ICECandidate, error) {
|
||||
typ, err := newICECandidateType(c.Typ)
|
||||
if err != nil {
|
||||
return RTCIceCandidate{}, err
|
||||
return ICECandidate{}, err
|
||||
}
|
||||
protocol, err := newRTCIceProtocol(c.Protocol)
|
||||
protocol, err := newICEProtocol(c.Protocol)
|
||||
if err != nil {
|
||||
return RTCIceCandidate{}, err
|
||||
return ICECandidate{}, err
|
||||
}
|
||||
return RTCIceCandidate{
|
||||
return ICECandidate{
|
||||
Foundation: c.Foundation,
|
||||
Priority: c.Priority,
|
||||
IP: c.IP,
|
||||
@@ -46,7 +46,7 @@ func newRTCIceCandidateFromSDP(c sdp.ICECandidate) (RTCIceCandidate, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c RTCIceCandidate) toSDP() sdp.ICECandidate {
|
||||
func (c ICECandidate) toSDP() sdp.ICECandidate {
|
||||
return sdp.ICECandidate{
|
||||
Foundation: c.Foundation,
|
||||
Priority: c.Priority,
|
||||
@@ -62,11 +62,11 @@ func (c RTCIceCandidate) toSDP() sdp.ICECandidate {
|
||||
|
||||
// Conversion for package ice
|
||||
|
||||
func newRTCIceCandidatesFromICE(iceCandidates []*ice.Candidate) ([]RTCIceCandidate, error) {
|
||||
candidates := []RTCIceCandidate{}
|
||||
func newICECandidatesFromICE(iceCandidates []*ice.Candidate) ([]ICECandidate, error) {
|
||||
candidates := []ICECandidate{}
|
||||
|
||||
for _, i := range iceCandidates {
|
||||
c, err := newRTCIceCandidateFromICE(i)
|
||||
c, err := newICECandidateFromICE(i)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -76,17 +76,17 @@ func newRTCIceCandidatesFromICE(iceCandidates []*ice.Candidate) ([]RTCIceCandida
|
||||
return candidates, nil
|
||||
}
|
||||
|
||||
func newRTCIceCandidateFromICE(i *ice.Candidate) (RTCIceCandidate, error) {
|
||||
func newICECandidateFromICE(i *ice.Candidate) (ICECandidate, error) {
|
||||
typ, err := convertTypeFromICE(i.Type)
|
||||
if err != nil {
|
||||
return RTCIceCandidate{}, err
|
||||
return ICECandidate{}, err
|
||||
}
|
||||
protocol, err := newRTCIceProtocol(i.NetworkType.NetworkShort())
|
||||
protocol, err := newICEProtocol(i.NetworkType.NetworkShort())
|
||||
if err != nil {
|
||||
return RTCIceCandidate{}, err
|
||||
return ICECandidate{}, err
|
||||
}
|
||||
|
||||
c := RTCIceCandidate{
|
||||
c := ICECandidate{
|
||||
Foundation: "foundation",
|
||||
Priority: uint32(i.Priority()),
|
||||
IP: i.IP.String(),
|
||||
@@ -104,22 +104,22 @@ func newRTCIceCandidateFromICE(i *ice.Candidate) (RTCIceCandidate, error) {
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func (c RTCIceCandidate) toICE() (*ice.Candidate, error) {
|
||||
func (c ICECandidate) toICE() (*ice.Candidate, error) {
|
||||
ip := net.ParseIP(c.IP)
|
||||
if ip == nil {
|
||||
return nil, errors.New("Failed to parse IP address")
|
||||
}
|
||||
|
||||
switch c.Typ {
|
||||
case RTCIceCandidateTypeHost:
|
||||
case ICECandidateTypeHost:
|
||||
return ice.NewCandidateHost(c.Protocol.String(), ip, int(c.Port), c.Component)
|
||||
case RTCIceCandidateTypeSrflx:
|
||||
case ICECandidateTypeSrflx:
|
||||
return ice.NewCandidateServerReflexive(c.Protocol.String(), ip, int(c.Port), c.Component,
|
||||
c.RelatedAddress, int(c.RelatedPort))
|
||||
case RTCIceCandidateTypePrflx:
|
||||
case ICECandidateTypePrflx:
|
||||
return ice.NewCandidatePeerReflexive(c.Protocol.String(), ip, int(c.Port), c.Component,
|
||||
c.RelatedAddress, int(c.RelatedPort))
|
||||
case RTCIceCandidateTypeRelay:
|
||||
case ICECandidateTypeRelay:
|
||||
return ice.NewCandidateRelay(c.Protocol.String(), ip, int(c.Port), c.Component,
|
||||
c.RelatedAddress, int(c.RelatedPort))
|
||||
default:
|
||||
@@ -127,17 +127,17 @@ func (c RTCIceCandidate) toICE() (*ice.Candidate, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func convertTypeFromICE(t ice.CandidateType) (RTCIceCandidateType, error) {
|
||||
func convertTypeFromICE(t ice.CandidateType) (ICECandidateType, error) {
|
||||
switch t {
|
||||
case ice.CandidateTypeHost:
|
||||
return RTCIceCandidateTypeHost, nil
|
||||
return ICECandidateTypeHost, nil
|
||||
case ice.CandidateTypeServerReflexive:
|
||||
return RTCIceCandidateTypeSrflx, nil
|
||||
return ICECandidateTypeSrflx, nil
|
||||
case ice.CandidateTypePeerReflexive:
|
||||
return RTCIceCandidateTypePrflx, nil
|
||||
return ICECandidateTypePrflx, nil
|
||||
case ice.CandidateTypeRelay:
|
||||
return RTCIceCandidateTypeRelay, nil
|
||||
return ICECandidateTypeRelay, nil
|
||||
default:
|
||||
return RTCIceCandidateType(t), fmt.Errorf("Unknown ICE candidate type: %s", t)
|
||||
return ICECandidateType(t), fmt.Errorf("Unknown ICE candidate type: %s", t)
|
||||
}
|
||||
}
|
||||
|
@@ -9,20 +9,20 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRTCIceCandidate_Convert(t *testing.T) {
|
||||
func TestICECandidate_Convert(t *testing.T) {
|
||||
testCases := []struct {
|
||||
native RTCIceCandidate
|
||||
native ICECandidate
|
||||
ice *ice.Candidate
|
||||
sdp sdp.ICECandidate
|
||||
}{
|
||||
{
|
||||
RTCIceCandidate{
|
||||
ICECandidate{
|
||||
Foundation: "foundation",
|
||||
Priority: 128,
|
||||
IP: "1.0.0.1",
|
||||
Protocol: RTCIceProtocolUDP,
|
||||
Protocol: ICEProtocolUDP,
|
||||
Port: 1234,
|
||||
Typ: RTCIceCandidateTypeHost,
|
||||
Typ: ICECandidateTypeHost,
|
||||
Component: 1,
|
||||
}, &ice.Candidate{
|
||||
IP: net.ParseIP("1.0.0.1"),
|
||||
@@ -43,13 +43,13 @@ func TestRTCIceCandidate_Convert(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
RTCIceCandidate{
|
||||
ICECandidate{
|
||||
Foundation: "foundation",
|
||||
Priority: 128,
|
||||
IP: "::1",
|
||||
Protocol: RTCIceProtocolUDP,
|
||||
Protocol: ICEProtocolUDP,
|
||||
Port: 1234,
|
||||
Typ: RTCIceCandidateTypeSrflx,
|
||||
Typ: ICECandidateTypeSrflx,
|
||||
Component: 1,
|
||||
RelatedAddress: "1.0.0.1",
|
||||
RelatedPort: 4321,
|
||||
@@ -78,13 +78,13 @@ func TestRTCIceCandidate_Convert(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
RTCIceCandidate{
|
||||
ICECandidate{
|
||||
Foundation: "foundation",
|
||||
Priority: 128,
|
||||
IP: "::1",
|
||||
Protocol: RTCIceProtocolUDP,
|
||||
Protocol: ICEProtocolUDP,
|
||||
Port: 1234,
|
||||
Typ: RTCIceCandidateTypePrflx,
|
||||
Typ: ICECandidateTypePrflx,
|
||||
Component: 1,
|
||||
RelatedAddress: "1.0.0.1",
|
||||
RelatedPort: 4321,
|
||||
@@ -137,8 +137,8 @@ func TestConvertTypeFromICE(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal("failed coverting ice.CandidateTypeHost")
|
||||
}
|
||||
if ct != RTCIceCandidateTypeHost {
|
||||
t.Fatal("should be coverted to RTCIceCandidateTypeHost")
|
||||
if ct != ICECandidateTypeHost {
|
||||
t.Fatal("should be coverted to ICECandidateTypeHost")
|
||||
}
|
||||
})
|
||||
t.Run("srflx", func(t *testing.T) {
|
||||
@@ -146,8 +146,8 @@ func TestConvertTypeFromICE(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal("failed coverting ice.CandidateTypeServerReflexive")
|
||||
}
|
||||
if ct != RTCIceCandidateTypeSrflx {
|
||||
t.Fatal("should be coverted to RTCIceCandidateTypeSrflx")
|
||||
if ct != ICECandidateTypeSrflx {
|
||||
t.Fatal("should be coverted to ICECandidateTypeSrflx")
|
||||
}
|
||||
})
|
||||
t.Run("prflx", func(t *testing.T) {
|
||||
@@ -155,8 +155,8 @@ func TestConvertTypeFromICE(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal("failed coverting ice.CandidateTypePeerReflexive")
|
||||
}
|
||||
if ct != RTCIceCandidateTypePrflx {
|
||||
t.Fatal("should be coverted to RTCIceCandidateTypePrflx")
|
||||
if ct != ICECandidateTypePrflx {
|
||||
t.Fatal("should be coverted to ICECandidateTypePrflx")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@@ -2,70 +2,70 @@ package webrtc
|
||||
|
||||
import "fmt"
|
||||
|
||||
// RTCIceCandidateType represents the type of the ICE candidate used.
|
||||
type RTCIceCandidateType int
|
||||
// ICECandidateType represents the type of the ICE candidate used.
|
||||
type ICECandidateType int
|
||||
|
||||
const (
|
||||
// RTCIceCandidateTypeHost indicates that the candidate is of Host type as
|
||||
// ICECandidateTypeHost indicates that the candidate is of Host type as
|
||||
// described in https://tools.ietf.org/html/rfc8445#section-5.1.1.1. A
|
||||
// candidate obtained by binding to a specific port from an IP address on
|
||||
// the host. This includes IP addresses on physical interfaces and logical
|
||||
// ones, such as ones obtained through VPNs.
|
||||
RTCIceCandidateTypeHost RTCIceCandidateType = iota + 1
|
||||
ICECandidateTypeHost ICECandidateType = iota + 1
|
||||
|
||||
// RTCIceCandidateTypeSrflx indicates the the candidate is of Server
|
||||
// ICECandidateTypeSrflx indicates the the candidate is of Server
|
||||
// Reflexive type as described
|
||||
// https://tools.ietf.org/html/rfc8445#section-5.1.1.2. A candidate type
|
||||
// whose IP address and port are a binding allocated by a NAT for an ICE
|
||||
// agent after it sends a packet through the NAT to a server, such as a
|
||||
// STUN server.
|
||||
RTCIceCandidateTypeSrflx
|
||||
ICECandidateTypeSrflx
|
||||
|
||||
// RTCIceCandidateTypePrflx indicates that the candidate is of Peer
|
||||
// ICECandidateTypePrflx indicates that the candidate is of Peer
|
||||
// Reflexive type. A candidate type whose IP address and port are a binding
|
||||
// allocated by a NAT for an ICE agent after it sends a packet through the
|
||||
// NAT to its peer.
|
||||
RTCIceCandidateTypePrflx
|
||||
ICECandidateTypePrflx
|
||||
|
||||
// RTCIceCandidateTypeRelay indicates the the candidate is of Relay type as
|
||||
// ICECandidateTypeRelay indicates the the candidate is of Relay type as
|
||||
// described in https://tools.ietf.org/html/rfc8445#section-5.1.1.2. A
|
||||
// candidate type obtained from a relay server, such as a TURN server.
|
||||
RTCIceCandidateTypeRelay
|
||||
ICECandidateTypeRelay
|
||||
)
|
||||
|
||||
// This is done this way because of a linter.
|
||||
const (
|
||||
rtcIceCandidateTypeHostStr = "host"
|
||||
rtcIceCandidateTypeSrflxStr = "srflx"
|
||||
rtcIceCandidateTypePrflxStr = "prflx"
|
||||
rtcIceCandidateTypeRelayStr = "relay"
|
||||
iceCandidateTypeHostStr = "host"
|
||||
iceCandidateTypeSrflxStr = "srflx"
|
||||
iceCandidateTypePrflxStr = "prflx"
|
||||
iceCandidateTypeRelayStr = "relay"
|
||||
)
|
||||
|
||||
func newRTCIceCandidateType(raw string) (RTCIceCandidateType, error) {
|
||||
func newICECandidateType(raw string) (ICECandidateType, error) {
|
||||
switch raw {
|
||||
case rtcIceCandidateTypeHostStr:
|
||||
return RTCIceCandidateTypeHost, nil
|
||||
case rtcIceCandidateTypeSrflxStr:
|
||||
return RTCIceCandidateTypeSrflx, nil
|
||||
case rtcIceCandidateTypePrflxStr:
|
||||
return RTCIceCandidateTypePrflx, nil
|
||||
case rtcIceCandidateTypeRelayStr:
|
||||
return RTCIceCandidateTypeRelay, nil
|
||||
case iceCandidateTypeHostStr:
|
||||
return ICECandidateTypeHost, nil
|
||||
case iceCandidateTypeSrflxStr:
|
||||
return ICECandidateTypeSrflx, nil
|
||||
case iceCandidateTypePrflxStr:
|
||||
return ICECandidateTypePrflx, nil
|
||||
case iceCandidateTypeRelayStr:
|
||||
return ICECandidateTypeRelay, nil
|
||||
default:
|
||||
return RTCIceCandidateType(Unknown), fmt.Errorf("Unknown ICE candidate type: %s", raw)
|
||||
return ICECandidateType(Unknown), fmt.Errorf("Unknown ICE candidate type: %s", raw)
|
||||
}
|
||||
}
|
||||
|
||||
func (t RTCIceCandidateType) String() string {
|
||||
func (t ICECandidateType) String() string {
|
||||
switch t {
|
||||
case RTCIceCandidateTypeHost:
|
||||
return rtcIceCandidateTypeHostStr
|
||||
case RTCIceCandidateTypeSrflx:
|
||||
return rtcIceCandidateTypeSrflxStr
|
||||
case RTCIceCandidateTypePrflx:
|
||||
return rtcIceCandidateTypePrflxStr
|
||||
case RTCIceCandidateTypeRelay:
|
||||
return rtcIceCandidateTypeRelayStr
|
||||
case ICECandidateTypeHost:
|
||||
return iceCandidateTypeHostStr
|
||||
case ICECandidateTypeSrflx:
|
||||
return iceCandidateTypeSrflxStr
|
||||
case ICECandidateTypePrflx:
|
||||
return iceCandidateTypePrflxStr
|
||||
case ICECandidateTypeRelay:
|
||||
return iceCandidateTypeRelayStr
|
||||
default:
|
||||
return ErrUnknownType.Error()
|
||||
}
|
||||
|
@@ -6,21 +6,21 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRTCIceCandidateType(t *testing.T) {
|
||||
func TestICECandidateType(t *testing.T) {
|
||||
testCases := []struct {
|
||||
typeString string
|
||||
shouldFail bool
|
||||
expectedType RTCIceCandidateType
|
||||
expectedType ICECandidateType
|
||||
}{
|
||||
{unknownStr, true, RTCIceCandidateType(Unknown)},
|
||||
{"host", false, RTCIceCandidateTypeHost},
|
||||
{"srflx", false, RTCIceCandidateTypeSrflx},
|
||||
{"prflx", false, RTCIceCandidateTypePrflx},
|
||||
{"relay", false, RTCIceCandidateTypeRelay},
|
||||
{unknownStr, true, ICECandidateType(Unknown)},
|
||||
{"host", false, ICECandidateTypeHost},
|
||||
{"srflx", false, ICECandidateTypeSrflx},
|
||||
{"prflx", false, ICECandidateTypePrflx},
|
||||
{"relay", false, ICECandidateTypeRelay},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
actual, err := newRTCIceCandidateType(testCase.typeString)
|
||||
actual, err := newICECandidateType(testCase.typeString)
|
||||
if (err != nil) != testCase.shouldFail {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -32,16 +32,16 @@ func TestRTCIceCandidateType(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRTCIceCandidateType_String(t *testing.T) {
|
||||
func TestICECandidateType_String(t *testing.T) {
|
||||
testCases := []struct {
|
||||
cType RTCIceCandidateType
|
||||
cType ICECandidateType
|
||||
expectedString string
|
||||
}{
|
||||
{RTCIceCandidateType(Unknown), unknownStr},
|
||||
{RTCIceCandidateTypeHost, "host"},
|
||||
{RTCIceCandidateTypeSrflx, "srflx"},
|
||||
{RTCIceCandidateTypePrflx, "prflx"},
|
||||
{RTCIceCandidateTypeRelay, "relay"},
|
||||
{ICECandidateType(Unknown), unknownStr},
|
||||
{ICECandidateTypeHost, "host"},
|
||||
{ICECandidateTypeSrflx, "srflx"},
|
||||
{ICECandidateTypePrflx, "prflx"},
|
||||
{ICECandidateTypeRelay, "relay"},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
|
@@ -1,46 +1,46 @@
|
||||
package webrtc
|
||||
|
||||
// RTCIceComponent describes if the ice transport is used for RTP
|
||||
// ICEComponent describes if the ice transport is used for RTP
|
||||
// (or RTCP multiplexing).
|
||||
type RTCIceComponent int
|
||||
type ICEComponent int
|
||||
|
||||
const (
|
||||
// RTCIceComponentRtp indicates that the ICE Transport is used for RTP (or
|
||||
// ICEComponentRTP indicates that the ICE Transport is used for RTP (or
|
||||
// RTCP multiplexing), as defined in
|
||||
// https://tools.ietf.org/html/rfc5245#section-4.1.1.1. Protocols
|
||||
// multiplexed with RTP (e.g. data channel) share its component ID. This
|
||||
// represents the component-id value 1 when encoded in candidate-attribute.
|
||||
RTCIceComponentRtp RTCIceComponent = iota + 1
|
||||
ICEComponentRTP ICEComponent = iota + 1
|
||||
|
||||
// RTCIceComponentRtcp indicates that the ICE Transport is used for RTCP as
|
||||
// ICEComponentRTCP indicates that the ICE Transport is used for RTCP as
|
||||
// defined by https://tools.ietf.org/html/rfc5245#section-4.1.1.1. This
|
||||
// represents the component-id value 2 when encoded in candidate-attribute.
|
||||
RTCIceComponentRtcp
|
||||
ICEComponentRTCP
|
||||
)
|
||||
|
||||
// This is done this way because of a linter.
|
||||
const (
|
||||
rtcIceComponentRtpStr = "rtp"
|
||||
rtcIceComponentRtcpStr = "rtcp"
|
||||
iceComponentRTPStr = "rtp"
|
||||
iceComponentRTCPStr = "rtcp"
|
||||
)
|
||||
|
||||
func newRTCIceComponent(raw string) RTCIceComponent {
|
||||
func newICEComponent(raw string) ICEComponent {
|
||||
switch raw {
|
||||
case rtcIceComponentRtpStr:
|
||||
return RTCIceComponentRtp
|
||||
case rtcIceComponentRtcpStr:
|
||||
return RTCIceComponentRtcp
|
||||
case iceComponentRTPStr:
|
||||
return ICEComponentRTP
|
||||
case iceComponentRTCPStr:
|
||||
return ICEComponentRTCP
|
||||
default:
|
||||
return RTCIceComponent(Unknown)
|
||||
return ICEComponent(Unknown)
|
||||
}
|
||||
}
|
||||
|
||||
func (t RTCIceComponent) String() string {
|
||||
func (t ICEComponent) String() string {
|
||||
switch t {
|
||||
case RTCIceComponentRtp:
|
||||
return rtcIceComponentRtpStr
|
||||
case RTCIceComponentRtcp:
|
||||
return rtcIceComponentRtcpStr
|
||||
case ICEComponentRTP:
|
||||
return iceComponentRTPStr
|
||||
case ICEComponentRTCP:
|
||||
return iceComponentRTCPStr
|
||||
default:
|
||||
return ErrUnknownType.Error()
|
||||
}
|
||||
|
@@ -6,33 +6,33 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRTCIceComponent(t *testing.T) {
|
||||
func TestICEComponent(t *testing.T) {
|
||||
testCases := []struct {
|
||||
componentString string
|
||||
expectedComponent RTCIceComponent
|
||||
expectedComponent ICEComponent
|
||||
}{
|
||||
{unknownStr, RTCIceComponent(Unknown)},
|
||||
{"rtp", RTCIceComponentRtp},
|
||||
{"rtcp", RTCIceComponentRtcp},
|
||||
{unknownStr, ICEComponent(Unknown)},
|
||||
{"rtp", ICEComponentRTP},
|
||||
{"rtcp", ICEComponentRTCP},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
assert.Equal(t,
|
||||
newRTCIceComponent(testCase.componentString),
|
||||
newICEComponent(testCase.componentString),
|
||||
testCase.expectedComponent,
|
||||
"testCase: %d %v", i, testCase,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRTCIceComponent_String(t *testing.T) {
|
||||
func TestICEComponent_String(t *testing.T) {
|
||||
testCases := []struct {
|
||||
state RTCIceComponent
|
||||
state ICEComponent
|
||||
expectedString string
|
||||
}{
|
||||
{RTCIceComponent(Unknown), unknownStr},
|
||||
{RTCIceComponentRtp, "rtp"},
|
||||
{RTCIceComponentRtcp, "rtcp"},
|
||||
{ICEComponent(Unknown), unknownStr},
|
||||
{ICEComponentRTP, "rtp"},
|
||||
{ICEComponentRTCP, "rtcp"},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
|
@@ -1,92 +1,92 @@
|
||||
package webrtc
|
||||
|
||||
// RTCIceConnectionState indicates signaling state of the Ice Connection.
|
||||
type RTCIceConnectionState int
|
||||
// ICEConnectionState indicates signaling state of the ICE Connection.
|
||||
type ICEConnectionState int
|
||||
|
||||
const (
|
||||
// RTCIceConnectionStateNew indicates that any of the RTCIceTransports are
|
||||
// ICEConnectionStateNew indicates that any of the ICETransports are
|
||||
// in the "new" state and none of them are in the "checking", "disconnected"
|
||||
// or "failed" state, or all RTCIceTransports are in the "closed" state, or
|
||||
// or "failed" state, or all ICETransports are in the "closed" state, or
|
||||
// there are no transports.
|
||||
RTCIceConnectionStateNew RTCIceConnectionState = iota + 1
|
||||
ICEConnectionStateNew ICEConnectionState = iota + 1
|
||||
|
||||
// RTCIceConnectionStateChecking indicates that any of the RTCIceTransports
|
||||
// ICEConnectionStateChecking indicates that any of the ICETransports
|
||||
// are in the "checking" state and none of them are in the "disconnected"
|
||||
// or "failed" state.
|
||||
RTCIceConnectionStateChecking
|
||||
ICEConnectionStateChecking
|
||||
|
||||
// RTCIceConnectionStateConnected indicates that all RTCIceTransports are
|
||||
// ICEConnectionStateConnected indicates that all ICETransports are
|
||||
// in the "connected", "completed" or "closed" state and at least one of
|
||||
// them is in the "connected" state.
|
||||
RTCIceConnectionStateConnected
|
||||
ICEConnectionStateConnected
|
||||
|
||||
// RTCIceConnectionStateCompleted indicates that all RTCIceTransports are
|
||||
// ICEConnectionStateCompleted indicates that all ICETransports are
|
||||
// in the "completed" or "closed" state and at least one of them is in the
|
||||
// "completed" state.
|
||||
RTCIceConnectionStateCompleted
|
||||
ICEConnectionStateCompleted
|
||||
|
||||
// RTCIceConnectionStateDisconnected indicates that any of the
|
||||
// RTCIceTransports are in the "disconnected" state and none of them are
|
||||
// ICEConnectionStateDisconnected indicates that any of the
|
||||
// ICETransports are in the "disconnected" state and none of them are
|
||||
// in the "failed" state.
|
||||
RTCIceConnectionStateDisconnected
|
||||
ICEConnectionStateDisconnected
|
||||
|
||||
// RTCIceConnectionStateFailed indicates that any of the RTCIceTransports
|
||||
// ICEConnectionStateFailed indicates that any of the ICETransports
|
||||
// are in the "failed" state.
|
||||
RTCIceConnectionStateFailed
|
||||
ICEConnectionStateFailed
|
||||
|
||||
// RTCIceConnectionStateClosed indicates that the RTCPeerConnection's
|
||||
// ICEConnectionStateClosed indicates that the PeerConnection's
|
||||
// isClosed is true.
|
||||
RTCIceConnectionStateClosed
|
||||
ICEConnectionStateClosed
|
||||
)
|
||||
|
||||
// This is done this way because of a linter.
|
||||
const (
|
||||
rtcIceConnectionStateNewStr = "new"
|
||||
rtcIceConnectionStateCheckingStr = "checking"
|
||||
rtcIceConnectionStateConnectedStr = "connected"
|
||||
rtcIceConnectionStateCompletedStr = "completed"
|
||||
rtcIceConnectionStateDisconnectedStr = "disconnected"
|
||||
rtcIceConnectionStateFailedStr = "failed"
|
||||
rtcIceConnectionStateClosedStr = "closed"
|
||||
iceConnectionStateNewStr = "new"
|
||||
iceConnectionStateCheckingStr = "checking"
|
||||
iceConnectionStateConnectedStr = "connected"
|
||||
iceConnectionStateCompletedStr = "completed"
|
||||
iceConnectionStateDisconnectedStr = "disconnected"
|
||||
iceConnectionStateFailedStr = "failed"
|
||||
iceConnectionStateClosedStr = "closed"
|
||||
)
|
||||
|
||||
func newRTCIceConnectionState(raw string) RTCIceConnectionState {
|
||||
func newICEConnectionState(raw string) ICEConnectionState {
|
||||
switch raw {
|
||||
case rtcIceConnectionStateNewStr:
|
||||
return RTCIceConnectionStateNew
|
||||
case rtcIceConnectionStateCheckingStr:
|
||||
return RTCIceConnectionStateChecking
|
||||
case rtcIceConnectionStateConnectedStr:
|
||||
return RTCIceConnectionStateConnected
|
||||
case rtcIceConnectionStateCompletedStr:
|
||||
return RTCIceConnectionStateCompleted
|
||||
case rtcIceConnectionStateDisconnectedStr:
|
||||
return RTCIceConnectionStateDisconnected
|
||||
case rtcIceConnectionStateFailedStr:
|
||||
return RTCIceConnectionStateFailed
|
||||
case rtcIceConnectionStateClosedStr:
|
||||
return RTCIceConnectionStateClosed
|
||||
case iceConnectionStateNewStr:
|
||||
return ICEConnectionStateNew
|
||||
case iceConnectionStateCheckingStr:
|
||||
return ICEConnectionStateChecking
|
||||
case iceConnectionStateConnectedStr:
|
||||
return ICEConnectionStateConnected
|
||||
case iceConnectionStateCompletedStr:
|
||||
return ICEConnectionStateCompleted
|
||||
case iceConnectionStateDisconnectedStr:
|
||||
return ICEConnectionStateDisconnected
|
||||
case iceConnectionStateFailedStr:
|
||||
return ICEConnectionStateFailed
|
||||
case iceConnectionStateClosedStr:
|
||||
return ICEConnectionStateClosed
|
||||
default:
|
||||
return RTCIceConnectionState(Unknown)
|
||||
return ICEConnectionState(Unknown)
|
||||
}
|
||||
}
|
||||
|
||||
func (c RTCIceConnectionState) String() string {
|
||||
func (c ICEConnectionState) String() string {
|
||||
switch c {
|
||||
case RTCIceConnectionStateNew:
|
||||
return rtcIceConnectionStateNewStr
|
||||
case RTCIceConnectionStateChecking:
|
||||
return rtcIceConnectionStateCheckingStr
|
||||
case RTCIceConnectionStateConnected:
|
||||
return rtcIceConnectionStateConnectedStr
|
||||
case RTCIceConnectionStateCompleted:
|
||||
return rtcIceConnectionStateCompletedStr
|
||||
case RTCIceConnectionStateDisconnected:
|
||||
return rtcIceConnectionStateDisconnectedStr
|
||||
case RTCIceConnectionStateFailed:
|
||||
return rtcIceConnectionStateFailedStr
|
||||
case RTCIceConnectionStateClosed:
|
||||
return rtcIceConnectionStateClosedStr
|
||||
case ICEConnectionStateNew:
|
||||
return iceConnectionStateNewStr
|
||||
case ICEConnectionStateChecking:
|
||||
return iceConnectionStateCheckingStr
|
||||
case ICEConnectionStateConnected:
|
||||
return iceConnectionStateConnectedStr
|
||||
case ICEConnectionStateCompleted:
|
||||
return iceConnectionStateCompletedStr
|
||||
case ICEConnectionStateDisconnected:
|
||||
return iceConnectionStateDisconnectedStr
|
||||
case ICEConnectionStateFailed:
|
||||
return iceConnectionStateFailedStr
|
||||
case ICEConnectionStateClosed:
|
||||
return iceConnectionStateClosedStr
|
||||
default:
|
||||
return ErrUnknownType.Error()
|
||||
}
|
||||
|
@@ -6,43 +6,43 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewRTCIceConnectionState(t *testing.T) {
|
||||
func TestNewICEConnectionState(t *testing.T) {
|
||||
testCases := []struct {
|
||||
stateString string
|
||||
expectedState RTCIceConnectionState
|
||||
expectedState ICEConnectionState
|
||||
}{
|
||||
{unknownStr, RTCIceConnectionState(Unknown)},
|
||||
{"new", RTCIceConnectionStateNew},
|
||||
{"checking", RTCIceConnectionStateChecking},
|
||||
{"connected", RTCIceConnectionStateConnected},
|
||||
{"completed", RTCIceConnectionStateCompleted},
|
||||
{"disconnected", RTCIceConnectionStateDisconnected},
|
||||
{"failed", RTCIceConnectionStateFailed},
|
||||
{"closed", RTCIceConnectionStateClosed},
|
||||
{unknownStr, ICEConnectionState(Unknown)},
|
||||
{"new", ICEConnectionStateNew},
|
||||
{"checking", ICEConnectionStateChecking},
|
||||
{"connected", ICEConnectionStateConnected},
|
||||
{"completed", ICEConnectionStateCompleted},
|
||||
{"disconnected", ICEConnectionStateDisconnected},
|
||||
{"failed", ICEConnectionStateFailed},
|
||||
{"closed", ICEConnectionStateClosed},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
assert.Equal(t,
|
||||
testCase.expectedState,
|
||||
newRTCIceConnectionState(testCase.stateString),
|
||||
newICEConnectionState(testCase.stateString),
|
||||
"testCase: %d %v", i, testCase,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRTCIceConnectionState_String(t *testing.T) {
|
||||
func TestICEConnectionState_String(t *testing.T) {
|
||||
testCases := []struct {
|
||||
state RTCIceConnectionState
|
||||
state ICEConnectionState
|
||||
expectedString string
|
||||
}{
|
||||
{RTCIceConnectionState(Unknown), unknownStr},
|
||||
{RTCIceConnectionStateNew, "new"},
|
||||
{RTCIceConnectionStateChecking, "checking"},
|
||||
{RTCIceConnectionStateConnected, "connected"},
|
||||
{RTCIceConnectionStateCompleted, "completed"},
|
||||
{RTCIceConnectionStateDisconnected, "disconnected"},
|
||||
{RTCIceConnectionStateFailed, "failed"},
|
||||
{RTCIceConnectionStateClosed, "closed"},
|
||||
{ICEConnectionState(Unknown), unknownStr},
|
||||
{ICEConnectionStateNew, "new"},
|
||||
{ICEConnectionStateChecking, "checking"},
|
||||
{ICEConnectionStateConnected, "connected"},
|
||||
{ICEConnectionStateCompleted, "completed"},
|
||||
{ICEConnectionStateDisconnected, "disconnected"},
|
||||
{ICEConnectionStateFailed, "failed"},
|
||||
{ICEConnectionStateClosed, "closed"},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
|
@@ -1,42 +1,42 @@
|
||||
package webrtc
|
||||
|
||||
// RTCIceCredentialType indicates the type of credentials used to connect to
|
||||
// ICECredentialType indicates the type of credentials used to connect to
|
||||
// an ICE server.
|
||||
type RTCIceCredentialType int
|
||||
type ICECredentialType int
|
||||
|
||||
const (
|
||||
// RTCIceCredentialTypePassword describes username and pasword based
|
||||
// ICECredentialTypePassword describes username and pasword based
|
||||
// credentials as described in https://tools.ietf.org/html/rfc5389.
|
||||
RTCIceCredentialTypePassword RTCIceCredentialType = iota + 1
|
||||
ICECredentialTypePassword ICECredentialType = iota + 1
|
||||
|
||||
// RTCIceCredentialTypeOauth describes token based credential as described
|
||||
// ICECredentialTypeOauth describes token based credential as described
|
||||
// in https://tools.ietf.org/html/rfc7635.
|
||||
RTCIceCredentialTypeOauth
|
||||
ICECredentialTypeOauth
|
||||
)
|
||||
|
||||
// This is done this way because of a linter.
|
||||
const (
|
||||
rtcIceCredentialTypePasswordStr = "password"
|
||||
rtcIceCredentialTypeOauthStr = "oauth"
|
||||
iceCredentialTypePasswordStr = "password"
|
||||
iceCredentialTypeOauthStr = "oauth"
|
||||
)
|
||||
|
||||
func newRTCIceCredentialType(raw string) RTCIceCredentialType {
|
||||
func newICECredentialType(raw string) ICECredentialType {
|
||||
switch raw {
|
||||
case rtcIceCredentialTypePasswordStr:
|
||||
return RTCIceCredentialTypePassword
|
||||
case rtcIceCredentialTypeOauthStr:
|
||||
return RTCIceCredentialTypeOauth
|
||||
case iceCredentialTypePasswordStr:
|
||||
return ICECredentialTypePassword
|
||||
case iceCredentialTypeOauthStr:
|
||||
return ICECredentialTypeOauth
|
||||
default:
|
||||
return RTCIceCredentialType(Unknown)
|
||||
return ICECredentialType(Unknown)
|
||||
}
|
||||
}
|
||||
|
||||
func (t RTCIceCredentialType) String() string {
|
||||
func (t ICECredentialType) String() string {
|
||||
switch t {
|
||||
case RTCIceCredentialTypePassword:
|
||||
return rtcIceCredentialTypePasswordStr
|
||||
case RTCIceCredentialTypeOauth:
|
||||
return rtcIceCredentialTypeOauthStr
|
||||
case ICECredentialTypePassword:
|
||||
return iceCredentialTypePasswordStr
|
||||
case ICECredentialTypeOauth:
|
||||
return iceCredentialTypeOauthStr
|
||||
default:
|
||||
return ErrUnknownType.Error()
|
||||
}
|
||||
|
@@ -6,33 +6,33 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewRTCIceCredentialType(t *testing.T) {
|
||||
func TestNewICECredentialType(t *testing.T) {
|
||||
testCases := []struct {
|
||||
credentialTypeString string
|
||||
expectedCredentialType RTCIceCredentialType
|
||||
expectedCredentialType ICECredentialType
|
||||
}{
|
||||
{unknownStr, RTCIceCredentialType(Unknown)},
|
||||
{"password", RTCIceCredentialTypePassword},
|
||||
{"oauth", RTCIceCredentialTypeOauth},
|
||||
{unknownStr, ICECredentialType(Unknown)},
|
||||
{"password", ICECredentialTypePassword},
|
||||
{"oauth", ICECredentialTypeOauth},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
assert.Equal(t,
|
||||
testCase.expectedCredentialType,
|
||||
newRTCIceCredentialType(testCase.credentialTypeString),
|
||||
newICECredentialType(testCase.credentialTypeString),
|
||||
"testCase: %d %v", i, testCase,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRTCIceCredentialType_String(t *testing.T) {
|
||||
func TestICECredentialType_String(t *testing.T) {
|
||||
testCases := []struct {
|
||||
credentialType RTCIceCredentialType
|
||||
credentialType ICECredentialType
|
||||
expectedString string
|
||||
}{
|
||||
{RTCIceCredentialType(Unknown), unknownStr},
|
||||
{RTCIceCredentialTypePassword, "password"},
|
||||
{RTCIceCredentialTypeOauth, "oauth"},
|
||||
{ICECredentialType(Unknown), unknownStr},
|
||||
{ICECredentialTypePassword, "password"},
|
||||
{ICECredentialTypeOauth, "oauth"},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
|
@@ -7,13 +7,13 @@ import (
|
||||
"github.com/pions/webrtc/pkg/ice"
|
||||
)
|
||||
|
||||
// The RTCIceGatherer gathers local host, server reflexive and relay
|
||||
// The ICEGatherer gathers local host, server reflexive and relay
|
||||
// candidates, as well as enabling the retrieval of local Interactive
|
||||
// Connectivity Establishment (ICE) parameters which can be
|
||||
// exchanged in signaling.
|
||||
type RTCIceGatherer struct {
|
||||
type ICEGatherer struct {
|
||||
lock sync.RWMutex
|
||||
state RTCIceGathererState
|
||||
state ICEGathererState
|
||||
|
||||
validatedServers []*ice.URL
|
||||
|
||||
@@ -22,10 +22,10 @@ type RTCIceGatherer struct {
|
||||
api *API
|
||||
}
|
||||
|
||||
// NewRTCIceGatherer creates a new NewRTCIceGatherer.
|
||||
// NewICEGatherer creates a new NewICEGatherer.
|
||||
// This constructor is part of the ORTC API. It is not
|
||||
// meant to be used together with the basic WebRTC API.
|
||||
func (api *API) NewRTCIceGatherer(opts RTCIceGatherOptions) (*RTCIceGatherer, error) {
|
||||
func (api *API) NewICEGatherer(opts ICEGatherOptions) (*ICEGatherer, error) {
|
||||
validatedServers := []*ice.URL{}
|
||||
if len(opts.ICEServers) > 0 {
|
||||
for _, server := range opts.ICEServers {
|
||||
@@ -37,22 +37,22 @@ func (api *API) NewRTCIceGatherer(opts RTCIceGatherOptions) (*RTCIceGatherer, er
|
||||
}
|
||||
}
|
||||
|
||||
return &RTCIceGatherer{
|
||||
state: RTCIceGathererStateNew,
|
||||
return &ICEGatherer{
|
||||
state: ICEGathererStateNew,
|
||||
validatedServers: validatedServers,
|
||||
api: api,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// State indicates the current state of the ICE gatherer.
|
||||
func (g *RTCIceGatherer) State() RTCIceGathererState {
|
||||
func (g *ICEGatherer) State() ICEGathererState {
|
||||
g.lock.RLock()
|
||||
defer g.lock.RUnlock()
|
||||
return g.state
|
||||
}
|
||||
|
||||
// Gather ICE candidates.
|
||||
func (g *RTCIceGatherer) Gather() error {
|
||||
func (g *ICEGatherer) Gather() error {
|
||||
g.lock.Lock()
|
||||
defer g.lock.Unlock()
|
||||
|
||||
@@ -70,13 +70,13 @@ func (g *RTCIceGatherer) Gather() error {
|
||||
}
|
||||
|
||||
g.agent = agent
|
||||
g.state = RTCIceGathererStateComplete
|
||||
g.state = ICEGathererStateComplete
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Close prunes all local candidates, and closes the ports.
|
||||
func (g *RTCIceGatherer) Close() error {
|
||||
func (g *ICEGatherer) Close() error {
|
||||
g.lock.Lock()
|
||||
defer g.lock.Unlock()
|
||||
|
||||
@@ -93,25 +93,25 @@ func (g *RTCIceGatherer) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetLocalParameters returns the ICE parameters of the RTCIceGatherer.
|
||||
func (g *RTCIceGatherer) GetLocalParameters() (RTCIceParameters, error) {
|
||||
// GetLocalParameters returns the ICE parameters of the ICEGatherer.
|
||||
func (g *ICEGatherer) GetLocalParameters() (ICEParameters, error) {
|
||||
g.lock.RLock()
|
||||
defer g.lock.RUnlock()
|
||||
if g.agent == nil {
|
||||
return RTCIceParameters{}, errors.New("Gatherer not started")
|
||||
return ICEParameters{}, errors.New("Gatherer not started")
|
||||
}
|
||||
|
||||
frag, pwd := g.agent.GetLocalUserCredentials()
|
||||
|
||||
return RTCIceParameters{
|
||||
return ICEParameters{
|
||||
UsernameFragment: frag,
|
||||
Password: pwd,
|
||||
IceLite: false,
|
||||
ICELite: false,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetLocalCandidates returns the sequence of valid local candidates associated with the RTCIceGatherer.
|
||||
func (g *RTCIceGatherer) GetLocalCandidates() ([]RTCIceCandidate, error) {
|
||||
// GetLocalCandidates returns the sequence of valid local candidates associated with the ICEGatherer.
|
||||
func (g *ICEGatherer) GetLocalCandidates() ([]ICECandidate, error) {
|
||||
g.lock.RLock()
|
||||
defer g.lock.RUnlock()
|
||||
|
||||
@@ -124,5 +124,5 @@ func (g *RTCIceGatherer) GetLocalCandidates() ([]RTCIceCandidate, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return newRTCIceCandidatesFromICE(iceCandidates)
|
||||
return newICECandidatesFromICE(iceCandidates)
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/pions/transport/test"
|
||||
)
|
||||
|
||||
func TestNewRTCIceGatherer_Success(t *testing.T) {
|
||||
func TestNewICEGatherer_Success(t *testing.T) {
|
||||
// Limit runtime in case of deadlocks
|
||||
lim := test.TimeOut(time.Second * 20)
|
||||
defer lim.Stop()
|
||||
@@ -15,18 +15,18 @@ func TestNewRTCIceGatherer_Success(t *testing.T) {
|
||||
report := test.CheckRoutines(t)
|
||||
defer report()
|
||||
|
||||
opts := RTCIceGatherOptions{
|
||||
ICEServers: []RTCIceServer{{URLs: []string{"stun:stun.l.google.com:19302"}}},
|
||||
opts := ICEGatherOptions{
|
||||
ICEServers: []ICEServer{{URLs: []string{"stun:stun.l.google.com:19302"}}},
|
||||
}
|
||||
|
||||
api := NewAPI()
|
||||
|
||||
gatherer, err := api.NewRTCIceGatherer(opts)
|
||||
gatherer, err := api.NewICEGatherer(opts)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if gatherer.State() != RTCIceGathererStateNew {
|
||||
if gatherer.State() != ICEGathererStateNew {
|
||||
t.Fatalf("Expected gathering state new")
|
||||
}
|
||||
|
||||
|
@@ -1,34 +1,34 @@
|
||||
package webrtc
|
||||
|
||||
// RTCIceGathererState represents the current state of the ICE gatherer.
|
||||
type RTCIceGathererState byte
|
||||
// ICEGathererState represents the current state of the ICE gatherer.
|
||||
type ICEGathererState byte
|
||||
|
||||
const (
|
||||
// RTCIceGathererStateNew indicates object has been created but
|
||||
// ICEGathererStateNew indicates object has been created but
|
||||
// gather() has not been called.
|
||||
RTCIceGathererStateNew RTCIceGathererState = iota + 1
|
||||
ICEGathererStateNew ICEGathererState = iota + 1
|
||||
|
||||
// RTCIceGathererStateGathering indicates gather() has been called,
|
||||
// and the RTCIceGatherer is in the process of gathering candidates.
|
||||
RTCIceGathererStateGathering
|
||||
// ICEGathererStateGathering indicates gather() has been called,
|
||||
// and the ICEGatherer is in the process of gathering candidates.
|
||||
ICEGathererStateGathering
|
||||
|
||||
// RTCIceGathererStateComplete indicates the RTCIceGatherer has completed gathering.
|
||||
RTCIceGathererStateComplete
|
||||
// ICEGathererStateComplete indicates the ICEGatherer has completed gathering.
|
||||
ICEGathererStateComplete
|
||||
|
||||
// RTCIceGathererStateClosed indicates the closed state can only be entered
|
||||
// when the RTCIceGatherer has been closed intentionally by calling close().
|
||||
RTCIceGathererStateClosed
|
||||
// ICEGathererStateClosed indicates the closed state can only be entered
|
||||
// when the ICEGatherer has been closed intentionally by calling close().
|
||||
ICEGathererStateClosed
|
||||
)
|
||||
|
||||
func (s RTCIceGathererState) String() string {
|
||||
func (s ICEGathererState) String() string {
|
||||
switch s {
|
||||
case RTCIceGathererStateNew:
|
||||
case ICEGathererStateNew:
|
||||
return "new"
|
||||
case RTCIceGathererStateGathering:
|
||||
case ICEGathererStateGathering:
|
||||
return "gathering"
|
||||
case RTCIceGathererStateComplete:
|
||||
case ICEGathererStateComplete:
|
||||
return "complete"
|
||||
case RTCIceGathererStateClosed:
|
||||
case ICEGathererStateClosed:
|
||||
return "closed"
|
||||
default:
|
||||
return unknownStr
|
||||
|
@@ -6,16 +6,16 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRTCIceGathererState_String(t *testing.T) {
|
||||
func TestICEGathererState_String(t *testing.T) {
|
||||
testCases := []struct {
|
||||
state RTCIceGathererState
|
||||
state ICEGathererState
|
||||
expectedString string
|
||||
}{
|
||||
{RTCIceGathererState(Unknown), unknownStr},
|
||||
{RTCIceGathererStateNew, "new"},
|
||||
{RTCIceGathererStateGathering, "gathering"},
|
||||
{RTCIceGathererStateComplete, "complete"},
|
||||
{RTCIceGathererStateClosed, "closed"},
|
||||
{ICEGathererState(Unknown), unknownStr},
|
||||
{ICEGathererStateNew, "new"},
|
||||
{ICEGathererStateGathering, "gathering"},
|
||||
{ICEGathererStateComplete, "complete"},
|
||||
{ICEGathererStateClosed, "closed"},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
|
@@ -1,51 +1,51 @@
|
||||
package webrtc
|
||||
|
||||
// RTCIceGatheringState describes the state of the candidate gathering process.
|
||||
type RTCIceGatheringState int
|
||||
// ICEGatheringState describes the state of the candidate gathering process.
|
||||
type ICEGatheringState int
|
||||
|
||||
const (
|
||||
// RTCIceGatheringStateNew indicates that any of the RTCIceTransports are
|
||||
// ICEGatheringStateNew indicates that any of the ICETransports are
|
||||
// in the "new" gathering state and none of the transports are in the
|
||||
// "gathering" state, or there are no transports.
|
||||
RTCIceGatheringStateNew RTCIceGatheringState = iota + 1
|
||||
ICEGatheringStateNew ICEGatheringState = iota + 1
|
||||
|
||||
// RTCIceGatheringStateGathering indicates that any of the RTCIceTransports
|
||||
// ICEGatheringStateGathering indicates that any of the ICETransports
|
||||
// are in the "gathering" state.
|
||||
RTCIceGatheringStateGathering
|
||||
ICEGatheringStateGathering
|
||||
|
||||
// RTCIceGatheringStateComplete indicates that at least one RTCIceTransport
|
||||
// exists, and all RTCIceTransports are in the "completed" gathering state.
|
||||
RTCIceGatheringStateComplete
|
||||
// ICEGatheringStateComplete indicates that at least one ICETransport
|
||||
// exists, and all ICETransports are in the "completed" gathering state.
|
||||
ICEGatheringStateComplete
|
||||
)
|
||||
|
||||
// This is done this way because of a linter.
|
||||
const (
|
||||
rtcIceGatheringStateNewStr = "new"
|
||||
rtcIceGatheringStateGatheringStr = "gathering"
|
||||
rtcIceGatheringStateCompleteStr = "complete"
|
||||
iceGatheringStateNewStr = "new"
|
||||
iceGatheringStateGatheringStr = "gathering"
|
||||
iceGatheringStateCompleteStr = "complete"
|
||||
)
|
||||
|
||||
func newRTCIceGatheringState(raw string) RTCIceGatheringState {
|
||||
func newICEGatheringState(raw string) ICEGatheringState {
|
||||
switch raw {
|
||||
case rtcIceGatheringStateNewStr:
|
||||
return RTCIceGatheringStateNew
|
||||
case rtcIceGatheringStateGatheringStr:
|
||||
return RTCIceGatheringStateGathering
|
||||
case rtcIceGatheringStateCompleteStr:
|
||||
return RTCIceGatheringStateComplete
|
||||
case iceGatheringStateNewStr:
|
||||
return ICEGatheringStateNew
|
||||
case iceGatheringStateGatheringStr:
|
||||
return ICEGatheringStateGathering
|
||||
case iceGatheringStateCompleteStr:
|
||||
return ICEGatheringStateComplete
|
||||
default:
|
||||
return RTCIceGatheringState(Unknown)
|
||||
return ICEGatheringState(Unknown)
|
||||
}
|
||||
}
|
||||
|
||||
func (t RTCIceGatheringState) String() string {
|
||||
func (t ICEGatheringState) String() string {
|
||||
switch t {
|
||||
case RTCIceGatheringStateNew:
|
||||
return rtcIceGatheringStateNewStr
|
||||
case RTCIceGatheringStateGathering:
|
||||
return rtcIceGatheringStateGatheringStr
|
||||
case RTCIceGatheringStateComplete:
|
||||
return rtcIceGatheringStateCompleteStr
|
||||
case ICEGatheringStateNew:
|
||||
return iceGatheringStateNewStr
|
||||
case ICEGatheringStateGathering:
|
||||
return iceGatheringStateGatheringStr
|
||||
case ICEGatheringStateComplete:
|
||||
return iceGatheringStateCompleteStr
|
||||
default:
|
||||
return ErrUnknownType.Error()
|
||||
}
|
||||
|
@@ -6,35 +6,35 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewRTCIceGatheringState(t *testing.T) {
|
||||
func TestNewICEGatheringState(t *testing.T) {
|
||||
testCases := []struct {
|
||||
stateString string
|
||||
expectedState RTCIceGatheringState
|
||||
expectedState ICEGatheringState
|
||||
}{
|
||||
{unknownStr, RTCIceGatheringState(Unknown)},
|
||||
{"new", RTCIceGatheringStateNew},
|
||||
{"gathering", RTCIceGatheringStateGathering},
|
||||
{"complete", RTCIceGatheringStateComplete},
|
||||
{unknownStr, ICEGatheringState(Unknown)},
|
||||
{"new", ICEGatheringStateNew},
|
||||
{"gathering", ICEGatheringStateGathering},
|
||||
{"complete", ICEGatheringStateComplete},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
assert.Equal(t,
|
||||
testCase.expectedState,
|
||||
newRTCIceGatheringState(testCase.stateString),
|
||||
newICEGatheringState(testCase.stateString),
|
||||
"testCase: %d %v", i, testCase,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRTCIceGatheringState_String(t *testing.T) {
|
||||
func TestICEGatheringState_String(t *testing.T) {
|
||||
testCases := []struct {
|
||||
state RTCIceGatheringState
|
||||
state ICEGatheringState
|
||||
expectedString string
|
||||
}{
|
||||
{RTCIceGatheringState(Unknown), unknownStr},
|
||||
{RTCIceGatheringStateNew, "new"},
|
||||
{RTCIceGatheringStateGathering, "gathering"},
|
||||
{RTCIceGatheringStateComplete, "complete"},
|
||||
{ICEGatheringState(Unknown), unknownStr},
|
||||
{ICEGatheringStateNew, "new"},
|
||||
{ICEGatheringStateGathering, "gathering"},
|
||||
{ICEGatheringStateComplete, "complete"},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package webrtc
|
||||
|
||||
// RTCIceGatherOptions provides options relating to the gathering of ICE candidates.
|
||||
type RTCIceGatherOptions struct {
|
||||
ICEServers []RTCIceServer
|
||||
// ICEGatherOptions provides options relating to the gathering of ICE candidates.
|
||||
type ICEGatherOptions struct {
|
||||
ICEServers []ICEServer
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package webrtc
|
||||
|
||||
// RTCIceParameters includes the ICE username fragment
|
||||
// ICEParameters includes the ICE username fragment
|
||||
// and password and other ICE-related parameters.
|
||||
type RTCIceParameters struct {
|
||||
type ICEParameters struct {
|
||||
UsernameFragment string `json:"usernameFragment"`
|
||||
Password string `json:"password"`
|
||||
IceLite bool `json:"iceLite"`
|
||||
ICELite bool `json:"iceLite"`
|
||||
}
|
||||
|
@@ -5,41 +5,41 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// RTCIceProtocol indicates the transport protocol type that is used in the
|
||||
// ICEProtocol indicates the transport protocol type that is used in the
|
||||
// ice.URL structure.
|
||||
type RTCIceProtocol int
|
||||
type ICEProtocol int
|
||||
|
||||
const (
|
||||
// RTCIceProtocolUDP indicates the URL uses a UDP transport.
|
||||
RTCIceProtocolUDP RTCIceProtocol = iota + 1
|
||||
// ICEProtocolUDP indicates the URL uses a UDP transport.
|
||||
ICEProtocolUDP ICEProtocol = iota + 1
|
||||
|
||||
// RTCIceProtocolTCP indicates the URL uses a TCP transport.
|
||||
RTCIceProtocolTCP
|
||||
// ICEProtocolTCP indicates the URL uses a TCP transport.
|
||||
ICEProtocolTCP
|
||||
)
|
||||
|
||||
// This is done this way because of a linter.
|
||||
const (
|
||||
rtcIceProtocolUDPStr = "udp"
|
||||
rtcIceProtocolTCPStr = "tcp"
|
||||
iceProtocolUDPStr = "udp"
|
||||
iceProtocolTCPStr = "tcp"
|
||||
)
|
||||
|
||||
func newRTCIceProtocol(raw string) (RTCIceProtocol, error) {
|
||||
func newICEProtocol(raw string) (ICEProtocol, error) {
|
||||
switch {
|
||||
case strings.EqualFold(rtcIceProtocolUDPStr, raw):
|
||||
return RTCIceProtocolUDP, nil
|
||||
case strings.EqualFold(rtcIceProtocolTCPStr, raw):
|
||||
return RTCIceProtocolTCP, nil
|
||||
case strings.EqualFold(iceProtocolUDPStr, raw):
|
||||
return ICEProtocolUDP, nil
|
||||
case strings.EqualFold(iceProtocolTCPStr, raw):
|
||||
return ICEProtocolTCP, nil
|
||||
default:
|
||||
return RTCIceProtocol(Unknown), fmt.Errorf("unknown protocol: %s", raw)
|
||||
return ICEProtocol(Unknown), fmt.Errorf("unknown protocol: %s", raw)
|
||||
}
|
||||
}
|
||||
|
||||
func (t RTCIceProtocol) String() string {
|
||||
func (t ICEProtocol) String() string {
|
||||
switch t {
|
||||
case RTCIceProtocolUDP:
|
||||
return rtcIceProtocolUDPStr
|
||||
case RTCIceProtocolTCP:
|
||||
return rtcIceProtocolTCPStr
|
||||
case ICEProtocolUDP:
|
||||
return iceProtocolUDPStr
|
||||
case ICEProtocolTCP:
|
||||
return iceProtocolTCPStr
|
||||
default:
|
||||
return ErrUnknownType.Error()
|
||||
}
|
||||
|
@@ -6,21 +6,21 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewRTCIceProtocol(t *testing.T) {
|
||||
func TestNewICEProtocol(t *testing.T) {
|
||||
testCases := []struct {
|
||||
protoString string
|
||||
shouldFail bool
|
||||
expectedProto RTCIceProtocol
|
||||
expectedProto ICEProtocol
|
||||
}{
|
||||
{unknownStr, true, RTCIceProtocol(Unknown)},
|
||||
{"udp", false, RTCIceProtocolUDP},
|
||||
{"tcp", false, RTCIceProtocolTCP},
|
||||
{"UDP", false, RTCIceProtocolUDP},
|
||||
{"TCP", false, RTCIceProtocolTCP},
|
||||
{unknownStr, true, ICEProtocol(Unknown)},
|
||||
{"udp", false, ICEProtocolUDP},
|
||||
{"tcp", false, ICEProtocolTCP},
|
||||
{"UDP", false, ICEProtocolUDP},
|
||||
{"TCP", false, ICEProtocolTCP},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
actual, err := newRTCIceProtocol(testCase.protoString)
|
||||
actual, err := newICEProtocol(testCase.protoString)
|
||||
if (err != nil) != testCase.shouldFail {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -32,14 +32,14 @@ func TestNewRTCIceProtocol(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRTCIceProtocol_String(t *testing.T) {
|
||||
func TestICEProtocol_String(t *testing.T) {
|
||||
testCases := []struct {
|
||||
proto RTCIceProtocol
|
||||
proto ICEProtocol
|
||||
expectedString string
|
||||
}{
|
||||
{RTCIceProtocol(Unknown), unknownStr},
|
||||
{RTCIceProtocolUDP, "udp"},
|
||||
{RTCIceProtocolTCP, "tcp"},
|
||||
{ICEProtocol(Unknown), unknownStr},
|
||||
{ICEProtocolUDP, "udp"},
|
||||
{ICEProtocolTCP, "tcp"},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
|
@@ -1,44 +1,44 @@
|
||||
package webrtc
|
||||
|
||||
// RTCIceRole describes the role ice.Agent is playing in selecting the
|
||||
// ICERole describes the role ice.Agent is playing in selecting the
|
||||
// preferred the candidate pair.
|
||||
type RTCIceRole int
|
||||
type ICERole int
|
||||
|
||||
const (
|
||||
// RTCIceRoleControlling indicates that the ICE agent that is responsible
|
||||
// ICERoleControlling indicates that the ICE agent that is responsible
|
||||
// for selecting the final choice of candidate pairs and signaling them
|
||||
// through STUN and an updated offer, if needed. In any session, one agent
|
||||
// is always controlling. The other is the controlled agent.
|
||||
RTCIceRoleControlling RTCIceRole = iota + 1
|
||||
ICERoleControlling ICERole = iota + 1
|
||||
|
||||
// RTCIceRoleControlled indicates that an ICE agent that waits for the
|
||||
// ICERoleControlled indicates that an ICE agent that waits for the
|
||||
// controlling agent to select the final choice of candidate pairs.
|
||||
RTCIceRoleControlled
|
||||
ICERoleControlled
|
||||
)
|
||||
|
||||
// This is done this way because of a linter.
|
||||
const (
|
||||
rtcIceRoleControllingStr = "controlling"
|
||||
rtcIceRoleControlledStr = "controlled"
|
||||
iceRoleControllingStr = "controlling"
|
||||
iceRoleControlledStr = "controlled"
|
||||
)
|
||||
|
||||
func newRTCIceRole(raw string) RTCIceRole {
|
||||
func newICERole(raw string) ICERole {
|
||||
switch raw {
|
||||
case rtcIceRoleControllingStr:
|
||||
return RTCIceRoleControlling
|
||||
case rtcIceRoleControlledStr:
|
||||
return RTCIceRoleControlled
|
||||
case iceRoleControllingStr:
|
||||
return ICERoleControlling
|
||||
case iceRoleControlledStr:
|
||||
return ICERoleControlled
|
||||
default:
|
||||
return RTCIceRole(Unknown)
|
||||
return ICERole(Unknown)
|
||||
}
|
||||
}
|
||||
|
||||
func (t RTCIceRole) String() string {
|
||||
func (t ICERole) String() string {
|
||||
switch t {
|
||||
case RTCIceRoleControlling:
|
||||
return rtcIceRoleControllingStr
|
||||
case RTCIceRoleControlled:
|
||||
return rtcIceRoleControlledStr
|
||||
case ICERoleControlling:
|
||||
return iceRoleControllingStr
|
||||
case ICERoleControlled:
|
||||
return iceRoleControlledStr
|
||||
default:
|
||||
return ErrUnknownType.Error()
|
||||
}
|
||||
|
@@ -6,33 +6,33 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewRTCIceRole(t *testing.T) {
|
||||
func TestNewICERole(t *testing.T) {
|
||||
testCases := []struct {
|
||||
roleString string
|
||||
expectedRole RTCIceRole
|
||||
expectedRole ICERole
|
||||
}{
|
||||
{unknownStr, RTCIceRole(Unknown)},
|
||||
{"controlling", RTCIceRoleControlling},
|
||||
{"controlled", RTCIceRoleControlled},
|
||||
{unknownStr, ICERole(Unknown)},
|
||||
{"controlling", ICERoleControlling},
|
||||
{"controlled", ICERoleControlled},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
assert.Equal(t,
|
||||
testCase.expectedRole,
|
||||
newRTCIceRole(testCase.roleString),
|
||||
newICERole(testCase.roleString),
|
||||
"testCase: %d %v", i, testCase,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRTCIceRole_String(t *testing.T) {
|
||||
func TestICERole_String(t *testing.T) {
|
||||
testCases := []struct {
|
||||
proto RTCIceRole
|
||||
proto ICERole
|
||||
expectedString string
|
||||
}{
|
||||
{RTCIceRole(Unknown), unknownStr},
|
||||
{RTCIceRoleControlling, "controlling"},
|
||||
{RTCIceRoleControlled, "controlled"},
|
||||
{ICERole(Unknown), unknownStr},
|
||||
{ICERoleControlling, "controlling"},
|
||||
{ICERoleControlled, "controlled"},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
|
@@ -5,20 +5,20 @@ import (
|
||||
"github.com/pions/webrtc/pkg/rtcerr"
|
||||
)
|
||||
|
||||
// RTCIceServer describes a single STUN and TURN server that can be used by
|
||||
// the IceAgent to establish a connection with a peer.
|
||||
type RTCIceServer struct {
|
||||
// ICEServer describes a single STUN and TURN server that can be used by
|
||||
// the ICEAgent to establish a connection with a peer.
|
||||
type ICEServer struct {
|
||||
URLs []string
|
||||
Username string
|
||||
Credential interface{}
|
||||
CredentialType RTCIceCredentialType
|
||||
CredentialType ICECredentialType
|
||||
}
|
||||
|
||||
func (s RTCIceServer) parseURL(i int) (*ice.URL, error) {
|
||||
func (s ICEServer) parseURL(i int) (*ice.URL, error) {
|
||||
return ice.ParseURL(s.URLs[i])
|
||||
}
|
||||
|
||||
func (s RTCIceServer) validate() ([]*ice.URL, error) {
|
||||
func (s ICEServer) validate() ([]*ice.URL, error) {
|
||||
urls := []*ice.URL{}
|
||||
|
||||
for i := range s.URLs {
|
||||
@@ -34,15 +34,15 @@ func (s RTCIceServer) validate() ([]*ice.URL, error) {
|
||||
}
|
||||
|
||||
switch s.CredentialType {
|
||||
case RTCIceCredentialTypePassword:
|
||||
case ICECredentialTypePassword:
|
||||
// https://www.w3.org/TR/webrtc/#set-the-configuration (step #11.3.3)
|
||||
if _, ok := s.Credential.(string); !ok {
|
||||
return nil, &rtcerr.InvalidAccessError{Err: ErrTurnCredencials}
|
||||
}
|
||||
|
||||
case RTCIceCredentialTypeOauth:
|
||||
case ICECredentialTypeOauth:
|
||||
// https://www.w3.org/TR/webrtc/#set-the-configuration (step #11.3.4)
|
||||
if _, ok := s.Credential.(RTCOAuthCredential); !ok {
|
||||
if _, ok := s.Credential.(OAuthCredential); !ok {
|
||||
return nil, &rtcerr.InvalidAccessError{Err: ErrTurnCredencials}
|
||||
}
|
||||
|
||||
|
@@ -8,26 +8,26 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRTCIceServer_validate(t *testing.T) {
|
||||
func TestICEServer_validate(t *testing.T) {
|
||||
t.Run("Success", func(t *testing.T) {
|
||||
testCases := []struct {
|
||||
iceServer RTCIceServer
|
||||
iceServer ICEServer
|
||||
expectedValidate bool
|
||||
}{
|
||||
{RTCIceServer{
|
||||
{ICEServer{
|
||||
URLs: []string{"turn:192.158.29.39?transport=udp"},
|
||||
Username: "unittest",
|
||||
Credential: "placeholder",
|
||||
CredentialType: RTCIceCredentialTypePassword,
|
||||
CredentialType: ICECredentialTypePassword,
|
||||
}, true},
|
||||
{RTCIceServer{
|
||||
{ICEServer{
|
||||
URLs: []string{"turn:192.158.29.39?transport=udp"},
|
||||
Username: "unittest",
|
||||
Credential: RTCOAuthCredential{
|
||||
Credential: OAuthCredential{
|
||||
MacKey: "WmtzanB3ZW9peFhtdm42NzUzNG0=",
|
||||
AccessToken: "AAwg3kPHWPfvk9bDFL936wYvkoctMADzQ5VhNDgeMR3+ZlZ35byg972fW8QjpEl7bx91YLBPFsIhsxloWcXPhA==",
|
||||
},
|
||||
CredentialType: RTCIceCredentialTypeOauth,
|
||||
CredentialType: ICECredentialTypeOauth,
|
||||
}, true},
|
||||
}
|
||||
|
||||
@@ -38,35 +38,35 @@ func TestRTCIceServer_validate(t *testing.T) {
|
||||
})
|
||||
t.Run("Failure", func(t *testing.T) {
|
||||
testCases := []struct {
|
||||
iceServer RTCIceServer
|
||||
iceServer ICEServer
|
||||
expectedErr error
|
||||
}{
|
||||
{RTCIceServer{
|
||||
{ICEServer{
|
||||
URLs: []string{"turn:192.158.29.39?transport=udp"},
|
||||
}, &rtcerr.InvalidAccessError{Err: ErrNoTurnCredencials}},
|
||||
{RTCIceServer{
|
||||
{ICEServer{
|
||||
URLs: []string{"turn:192.158.29.39?transport=udp"},
|
||||
Username: "unittest",
|
||||
Credential: false,
|
||||
CredentialType: RTCIceCredentialTypePassword,
|
||||
CredentialType: ICECredentialTypePassword,
|
||||
}, &rtcerr.InvalidAccessError{Err: ErrTurnCredencials}},
|
||||
{RTCIceServer{
|
||||
{ICEServer{
|
||||
URLs: []string{"turn:192.158.29.39?transport=udp"},
|
||||
Username: "unittest",
|
||||
Credential: false,
|
||||
CredentialType: RTCIceCredentialTypeOauth,
|
||||
CredentialType: ICECredentialTypeOauth,
|
||||
}, &rtcerr.InvalidAccessError{Err: ErrTurnCredencials}},
|
||||
{RTCIceServer{
|
||||
{ICEServer{
|
||||
URLs: []string{"turn:192.158.29.39?transport=udp"},
|
||||
Username: "unittest",
|
||||
Credential: false,
|
||||
CredentialType: Unknown,
|
||||
}, &rtcerr.InvalidAccessError{Err: ErrTurnCredencials}},
|
||||
{RTCIceServer{
|
||||
{ICEServer{
|
||||
URLs: []string{"stun:google.de?transport=udp"},
|
||||
Username: "unittest",
|
||||
Credential: false,
|
||||
CredentialType: RTCIceCredentialTypeOauth,
|
||||
CredentialType: ICECredentialTypeOauth,
|
||||
}, &rtcerr.SyntaxError{Err: ice.ErrSTUNQuery}},
|
||||
}
|
||||
|
||||
|
@@ -9,52 +9,52 @@ import (
|
||||
"github.com/pions/webrtc/pkg/ice"
|
||||
)
|
||||
|
||||
// RTCIceTransport allows an application access to information about the ICE
|
||||
// ICETransport allows an application access to information about the ICE
|
||||
// transport over which packets are sent and received.
|
||||
type RTCIceTransport struct {
|
||||
type ICETransport struct {
|
||||
lock sync.RWMutex
|
||||
|
||||
role RTCIceRole
|
||||
// Component RTCIceComponent
|
||||
// State RTCIceTransportState
|
||||
// gatheringState RTCIceGathererState
|
||||
role ICERole
|
||||
// Component ICEComponent
|
||||
// State ICETransportState
|
||||
// gatheringState ICEGathererState
|
||||
|
||||
onConnectionStateChangeHdlr func(RTCIceTransportState)
|
||||
onConnectionStateChangeHdlr func(ICETransportState)
|
||||
|
||||
gatherer *RTCIceGatherer
|
||||
gatherer *ICEGatherer
|
||||
conn *ice.Conn
|
||||
mux *mux.Mux
|
||||
}
|
||||
|
||||
// func (t *RTCIceTransport) GetLocalCandidates() []RTCIceCandidate {
|
||||
// func (t *ICETransport) GetLocalCandidates() []ICECandidate {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// func (t *RTCIceTransport) GetRemoteCandidates() []RTCIceCandidate {
|
||||
// func (t *ICETransport) GetRemoteCandidates() []ICECandidate {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// func (t *RTCIceTransport) GetSelectedCandidatePair() RTCIceCandidatePair {
|
||||
// func (t *ICETransport) GetSelectedCandidatePair() ICECandidatePair {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// func (t *RTCIceTransport) GetLocalParameters() RTCIceParameters {
|
||||
// func (t *ICETransport) GetLocalParameters() ICEParameters {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// func (t *RTCIceTransport) GetRemoteParameters() RTCIceParameters {
|
||||
// func (t *ICETransport) GetRemoteParameters() ICEParameters {
|
||||
//
|
||||
// }
|
||||
|
||||
// NewRTCIceTransport creates a new NewRTCIceTransport.
|
||||
// NewICETransport creates a new NewICETransport.
|
||||
// This constructor is part of the ORTC API. It is not
|
||||
// meant to be used together with the basic WebRTC API.
|
||||
func (api *API) NewRTCIceTransport(gatherer *RTCIceGatherer) *RTCIceTransport {
|
||||
return &RTCIceTransport{gatherer: gatherer}
|
||||
func (api *API) NewICETransport(gatherer *ICEGatherer) *ICETransport {
|
||||
return &ICETransport{gatherer: gatherer}
|
||||
}
|
||||
|
||||
// Start incoming connectivity checks based on its configured role.
|
||||
func (t *RTCIceTransport) Start(gatherer *RTCIceGatherer, params RTCIceParameters, role *RTCIceRole) error {
|
||||
func (t *ICETransport) Start(gatherer *ICEGatherer, params ICEParameters, role *ICERole) error {
|
||||
t.lock.Lock()
|
||||
defer t.lock.Unlock()
|
||||
|
||||
@@ -68,14 +68,14 @@ func (t *RTCIceTransport) Start(gatherer *RTCIceGatherer, params RTCIceParameter
|
||||
|
||||
agent := t.gatherer.agent
|
||||
err := agent.OnConnectionStateChange(func(iceState ice.ConnectionState) {
|
||||
t.onConnectionStateChange(newRTCIceTransportStateFromICE(iceState))
|
||||
t.onConnectionStateChange(newICETransportStateFromICE(iceState))
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if role == nil {
|
||||
controlled := RTCIceRoleControlled
|
||||
controlled := ICERoleControlled
|
||||
role = &controlled
|
||||
}
|
||||
t.role = *role
|
||||
@@ -86,12 +86,12 @@ func (t *RTCIceTransport) Start(gatherer *RTCIceGatherer, params RTCIceParameter
|
||||
|
||||
var iceConn *ice.Conn
|
||||
switch *role {
|
||||
case RTCIceRoleControlling:
|
||||
case ICERoleControlling:
|
||||
iceConn, err = agent.Dial(context.TODO(),
|
||||
params.UsernameFragment,
|
||||
params.Password)
|
||||
|
||||
case RTCIceRoleControlled:
|
||||
case ICERoleControlled:
|
||||
iceConn, err = agent.Accept(context.TODO(),
|
||||
params.UsernameFragment,
|
||||
params.Password)
|
||||
@@ -112,8 +112,8 @@ func (t *RTCIceTransport) Start(gatherer *RTCIceGatherer, params RTCIceParameter
|
||||
return nil
|
||||
}
|
||||
|
||||
// Stop irreversibly stops the RTCIceTransport.
|
||||
func (t *RTCIceTransport) Stop() error {
|
||||
// Stop irreversibly stops the ICETransport.
|
||||
func (t *ICETransport) Stop() error {
|
||||
// Close the Mux. This closes the Mux and the underlying ICE conn.
|
||||
t.lock.Lock()
|
||||
defer t.lock.Unlock()
|
||||
@@ -126,13 +126,13 @@ func (t *RTCIceTransport) Stop() error {
|
||||
|
||||
// OnConnectionStateChange sets a handler that is fired when the ICE
|
||||
// connection state changes.
|
||||
func (t *RTCIceTransport) OnConnectionStateChange(f func(RTCIceTransportState)) {
|
||||
func (t *ICETransport) OnConnectionStateChange(f func(ICETransportState)) {
|
||||
t.lock.Lock()
|
||||
defer t.lock.Unlock()
|
||||
t.onConnectionStateChangeHdlr = f
|
||||
}
|
||||
|
||||
func (t *RTCIceTransport) onConnectionStateChange(state RTCIceTransportState) {
|
||||
func (t *ICETransport) onConnectionStateChange(state ICETransportState) {
|
||||
t.lock.RLock()
|
||||
hdlr := t.onConnectionStateChangeHdlr
|
||||
t.lock.RUnlock()
|
||||
@@ -142,15 +142,15 @@ func (t *RTCIceTransport) onConnectionStateChange(state RTCIceTransportState) {
|
||||
}
|
||||
|
||||
// Role indicates the current role of the ICE transport.
|
||||
func (t *RTCIceTransport) Role() RTCIceRole {
|
||||
func (t *ICETransport) Role() ICERole {
|
||||
t.lock.RLock()
|
||||
defer t.lock.RUnlock()
|
||||
|
||||
return t.role
|
||||
}
|
||||
|
||||
// SetRemoteCandidates sets the sequence of candidates associated with the remote RTCIceTransport.
|
||||
func (t *RTCIceTransport) SetRemoteCandidates(remoteCandidates []RTCIceCandidate) error {
|
||||
// SetRemoteCandidates sets the sequence of candidates associated with the remote ICETransport.
|
||||
func (t *ICETransport) SetRemoteCandidates(remoteCandidates []ICECandidate) error {
|
||||
t.lock.RLock()
|
||||
defer t.lock.RUnlock()
|
||||
|
||||
@@ -172,8 +172,8 @@ func (t *RTCIceTransport) SetRemoteCandidates(remoteCandidates []RTCIceCandidate
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddRemoteCandidate adds a candidate associated with the remote RTCIceTransport.
|
||||
func (t *RTCIceTransport) AddRemoteCandidate(remoteCandidate RTCIceCandidate) error {
|
||||
// AddRemoteCandidate adds a candidate associated with the remote ICETransport.
|
||||
func (t *ICETransport) AddRemoteCandidate(remoteCandidate ICECandidate) error {
|
||||
t.lock.RLock()
|
||||
defer t.lock.RUnlock()
|
||||
|
||||
@@ -193,7 +193,7 @@ func (t *RTCIceTransport) AddRemoteCandidate(remoteCandidate RTCIceCandidate) er
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *RTCIceTransport) ensureGatherer() error {
|
||||
func (t *ICETransport) ensureGatherer() error {
|
||||
if t.gatherer == nil ||
|
||||
t.gatherer.agent == nil {
|
||||
return errors.New("Gatherer not started")
|
||||
|
@@ -1,41 +1,41 @@
|
||||
package webrtc
|
||||
|
||||
// RTCIceTransportPolicy defines the ICE candidate policy surface the
|
||||
// ICETransportPolicy defines the ICE candidate policy surface the
|
||||
// permitted candidates. Only these candidates are used for connectivity checks.
|
||||
type RTCIceTransportPolicy int
|
||||
type ICETransportPolicy int
|
||||
|
||||
const (
|
||||
// RTCIceTransportPolicyRelay indicates only media relay candidates such
|
||||
// ICETransportPolicyRelay indicates only media relay candidates such
|
||||
// as candidates passing through a TURN server are used.
|
||||
RTCIceTransportPolicyRelay RTCIceTransportPolicy = iota + 1
|
||||
ICETransportPolicyRelay ICETransportPolicy = iota + 1
|
||||
|
||||
// RTCIceTransportPolicyAll indicates any type of candidate is used.
|
||||
RTCIceTransportPolicyAll
|
||||
// ICETransportPolicyAll indicates any type of candidate is used.
|
||||
ICETransportPolicyAll
|
||||
)
|
||||
|
||||
// This is done this way because of a linter.
|
||||
const (
|
||||
rtcIceTransportPolicyRelayStr = "relay"
|
||||
rtcIceTransportPolicyAllStr = "all"
|
||||
iceTransportPolicyRelayStr = "relay"
|
||||
iceTransportPolicyAllStr = "all"
|
||||
)
|
||||
|
||||
func newRTCIceTransportPolicy(raw string) RTCIceTransportPolicy {
|
||||
func newICETransportPolicy(raw string) ICETransportPolicy {
|
||||
switch raw {
|
||||
case rtcIceTransportPolicyRelayStr:
|
||||
return RTCIceTransportPolicyRelay
|
||||
case rtcIceTransportPolicyAllStr:
|
||||
return RTCIceTransportPolicyAll
|
||||
case iceTransportPolicyRelayStr:
|
||||
return ICETransportPolicyRelay
|
||||
case iceTransportPolicyAllStr:
|
||||
return ICETransportPolicyAll
|
||||
default:
|
||||
return RTCIceTransportPolicy(Unknown)
|
||||
return ICETransportPolicy(Unknown)
|
||||
}
|
||||
}
|
||||
|
||||
func (t RTCIceTransportPolicy) String() string {
|
||||
func (t ICETransportPolicy) String() string {
|
||||
switch t {
|
||||
case RTCIceTransportPolicyRelay:
|
||||
return rtcIceTransportPolicyRelayStr
|
||||
case RTCIceTransportPolicyAll:
|
||||
return rtcIceTransportPolicyAllStr
|
||||
case ICETransportPolicyRelay:
|
||||
return iceTransportPolicyRelayStr
|
||||
case ICETransportPolicyAll:
|
||||
return iceTransportPolicyAllStr
|
||||
default:
|
||||
return ErrUnknownType.Error()
|
||||
}
|
||||
|
@@ -6,33 +6,33 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewRTCIceTransportPolicy(t *testing.T) {
|
||||
func TestNewICETransportPolicy(t *testing.T) {
|
||||
testCases := []struct {
|
||||
policyString string
|
||||
expectedPolicy RTCIceTransportPolicy
|
||||
expectedPolicy ICETransportPolicy
|
||||
}{
|
||||
{unknownStr, RTCIceTransportPolicy(Unknown)},
|
||||
{"relay", RTCIceTransportPolicyRelay},
|
||||
{"all", RTCIceTransportPolicyAll},
|
||||
{unknownStr, ICETransportPolicy(Unknown)},
|
||||
{"relay", ICETransportPolicyRelay},
|
||||
{"all", ICETransportPolicyAll},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
assert.Equal(t,
|
||||
testCase.expectedPolicy,
|
||||
newRTCIceTransportPolicy(testCase.policyString),
|
||||
newICETransportPolicy(testCase.policyString),
|
||||
"testCase: %d %v", i, testCase,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRTCIceTransportPolicy_String(t *testing.T) {
|
||||
func TestICETransportPolicy_String(t *testing.T) {
|
||||
testCases := []struct {
|
||||
policy RTCIceTransportPolicy
|
||||
policy ICETransportPolicy
|
||||
expectedString string
|
||||
}{
|
||||
{RTCIceTransportPolicy(Unknown), unknownStr},
|
||||
{RTCIceTransportPolicyRelay, "relay"},
|
||||
{RTCIceTransportPolicyAll, "all"},
|
||||
{ICETransportPolicy(Unknown), unknownStr},
|
||||
{ICETransportPolicyRelay, "relay"},
|
||||
{ICETransportPolicyAll, "all"},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
|
@@ -2,104 +2,104 @@ package webrtc
|
||||
|
||||
import "github.com/pions/webrtc/pkg/ice"
|
||||
|
||||
// RTCIceTransportState represents the current state of the ICE transport.
|
||||
type RTCIceTransportState int
|
||||
// ICETransportState represents the current state of the ICE transport.
|
||||
type ICETransportState int
|
||||
|
||||
const (
|
||||
// RTCIceTransportStateNew indicates the RTCIceTransport is waiting
|
||||
// ICETransportStateNew indicates the ICETransport is waiting
|
||||
// for remote candidates to be supplied.
|
||||
RTCIceTransportStateNew = iota + 1
|
||||
ICETransportStateNew = iota + 1
|
||||
|
||||
// RTCIceTransportStateChecking indicates the RTCIceTransport has
|
||||
// ICETransportStateChecking indicates the ICETransport has
|
||||
// received at least one remote candidate, and a local and remote
|
||||
// RTCIceCandidateComplete dictionary was not added as the last candidate.
|
||||
RTCIceTransportStateChecking
|
||||
// ICECandidateComplete dictionary was not added as the last candidate.
|
||||
ICETransportStateChecking
|
||||
|
||||
// RTCIceTransportStateConnected indicates the RTCIceTransport has
|
||||
// ICETransportStateConnected indicates the ICETransport has
|
||||
// received a response to an outgoing connectivity check, or has
|
||||
// received incoming DTLS/media after a successful response to an
|
||||
// incoming connectivity check, but is still checking other candidate
|
||||
// pairs to see if there is a better connection.
|
||||
RTCIceTransportStateConnected
|
||||
ICETransportStateConnected
|
||||
|
||||
// RTCIceTransportStateCompleted indicates the RTCIceTransport tested
|
||||
// ICETransportStateCompleted indicates the ICETransport tested
|
||||
// all appropriate candidate pairs and at least one functioning
|
||||
// candidate pair has been found.
|
||||
RTCIceTransportStateCompleted
|
||||
ICETransportStateCompleted
|
||||
|
||||
// RTCIceTransportStateFailed indicates the RTCIceTransport the last
|
||||
// ICETransportStateFailed indicates the ICETransport the last
|
||||
// candidate was added and all appropriate candidate pairs have either
|
||||
// failed connectivity checks or have lost consent.
|
||||
RTCIceTransportStateFailed
|
||||
ICETransportStateFailed
|
||||
|
||||
// RTCIceTransportStateDisconnected indicates the RTCIceTransport has received
|
||||
// ICETransportStateDisconnected indicates the ICETransport has received
|
||||
// at least one local and remote candidate, but the final candidate was
|
||||
// received yet and all appropriate candidate pairs thus far have been
|
||||
// tested and failed.
|
||||
RTCIceTransportStateDisconnected
|
||||
ICETransportStateDisconnected
|
||||
|
||||
// RTCIceTransportStateClosed indicates the RTCIceTransport has shut down
|
||||
// ICETransportStateClosed indicates the ICETransport has shut down
|
||||
// and is no longer responding to STUN requests.
|
||||
RTCIceTransportStateClosed
|
||||
ICETransportStateClosed
|
||||
)
|
||||
|
||||
func (c RTCIceTransportState) String() string {
|
||||
func (c ICETransportState) String() string {
|
||||
switch c {
|
||||
case RTCIceTransportStateNew:
|
||||
case ICETransportStateNew:
|
||||
return "new"
|
||||
case RTCIceTransportStateChecking:
|
||||
case ICETransportStateChecking:
|
||||
return "checking"
|
||||
case RTCIceTransportStateConnected:
|
||||
case ICETransportStateConnected:
|
||||
return "connected"
|
||||
case RTCIceTransportStateCompleted:
|
||||
case ICETransportStateCompleted:
|
||||
return "completed"
|
||||
case RTCIceTransportStateFailed:
|
||||
case ICETransportStateFailed:
|
||||
return "failed"
|
||||
case RTCIceTransportStateDisconnected:
|
||||
case ICETransportStateDisconnected:
|
||||
return "disconnected"
|
||||
case RTCIceTransportStateClosed:
|
||||
case ICETransportStateClosed:
|
||||
return "closed"
|
||||
default:
|
||||
return unknownStr
|
||||
}
|
||||
}
|
||||
|
||||
func newRTCIceTransportStateFromICE(i ice.ConnectionState) RTCIceTransportState {
|
||||
func newICETransportStateFromICE(i ice.ConnectionState) ICETransportState {
|
||||
switch i {
|
||||
case ice.ConnectionStateNew:
|
||||
return RTCIceTransportStateNew
|
||||
return ICETransportStateNew
|
||||
case ice.ConnectionStateChecking:
|
||||
return RTCIceTransportStateChecking
|
||||
return ICETransportStateChecking
|
||||
case ice.ConnectionStateConnected:
|
||||
return RTCIceTransportStateConnected
|
||||
return ICETransportStateConnected
|
||||
case ice.ConnectionStateCompleted:
|
||||
return RTCIceTransportStateCompleted
|
||||
return ICETransportStateCompleted
|
||||
case ice.ConnectionStateFailed:
|
||||
return RTCIceTransportStateFailed
|
||||
return ICETransportStateFailed
|
||||
case ice.ConnectionStateDisconnected:
|
||||
return RTCIceTransportStateDisconnected
|
||||
return ICETransportStateDisconnected
|
||||
case ice.ConnectionStateClosed:
|
||||
return RTCIceTransportStateClosed
|
||||
return ICETransportStateClosed
|
||||
default:
|
||||
return RTCIceTransportState(Unknown)
|
||||
return ICETransportState(Unknown)
|
||||
}
|
||||
}
|
||||
|
||||
func (c RTCIceTransportState) toICE() ice.ConnectionState {
|
||||
func (c ICETransportState) toICE() ice.ConnectionState {
|
||||
switch c {
|
||||
case RTCIceTransportStateNew:
|
||||
case ICETransportStateNew:
|
||||
return ice.ConnectionStateNew
|
||||
case RTCIceTransportStateChecking:
|
||||
case ICETransportStateChecking:
|
||||
return ice.ConnectionStateChecking
|
||||
case RTCIceTransportStateConnected:
|
||||
case ICETransportStateConnected:
|
||||
return ice.ConnectionStateConnected
|
||||
case RTCIceTransportStateCompleted:
|
||||
case ICETransportStateCompleted:
|
||||
return ice.ConnectionStateCompleted
|
||||
case RTCIceTransportStateFailed:
|
||||
case ICETransportStateFailed:
|
||||
return ice.ConnectionStateFailed
|
||||
case RTCIceTransportStateDisconnected:
|
||||
case ICETransportStateDisconnected:
|
||||
return ice.ConnectionStateDisconnected
|
||||
case RTCIceTransportStateClosed:
|
||||
case ICETransportStateClosed:
|
||||
return ice.ConnectionStateClosed
|
||||
default:
|
||||
return ice.ConnectionState(Unknown)
|
||||
|
@@ -7,19 +7,19 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRTCIceTransportState_String(t *testing.T) {
|
||||
func TestICETransportState_String(t *testing.T) {
|
||||
testCases := []struct {
|
||||
state RTCIceTransportState
|
||||
state ICETransportState
|
||||
expectedString string
|
||||
}{
|
||||
{RTCIceTransportState(Unknown), unknownStr},
|
||||
{RTCIceTransportStateNew, "new"},
|
||||
{RTCIceTransportStateChecking, "checking"},
|
||||
{RTCIceTransportStateConnected, "connected"},
|
||||
{RTCIceTransportStateCompleted, "completed"},
|
||||
{RTCIceTransportStateFailed, "failed"},
|
||||
{RTCIceTransportStateDisconnected, "disconnected"},
|
||||
{RTCIceTransportStateClosed, "closed"},
|
||||
{ICETransportState(Unknown), unknownStr},
|
||||
{ICETransportStateNew, "new"},
|
||||
{ICETransportStateChecking, "checking"},
|
||||
{ICETransportStateConnected, "connected"},
|
||||
{ICETransportStateCompleted, "completed"},
|
||||
{ICETransportStateFailed, "failed"},
|
||||
{ICETransportStateDisconnected, "disconnected"},
|
||||
{ICETransportStateClosed, "closed"},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
@@ -31,19 +31,19 @@ func TestRTCIceTransportState_String(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRTCIceTransportState_Convert(t *testing.T) {
|
||||
func TestICETransportState_Convert(t *testing.T) {
|
||||
testCases := []struct {
|
||||
native RTCIceTransportState
|
||||
native ICETransportState
|
||||
ice ice.ConnectionState
|
||||
}{
|
||||
{RTCIceTransportState(Unknown), ice.ConnectionState(Unknown)},
|
||||
{RTCIceTransportStateNew, ice.ConnectionStateNew},
|
||||
{RTCIceTransportStateChecking, ice.ConnectionStateChecking},
|
||||
{RTCIceTransportStateConnected, ice.ConnectionStateConnected},
|
||||
{RTCIceTransportStateCompleted, ice.ConnectionStateCompleted},
|
||||
{RTCIceTransportStateFailed, ice.ConnectionStateFailed},
|
||||
{RTCIceTransportStateDisconnected, ice.ConnectionStateDisconnected},
|
||||
{RTCIceTransportStateClosed, ice.ConnectionStateClosed},
|
||||
{ICETransportState(Unknown), ice.ConnectionState(Unknown)},
|
||||
{ICETransportStateNew, ice.ConnectionStateNew},
|
||||
{ICETransportStateChecking, ice.ConnectionStateChecking},
|
||||
{ICETransportStateConnected, ice.ConnectionStateConnected},
|
||||
{ICETransportStateCompleted, ice.ConnectionStateCompleted},
|
||||
{ICETransportStateFailed, ice.ConnectionStateFailed},
|
||||
{ICETransportStateDisconnected, ice.ConnectionStateDisconnected},
|
||||
{ICETransportStateClosed, ice.ConnectionStateClosed},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
@@ -54,7 +54,7 @@ func TestRTCIceTransportState_Convert(t *testing.T) {
|
||||
)
|
||||
assert.Equal(t,
|
||||
testCase.native,
|
||||
newRTCIceTransportStateFromICE(testCase.ice),
|
||||
newICETransportStateFromICE(testCase.ice),
|
||||
"testCase: %d %v", i, testCase,
|
||||
)
|
||||
}
|
||||
|
@@ -1,10 +1,10 @@
|
||||
package webrtc
|
||||
|
||||
// RTCOAuthCredential represents OAuth credential information which is used by
|
||||
// OAuthCredential represents OAuth credential information which is used by
|
||||
// the STUN/TURN client to connect to an ICE server as defined in
|
||||
// https://tools.ietf.org/html/rfc7635. Note that the kid parameter is not
|
||||
// located in RTCOAuthCredential, but in RTCIceServer's username member.
|
||||
type RTCOAuthCredential struct {
|
||||
// located in OAuthCredential, but in ICEServer's username member.
|
||||
type OAuthCredential struct {
|
||||
// MacKey is a base64-url encoded format. It is used in STUN message
|
||||
// integrity hash calculation.
|
||||
MacKey string
|
||||
|
@@ -1,26 +1,26 @@
|
||||
package webrtc
|
||||
|
||||
// RTCOfferAnswerOptions is a base structure which describes the options that
|
||||
// OfferAnswerOptions is a base structure which describes the options that
|
||||
// can be used to control the offer/answer creation process.
|
||||
type RTCOfferAnswerOptions struct {
|
||||
type OfferAnswerOptions struct {
|
||||
// VoiceActivityDetection allows the application to provide information
|
||||
// about whether it wishes voice detection feature to be enabled or disabled.
|
||||
VoiceActivityDetection bool
|
||||
}
|
||||
|
||||
// RTCAnswerOptions structure describes the options used to control the answer
|
||||
// AnswerOptions structure describes the options used to control the answer
|
||||
// creation process.
|
||||
type RTCAnswerOptions struct {
|
||||
RTCOfferAnswerOptions
|
||||
type AnswerOptions struct {
|
||||
OfferAnswerOptions
|
||||
}
|
||||
|
||||
// RTCOfferOptions structure describes the options used to control the offer
|
||||
// OfferOptions structure describes the options used to control the offer
|
||||
// creation process
|
||||
type RTCOfferOptions struct {
|
||||
RTCOfferAnswerOptions
|
||||
type OfferOptions struct {
|
||||
OfferAnswerOptions
|
||||
|
||||
// IceRestart forces the underlying ice gathering process to be restarted.
|
||||
// ICERestart forces the underlying ice gathering process to be restarted.
|
||||
// When this value is true, the generated description will have ICE
|
||||
// credentials that are different from the current credentials
|
||||
IceRestart bool
|
||||
ICERestart bool
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -7,10 +7,10 @@ import (
|
||||
"github.com/pions/transport/test"
|
||||
)
|
||||
|
||||
// TestRTCPeerConnection_Close is moved to it's on file because the tests
|
||||
// TestPeerConnection_Close is moved to it's on file because the tests
|
||||
// in rtcpeerconnection_test.go are leaky, making the goroutine report useless.
|
||||
|
||||
func TestRTCPeerConnection_Close(t *testing.T) {
|
||||
func TestPeerConnection_Close(t *testing.T) {
|
||||
api := NewAPI()
|
||||
|
||||
// Limit runtime in case of deadlocks
|
||||
@@ -26,7 +26,7 @@ func TestRTCPeerConnection_Close(t *testing.T) {
|
||||
}
|
||||
|
||||
awaitSetup := make(chan struct{})
|
||||
pcAnswer.OnDataChannel(func(d *RTCDataChannel) {
|
||||
pcAnswer.OnDataChannel(func(d *DataChannel) {
|
||||
close(awaitSetup)
|
||||
})
|
||||
|
||||
|
@@ -12,7 +12,7 @@ import (
|
||||
"github.com/pions/webrtc/pkg/media"
|
||||
)
|
||||
|
||||
func TestRTCPeerConnection_Media_Sample(t *testing.T) {
|
||||
func TestPeerConnection_Media_Sample(t *testing.T) {
|
||||
api := NewAPI()
|
||||
lim := test.TimeOut(time.Second * 30)
|
||||
defer lim.Stop()
|
||||
@@ -36,7 +36,7 @@ func TestRTCPeerConnection_Media_Sample(t *testing.T) {
|
||||
awaitRTCPRecieverRecv := make(chan bool)
|
||||
awaitRTCPRecieverSend := make(chan error)
|
||||
|
||||
pcAnswer.OnTrack(func(track *RTCTrack) {
|
||||
pcAnswer.OnTrack(func(track *Track) {
|
||||
go func() {
|
||||
for {
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
@@ -72,7 +72,7 @@ func TestRTCPeerConnection_Media_Sample(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
vp8Track, err := pcOffer.NewRTCSampleTrack(DefaultPayloadTypeVP8, "video", "pion")
|
||||
vp8Track, err := pcOffer.NewSampleTrack(DefaultPayloadTypeVP8, "video", "pion")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -83,7 +83,7 @@ func TestRTCPeerConnection_Media_Sample(t *testing.T) {
|
||||
go func() {
|
||||
for {
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
vp8Track.Samples <- media.RTCSample{Data: []byte{0x00}, Samples: 1}
|
||||
vp8Track.Samples <- media.Sample{Data: []byte{0x00}, Samples: 1}
|
||||
|
||||
select {
|
||||
case <-awaitRTPRecv:
|
||||
@@ -149,14 +149,14 @@ func TestRTCPeerConnection_Media_Sample(t *testing.T) {
|
||||
}
|
||||
|
||||
/*
|
||||
RTCPeerConnection should be able to be torn down at anytime
|
||||
PeerConnection should be able to be torn down at anytime
|
||||
This test adds an input track and asserts
|
||||
|
||||
* OnTrack doesn't fire since no video packets will arrive
|
||||
* No goroutine leaks
|
||||
* No deadlocks on shutdown
|
||||
*/
|
||||
func TestRTCPeerConnection_Media_Shutdown(t *testing.T) {
|
||||
func TestPeerConnection_Media_Shutdown(t *testing.T) {
|
||||
iceComplete := make(chan bool)
|
||||
|
||||
api := NewAPI()
|
||||
@@ -172,11 +172,11 @@ func TestRTCPeerConnection_Media_Shutdown(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
opusTrack, err := pcOffer.NewRTCSampleTrack(DefaultPayloadTypeOpus, "audio", "pion1")
|
||||
opusTrack, err := pcOffer.NewSampleTrack(DefaultPayloadTypeOpus, "audio", "pion1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
vp8Track, err := pcOffer.NewRTCSampleTrack(DefaultPayloadTypeVP8, "video", "pion2")
|
||||
vp8Track, err := pcOffer.NewSampleTrack(DefaultPayloadTypeVP8, "video", "pion2")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -190,7 +190,7 @@ func TestRTCPeerConnection_Media_Shutdown(t *testing.T) {
|
||||
var onTrackFiredLock sync.RWMutex
|
||||
onTrackFired := false
|
||||
|
||||
pcAnswer.OnTrack(func(track *RTCTrack) {
|
||||
pcAnswer.OnTrack(func(track *Track) {
|
||||
onTrackFiredLock.Lock()
|
||||
defer onTrackFiredLock.Unlock()
|
||||
onTrackFired = true
|
||||
@@ -199,7 +199,7 @@ func TestRTCPeerConnection_Media_Shutdown(t *testing.T) {
|
||||
pcAnswer.OnICEConnectionStateChange(func(iceState ice.ConnectionState) {
|
||||
if iceState == ice.ConnectionStateConnected {
|
||||
go func() {
|
||||
time.Sleep(3 * time.Second) // TODO RTCPeerConnection.Close() doesn't block for all subsystems
|
||||
time.Sleep(3 * time.Second) // TODO PeerConnection.Close() doesn't block for all subsystems
|
||||
close(iceComplete)
|
||||
}()
|
||||
}
|
||||
@@ -224,7 +224,7 @@ func TestRTCPeerConnection_Media_Shutdown(t *testing.T) {
|
||||
|
||||
onTrackFiredLock.Lock()
|
||||
if onTrackFired {
|
||||
t.Fatalf("RTCPeerConnection OnTrack fired even though we got no packets")
|
||||
t.Fatalf("PeerConnection OnTrack fired even though we got no packets")
|
||||
}
|
||||
onTrackFiredLock.Unlock()
|
||||
|
||||
|
@@ -17,13 +17,13 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func (api *API) newPair() (pcOffer *RTCPeerConnection, pcAnswer *RTCPeerConnection, err error) {
|
||||
pca, err := api.NewRTCPeerConnection(RTCConfiguration{})
|
||||
func (api *API) newPair() (pcOffer *PeerConnection, pcAnswer *PeerConnection, err error) {
|
||||
pca, err := api.NewPeerConnection(Configuration{})
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
pcb, err := api.NewRTCPeerConnection(RTCConfiguration{})
|
||||
pcb, err := api.NewPeerConnection(Configuration{})
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -31,7 +31,7 @@ func (api *API) newPair() (pcOffer *RTCPeerConnection, pcAnswer *RTCPeerConnecti
|
||||
return pca, pcb, nil
|
||||
}
|
||||
|
||||
func signalPair(pcOffer *RTCPeerConnection, pcAnswer *RTCPeerConnection) error {
|
||||
func signalPair(pcOffer *PeerConnection, pcAnswer *PeerConnection) error {
|
||||
offer, err := pcOffer.CreateOffer(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -72,41 +72,41 @@ func TestNew(t *testing.T) {
|
||||
certificate, err := GenerateCertificate(secretKey)
|
||||
assert.Nil(t, err)
|
||||
|
||||
pc, err := api.NewRTCPeerConnection(RTCConfiguration{
|
||||
IceServers: []RTCIceServer{
|
||||
pc, err := api.NewPeerConnection(Configuration{
|
||||
ICEServers: []ICEServer{
|
||||
{
|
||||
URLs: []string{
|
||||
"stun:stun.l.google.com:19302",
|
||||
"turns:google.de?transport=tcp",
|
||||
},
|
||||
Username: "unittest",
|
||||
Credential: RTCOAuthCredential{
|
||||
Credential: OAuthCredential{
|
||||
MacKey: "WmtzanB3ZW9peFhtdm42NzUzNG0=",
|
||||
AccessToken: "AAwg3kPHWPfvk9bDFL936wYvkoctMADzQ==",
|
||||
},
|
||||
CredentialType: RTCIceCredentialTypeOauth,
|
||||
CredentialType: ICECredentialTypeOauth,
|
||||
},
|
||||
},
|
||||
IceTransportPolicy: RTCIceTransportPolicyRelay,
|
||||
BundlePolicy: RTCBundlePolicyMaxCompat,
|
||||
RtcpMuxPolicy: RTCRtcpMuxPolicyNegotiate,
|
||||
ICETransportPolicy: ICETransportPolicyRelay,
|
||||
BundlePolicy: BundlePolicyMaxCompat,
|
||||
RTCPMuxPolicy: RTCPMuxPolicyNegotiate,
|
||||
PeerIdentity: "unittest",
|
||||
Certificates: []RTCCertificate{*certificate},
|
||||
IceCandidatePoolSize: 5,
|
||||
Certificates: []Certificate{*certificate},
|
||||
ICECandidatePoolSize: 5,
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, pc)
|
||||
})
|
||||
t.Run("Failure", func(t *testing.T) {
|
||||
testCases := []struct {
|
||||
initialize func() (*RTCPeerConnection, error)
|
||||
initialize func() (*PeerConnection, error)
|
||||
expectedErr error
|
||||
}{
|
||||
{func() (*RTCPeerConnection, error) {
|
||||
{func() (*PeerConnection, error) {
|
||||
secretKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
||||
assert.Nil(t, err)
|
||||
|
||||
certificate, err := NewRTCCertificate(secretKey, x509.Certificate{
|
||||
certificate, err := NewCertificate(secretKey, x509.Certificate{
|
||||
Version: 2,
|
||||
SerialNumber: big.NewInt(1653),
|
||||
NotBefore: time.Now().AddDate(0, -2, 0),
|
||||
@@ -114,13 +114,13 @@ func TestNew(t *testing.T) {
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
|
||||
return api.NewRTCPeerConnection(RTCConfiguration{
|
||||
Certificates: []RTCCertificate{*certificate},
|
||||
return api.NewPeerConnection(Configuration{
|
||||
Certificates: []Certificate{*certificate},
|
||||
})
|
||||
}, &rtcerr.InvalidAccessError{Err: ErrCertificateExpired}},
|
||||
{func() (*RTCPeerConnection, error) {
|
||||
return api.NewRTCPeerConnection(RTCConfiguration{
|
||||
IceServers: []RTCIceServer{
|
||||
{func() (*PeerConnection, error) {
|
||||
return api.NewPeerConnection(Configuration{
|
||||
ICEServers: []ICEServer{
|
||||
{
|
||||
URLs: []string{
|
||||
"stun:stun.l.google.com:19302",
|
||||
@@ -142,7 +142,7 @@ func TestNew(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestRTCPeerConnection_SetConfiguration(t *testing.T) {
|
||||
func TestPeerConnection_SetConfiguration(t *testing.T) {
|
||||
api := NewAPI()
|
||||
t.Run("Success", func(t *testing.T) {
|
||||
secretKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
||||
@@ -151,63 +151,63 @@ func TestRTCPeerConnection_SetConfiguration(t *testing.T) {
|
||||
certificate, err := GenerateCertificate(secretKey)
|
||||
assert.Nil(t, err)
|
||||
|
||||
pc, err := api.NewRTCPeerConnection(RTCConfiguration{
|
||||
pc, err := api.NewPeerConnection(Configuration{
|
||||
PeerIdentity: "unittest",
|
||||
Certificates: []RTCCertificate{*certificate},
|
||||
IceCandidatePoolSize: 5,
|
||||
Certificates: []Certificate{*certificate},
|
||||
ICECandidatePoolSize: 5,
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = pc.SetConfiguration(RTCConfiguration{
|
||||
IceServers: []RTCIceServer{
|
||||
err = pc.SetConfiguration(Configuration{
|
||||
ICEServers: []ICEServer{
|
||||
{
|
||||
URLs: []string{
|
||||
"stun:stun.l.google.com:19302",
|
||||
"turns:google.de?transport=tcp",
|
||||
},
|
||||
Username: "unittest",
|
||||
Credential: RTCOAuthCredential{
|
||||
Credential: OAuthCredential{
|
||||
MacKey: "WmtzanB3ZW9peFhtdm42NzUzNG0=",
|
||||
AccessToken: "AAwg3kPHWPfvk9bDFL936wYvkoctMADzQ==",
|
||||
},
|
||||
CredentialType: RTCIceCredentialTypeOauth,
|
||||
CredentialType: ICECredentialTypeOauth,
|
||||
},
|
||||
},
|
||||
IceTransportPolicy: RTCIceTransportPolicyAll,
|
||||
BundlePolicy: RTCBundlePolicyBalanced,
|
||||
RtcpMuxPolicy: RTCRtcpMuxPolicyRequire,
|
||||
ICETransportPolicy: ICETransportPolicyAll,
|
||||
BundlePolicy: BundlePolicyBalanced,
|
||||
RTCPMuxPolicy: RTCPMuxPolicyRequire,
|
||||
PeerIdentity: "unittest",
|
||||
Certificates: []RTCCertificate{*certificate},
|
||||
IceCandidatePoolSize: 5,
|
||||
Certificates: []Certificate{*certificate},
|
||||
ICECandidatePoolSize: 5,
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
t.Run("Failure", func(t *testing.T) {
|
||||
testCases := []struct {
|
||||
initialize func() (*RTCPeerConnection, error)
|
||||
updatingConfig func() RTCConfiguration
|
||||
initialize func() (*PeerConnection, error)
|
||||
updatingConfig func() Configuration
|
||||
expectedErr error
|
||||
}{
|
||||
{func() (*RTCPeerConnection, error) {
|
||||
pc, err := api.NewRTCPeerConnection(RTCConfiguration{})
|
||||
{func() (*PeerConnection, error) {
|
||||
pc, err := api.NewPeerConnection(Configuration{})
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = pc.Close()
|
||||
assert.Nil(t, err)
|
||||
return pc, err
|
||||
}, func() RTCConfiguration {
|
||||
return RTCConfiguration{}
|
||||
}, func() Configuration {
|
||||
return Configuration{}
|
||||
}, &rtcerr.InvalidStateError{Err: ErrConnectionClosed}},
|
||||
{func() (*RTCPeerConnection, error) {
|
||||
return api.NewRTCPeerConnection(RTCConfiguration{})
|
||||
}, func() RTCConfiguration {
|
||||
return RTCConfiguration{
|
||||
{func() (*PeerConnection, error) {
|
||||
return api.NewPeerConnection(Configuration{})
|
||||
}, func() Configuration {
|
||||
return Configuration{
|
||||
PeerIdentity: "unittest",
|
||||
}
|
||||
}, &rtcerr.InvalidModificationError{Err: ErrModifyingPeerIdentity}},
|
||||
{func() (*RTCPeerConnection, error) {
|
||||
return api.NewRTCPeerConnection(RTCConfiguration{})
|
||||
}, func() RTCConfiguration {
|
||||
{func() (*PeerConnection, error) {
|
||||
return api.NewPeerConnection(Configuration{})
|
||||
}, func() Configuration {
|
||||
secretKey1, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
||||
assert.Nil(t, err)
|
||||
|
||||
@@ -220,43 +220,43 @@ func TestRTCPeerConnection_SetConfiguration(t *testing.T) {
|
||||
certificate2, err := GenerateCertificate(secretKey2)
|
||||
assert.Nil(t, err)
|
||||
|
||||
return RTCConfiguration{
|
||||
Certificates: []RTCCertificate{*certificate1, *certificate2},
|
||||
return Configuration{
|
||||
Certificates: []Certificate{*certificate1, *certificate2},
|
||||
}
|
||||
}, &rtcerr.InvalidModificationError{Err: ErrModifyingCertificates}},
|
||||
{func() (*RTCPeerConnection, error) {
|
||||
return api.NewRTCPeerConnection(RTCConfiguration{})
|
||||
}, func() RTCConfiguration {
|
||||
{func() (*PeerConnection, error) {
|
||||
return api.NewPeerConnection(Configuration{})
|
||||
}, func() Configuration {
|
||||
secretKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
||||
assert.Nil(t, err)
|
||||
|
||||
certificate, err := GenerateCertificate(secretKey)
|
||||
assert.Nil(t, err)
|
||||
|
||||
return RTCConfiguration{
|
||||
Certificates: []RTCCertificate{*certificate},
|
||||
return Configuration{
|
||||
Certificates: []Certificate{*certificate},
|
||||
}
|
||||
}, &rtcerr.InvalidModificationError{Err: ErrModifyingCertificates}},
|
||||
{func() (*RTCPeerConnection, error) {
|
||||
return api.NewRTCPeerConnection(RTCConfiguration{})
|
||||
}, func() RTCConfiguration {
|
||||
return RTCConfiguration{
|
||||
BundlePolicy: RTCBundlePolicyMaxCompat,
|
||||
{func() (*PeerConnection, error) {
|
||||
return api.NewPeerConnection(Configuration{})
|
||||
}, func() Configuration {
|
||||
return Configuration{
|
||||
BundlePolicy: BundlePolicyMaxCompat,
|
||||
}
|
||||
}, &rtcerr.InvalidModificationError{Err: ErrModifyingBundlePolicy}},
|
||||
{func() (*RTCPeerConnection, error) {
|
||||
return api.NewRTCPeerConnection(RTCConfiguration{})
|
||||
}, func() RTCConfiguration {
|
||||
return RTCConfiguration{
|
||||
RtcpMuxPolicy: RTCRtcpMuxPolicyNegotiate,
|
||||
{func() (*PeerConnection, error) {
|
||||
return api.NewPeerConnection(Configuration{})
|
||||
}, func() Configuration {
|
||||
return Configuration{
|
||||
RTCPMuxPolicy: RTCPMuxPolicyNegotiate,
|
||||
}
|
||||
}, &rtcerr.InvalidModificationError{Err: ErrModifyingRtcpMuxPolicy}},
|
||||
// TODO Unittest for IceCandidatePoolSize cannot be done now needs pc.LocalDescription()
|
||||
{func() (*RTCPeerConnection, error) {
|
||||
return api.NewRTCPeerConnection(RTCConfiguration{})
|
||||
}, func() RTCConfiguration {
|
||||
return RTCConfiguration{
|
||||
IceServers: []RTCIceServer{
|
||||
}, &rtcerr.InvalidModificationError{Err: ErrModifyingRTCPMuxPolicy}},
|
||||
// TODO Unittest for ICECandidatePoolSize cannot be done now needs pc.LocalDescription()
|
||||
{func() (*PeerConnection, error) {
|
||||
return api.NewPeerConnection(Configuration{})
|
||||
}, func() Configuration {
|
||||
return Configuration{
|
||||
ICEServers: []ICEServer{
|
||||
{
|
||||
URLs: []string{
|
||||
"stun:stun.l.google.com:19302",
|
||||
@@ -281,35 +281,35 @@ func TestRTCPeerConnection_SetConfiguration(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestRTCPeerConnection_GetConfiguration(t *testing.T) {
|
||||
func TestPeerConnection_GetConfiguration(t *testing.T) {
|
||||
api := NewAPI()
|
||||
pc, err := api.NewRTCPeerConnection(RTCConfiguration{})
|
||||
pc, err := api.NewPeerConnection(Configuration{})
|
||||
assert.Nil(t, err)
|
||||
|
||||
expected := RTCConfiguration{
|
||||
IceServers: []RTCIceServer{},
|
||||
IceTransportPolicy: RTCIceTransportPolicyAll,
|
||||
BundlePolicy: RTCBundlePolicyBalanced,
|
||||
RtcpMuxPolicy: RTCRtcpMuxPolicyRequire,
|
||||
Certificates: []RTCCertificate{},
|
||||
IceCandidatePoolSize: 0,
|
||||
expected := Configuration{
|
||||
ICEServers: []ICEServer{},
|
||||
ICETransportPolicy: ICETransportPolicyAll,
|
||||
BundlePolicy: BundlePolicyBalanced,
|
||||
RTCPMuxPolicy: RTCPMuxPolicyRequire,
|
||||
Certificates: []Certificate{},
|
||||
ICECandidatePoolSize: 0,
|
||||
}
|
||||
actual := pc.GetConfiguration()
|
||||
assert.True(t, &expected != &actual)
|
||||
assert.Equal(t, expected.IceServers, actual.IceServers)
|
||||
assert.Equal(t, expected.IceTransportPolicy, actual.IceTransportPolicy)
|
||||
assert.Equal(t, expected.ICEServers, actual.ICEServers)
|
||||
assert.Equal(t, expected.ICETransportPolicy, actual.ICETransportPolicy)
|
||||
assert.Equal(t, expected.BundlePolicy, actual.BundlePolicy)
|
||||
assert.Equal(t, expected.RtcpMuxPolicy, actual.RtcpMuxPolicy)
|
||||
assert.Equal(t, expected.RTCPMuxPolicy, actual.RTCPMuxPolicy)
|
||||
assert.NotEqual(t, len(expected.Certificates), len(actual.Certificates))
|
||||
assert.Equal(t, expected.IceCandidatePoolSize, actual.IceCandidatePoolSize)
|
||||
assert.Equal(t, expected.ICECandidatePoolSize, actual.ICECandidatePoolSize)
|
||||
}
|
||||
|
||||
// TODO - This unittest needs to be completed when CreateDataChannel is complete
|
||||
// func TestRTCPeerConnection_CreateDataChannel(t *testing.T) {
|
||||
// pc, err := New(RTCConfiguration{})
|
||||
// func TestPeerConnection_CreateDataChannel(t *testing.T) {
|
||||
// pc, err := New(Configuration{})
|
||||
// assert.Nil(t, err)
|
||||
//
|
||||
// _, err = pc.CreateDataChannel("data", &RTCDataChannelInit{
|
||||
// _, err = pc.CreateDataChannel("data", &DataChannelInit{
|
||||
//
|
||||
// })
|
||||
// assert.Nil(t, err)
|
||||
@@ -336,13 +336,13 @@ a=rtpmap:96 VP8/90000
|
||||
func TestSetRemoteDescription(t *testing.T) {
|
||||
api := NewAPI()
|
||||
testCases := []struct {
|
||||
desc RTCSessionDescription
|
||||
desc SessionDescription
|
||||
}{
|
||||
{RTCSessionDescription{Type: RTCSdpTypeOffer, Sdp: minimalOffer}},
|
||||
{SessionDescription{Type: SDPTypeOffer, Sdp: minimalOffer}},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
peerConn, err := api.NewRTCPeerConnection(RTCConfiguration{})
|
||||
peerConn, err := api.NewPeerConnection(Configuration{})
|
||||
if err != nil {
|
||||
t.Errorf("Case %d: got error: %v", i, err)
|
||||
}
|
||||
@@ -355,9 +355,9 @@ func TestSetRemoteDescription(t *testing.T) {
|
||||
|
||||
func TestCreateOfferAnswer(t *testing.T) {
|
||||
api := NewAPI()
|
||||
offerPeerConn, err := api.NewRTCPeerConnection(RTCConfiguration{})
|
||||
offerPeerConn, err := api.NewPeerConnection(Configuration{})
|
||||
if err != nil {
|
||||
t.Errorf("New RTCPeerConnection: got error: %v", err)
|
||||
t.Errorf("New PeerConnection: got error: %v", err)
|
||||
}
|
||||
offer, err := offerPeerConn.CreateOffer(nil)
|
||||
if err != nil {
|
||||
@@ -366,9 +366,9 @@ func TestCreateOfferAnswer(t *testing.T) {
|
||||
if err = offerPeerConn.SetLocalDescription(offer); err != nil {
|
||||
t.Errorf("SetLocalDescription: got error: %v", err)
|
||||
}
|
||||
answerPeerConn, err := api.NewRTCPeerConnection(RTCConfiguration{})
|
||||
answerPeerConn, err := api.NewPeerConnection(Configuration{})
|
||||
if err != nil {
|
||||
t.Errorf("New RTCPeerConnection: got error: %v", err)
|
||||
t.Errorf("New PeerConnection: got error: %v", err)
|
||||
}
|
||||
err = answerPeerConn.SetRemoteDescription(offer)
|
||||
if err != nil {
|
||||
@@ -387,11 +387,11 @@ func TestCreateOfferAnswer(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRTCPeerConnection_NewRawRTPTrack(t *testing.T) {
|
||||
func TestPeerConnection_NewRawRTPTrack(t *testing.T) {
|
||||
api := NewAPI()
|
||||
api.mediaEngine.RegisterDefaultCodecs()
|
||||
|
||||
pc, err := api.NewRTCPeerConnection(RTCConfiguration{})
|
||||
pc, err := api.NewPeerConnection(Configuration{})
|
||||
assert.Nil(t, err)
|
||||
|
||||
_, err = pc.NewRawRTPTrack(DefaultPayloadTypeH264, 0, "trackId", "trackLabel")
|
||||
@@ -405,7 +405,7 @@ func TestRTCPeerConnection_NewRawRTPTrack(t *testing.T) {
|
||||
|
||||
// This channel should not be set up for a RawRTP track
|
||||
assert.Panics(t, func() {
|
||||
track.Samples <- media.RTCSample{}
|
||||
track.Samples <- media.Sample{}
|
||||
})
|
||||
|
||||
assert.NotPanics(t, func() {
|
||||
@@ -413,32 +413,32 @@ func TestRTCPeerConnection_NewRawRTPTrack(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestRTCPeerConnection_NewRTCSampleTrack(t *testing.T) {
|
||||
func TestPeerConnection_NewSampleTrack(t *testing.T) {
|
||||
api := NewAPI()
|
||||
api.mediaEngine.RegisterDefaultCodecs()
|
||||
|
||||
pc, err := api.NewRTCPeerConnection(RTCConfiguration{})
|
||||
pc, err := api.NewPeerConnection(Configuration{})
|
||||
assert.Nil(t, err)
|
||||
|
||||
track, err := pc.NewRTCSampleTrack(DefaultPayloadTypeH264, "trackId", "trackLabel")
|
||||
track, err := pc.NewSampleTrack(DefaultPayloadTypeH264, "trackId", "trackLabel")
|
||||
assert.Nil(t, err)
|
||||
|
||||
_, err = pc.AddTrack(track)
|
||||
assert.Nil(t, err)
|
||||
|
||||
// This channel should not be set up for a RTCSample track
|
||||
// This channel should not be set up for a Sample track
|
||||
assert.Panics(t, func() {
|
||||
track.RawRTP <- &rtp.Packet{}
|
||||
})
|
||||
|
||||
assert.NotPanics(t, func() {
|
||||
track.Samples <- media.RTCSample{}
|
||||
track.Samples <- media.Sample{}
|
||||
})
|
||||
}
|
||||
|
||||
func TestRTCPeerConnection_EventHandlers(t *testing.T) {
|
||||
func TestPeerConnection_EventHandlers(t *testing.T) {
|
||||
api := NewAPI()
|
||||
pc, err := api.NewRTCPeerConnection(RTCConfiguration{})
|
||||
pc, err := api.NewPeerConnection(Configuration{})
|
||||
assert.Nil(t, err)
|
||||
|
||||
onTrackCalled := make(chan bool)
|
||||
@@ -449,7 +449,7 @@ func TestRTCPeerConnection_EventHandlers(t *testing.T) {
|
||||
assert.NotPanics(t, func() { pc.onTrack(nil) })
|
||||
assert.NotPanics(t, func() { pc.onICEConnectionStateChange(ice.ConnectionStateNew) })
|
||||
|
||||
pc.OnTrack(func(t *RTCTrack) {
|
||||
pc.OnTrack(func(t *Track) {
|
||||
onTrackCalled <- true
|
||||
})
|
||||
|
||||
@@ -457,7 +457,7 @@ func TestRTCPeerConnection_EventHandlers(t *testing.T) {
|
||||
onICEConnectionStateChangeCalled <- true
|
||||
})
|
||||
|
||||
pc.OnDataChannel(func(dc *RTCDataChannel) {
|
||||
pc.OnDataChannel(func(dc *DataChannel) {
|
||||
onDataChannelCalled <- true
|
||||
})
|
||||
|
||||
@@ -466,9 +466,9 @@ func TestRTCPeerConnection_EventHandlers(t *testing.T) {
|
||||
assert.NotPanics(t, func() { go pc.onDataChannelHandler(nil) })
|
||||
|
||||
// Verify that the set handlers are called
|
||||
assert.NotPanics(t, func() { pc.onTrack(&RTCTrack{}) })
|
||||
assert.NotPanics(t, func() { pc.onTrack(&Track{}) })
|
||||
assert.NotPanics(t, func() { pc.onICEConnectionStateChange(ice.ConnectionStateNew) })
|
||||
assert.NotPanics(t, func() { go pc.onDataChannelHandler(&RTCDataChannel{api: api}) })
|
||||
assert.NotPanics(t, func() { go pc.onDataChannelHandler(&DataChannel{api: api}) })
|
||||
|
||||
allTrue := func(vals []bool) bool {
|
||||
for _, val := range vals {
|
||||
|
@@ -1,82 +1,82 @@
|
||||
package webrtc
|
||||
|
||||
// RTCPeerConnectionState indicates the state of the RTCPeerConnection.
|
||||
type RTCPeerConnectionState int
|
||||
// PeerConnectionState indicates the state of the PeerConnection.
|
||||
type PeerConnectionState int
|
||||
|
||||
const (
|
||||
// RTCPeerConnectionStateNew indicates that any of the RTCIceTransports or
|
||||
// RTCDtlsTransports are in the "new" state and none of the transports are
|
||||
// PeerConnectionStateNew indicates that any of the ICETransports or
|
||||
// DTLSTransports are in the "new" state and none of the transports are
|
||||
// in the "connecting", "checking", "failed" or "disconnected" state, or
|
||||
// all transports are in the "closed" state, or there are no transports.
|
||||
RTCPeerConnectionStateNew RTCPeerConnectionState = iota + 1
|
||||
PeerConnectionStateNew PeerConnectionState = iota + 1
|
||||
|
||||
// RTCPeerConnectionStateConnecting indicates that any of the
|
||||
// RTCIceTransports or RTCDtlsTransports are in the "connecting" or
|
||||
// PeerConnectionStateConnecting indicates that any of the
|
||||
// ICETransports or DTLSTransports are in the "connecting" or
|
||||
// "checking" state and none of them is in the "failed" state.
|
||||
RTCPeerConnectionStateConnecting
|
||||
PeerConnectionStateConnecting
|
||||
|
||||
// RTCPeerConnectionStateConnected indicates that all RTCIceTransports and
|
||||
// RTCDtlsTransports are in the "connected", "completed" or "closed" state
|
||||
// PeerConnectionStateConnected indicates that all ICETransports and
|
||||
// DTLSTransports are in the "connected", "completed" or "closed" state
|
||||
// and at least one of them is in the "connected" or "completed" state.
|
||||
RTCPeerConnectionStateConnected
|
||||
PeerConnectionStateConnected
|
||||
|
||||
// RTCPeerConnectionStateDisconnected indicates that any of the
|
||||
// RTCIceTransports or RTCDtlsTransports are in the "disconnected" state
|
||||
// PeerConnectionStateDisconnected indicates that any of the
|
||||
// ICETransports or DTLSTransports are in the "disconnected" state
|
||||
// and none of them are in the "failed" or "connecting" or "checking" state.
|
||||
RTCPeerConnectionStateDisconnected
|
||||
PeerConnectionStateDisconnected
|
||||
|
||||
// RTCPeerConnectionStateFailed indicates that any of the RTCIceTransports
|
||||
// or RTCDtlsTransports are in a "failed" state.
|
||||
RTCPeerConnectionStateFailed
|
||||
// PeerConnectionStateFailed indicates that any of the ICETransports
|
||||
// or DTLSTransports are in a "failed" state.
|
||||
PeerConnectionStateFailed
|
||||
|
||||
// RTCPeerConnectionStateClosed indicates the peer connection is closed
|
||||
// and the isClosed member variable of RTCPeerConnection is true.
|
||||
RTCPeerConnectionStateClosed
|
||||
// PeerConnectionStateClosed indicates the peer connection is closed
|
||||
// and the isClosed member variable of PeerConnection is true.
|
||||
PeerConnectionStateClosed
|
||||
)
|
||||
|
||||
// This is done this way because of a linter.
|
||||
const (
|
||||
rtcPeerConnectionStateNewStr = "new"
|
||||
rtcPeerConnectionStateConnectingStr = "connecting"
|
||||
rtcPeerConnectionStateConnectedStr = "connected"
|
||||
rtcPeerConnectionStateDisconnectedStr = "disconnected"
|
||||
rtcPeerConnectionStateFailedStr = "failed"
|
||||
rtcPeerConnectionStateClosedStr = "closed"
|
||||
peerConnectionStateNewStr = "new"
|
||||
peerConnectionStateConnectingStr = "connecting"
|
||||
peerConnectionStateConnectedStr = "connected"
|
||||
peerConnectionStateDisconnectedStr = "disconnected"
|
||||
peerConnectionStateFailedStr = "failed"
|
||||
peerConnectionStateClosedStr = "closed"
|
||||
)
|
||||
|
||||
func newRTCPeerConnectionState(raw string) RTCPeerConnectionState {
|
||||
func newPeerConnectionState(raw string) PeerConnectionState {
|
||||
switch raw {
|
||||
case rtcPeerConnectionStateNewStr:
|
||||
return RTCPeerConnectionStateNew
|
||||
case rtcPeerConnectionStateConnectingStr:
|
||||
return RTCPeerConnectionStateConnecting
|
||||
case rtcPeerConnectionStateConnectedStr:
|
||||
return RTCPeerConnectionStateConnected
|
||||
case rtcPeerConnectionStateDisconnectedStr:
|
||||
return RTCPeerConnectionStateDisconnected
|
||||
case rtcPeerConnectionStateFailedStr:
|
||||
return RTCPeerConnectionStateFailed
|
||||
case rtcPeerConnectionStateClosedStr:
|
||||
return RTCPeerConnectionStateClosed
|
||||
case peerConnectionStateNewStr:
|
||||
return PeerConnectionStateNew
|
||||
case peerConnectionStateConnectingStr:
|
||||
return PeerConnectionStateConnecting
|
||||
case peerConnectionStateConnectedStr:
|
||||
return PeerConnectionStateConnected
|
||||
case peerConnectionStateDisconnectedStr:
|
||||
return PeerConnectionStateDisconnected
|
||||
case peerConnectionStateFailedStr:
|
||||
return PeerConnectionStateFailed
|
||||
case peerConnectionStateClosedStr:
|
||||
return PeerConnectionStateClosed
|
||||
default:
|
||||
return RTCPeerConnectionState(Unknown)
|
||||
return PeerConnectionState(Unknown)
|
||||
}
|
||||
}
|
||||
|
||||
func (t RTCPeerConnectionState) String() string {
|
||||
func (t PeerConnectionState) String() string {
|
||||
switch t {
|
||||
case RTCPeerConnectionStateNew:
|
||||
return rtcPeerConnectionStateNewStr
|
||||
case RTCPeerConnectionStateConnecting:
|
||||
return rtcPeerConnectionStateConnectingStr
|
||||
case RTCPeerConnectionStateConnected:
|
||||
return rtcPeerConnectionStateConnectedStr
|
||||
case RTCPeerConnectionStateDisconnected:
|
||||
return rtcPeerConnectionStateDisconnectedStr
|
||||
case RTCPeerConnectionStateFailed:
|
||||
return rtcPeerConnectionStateFailedStr
|
||||
case RTCPeerConnectionStateClosed:
|
||||
return rtcPeerConnectionStateClosedStr
|
||||
case PeerConnectionStateNew:
|
||||
return peerConnectionStateNewStr
|
||||
case PeerConnectionStateConnecting:
|
||||
return peerConnectionStateConnectingStr
|
||||
case PeerConnectionStateConnected:
|
||||
return peerConnectionStateConnectedStr
|
||||
case PeerConnectionStateDisconnected:
|
||||
return peerConnectionStateDisconnectedStr
|
||||
case PeerConnectionStateFailed:
|
||||
return peerConnectionStateFailedStr
|
||||
case PeerConnectionStateClosed:
|
||||
return peerConnectionStateClosedStr
|
||||
default:
|
||||
return ErrUnknownType.Error()
|
||||
}
|
||||
|
@@ -6,41 +6,41 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewRTCPeerConnectionState(t *testing.T) {
|
||||
func TestNewPeerConnectionState(t *testing.T) {
|
||||
testCases := []struct {
|
||||
stateString string
|
||||
expectedState RTCPeerConnectionState
|
||||
expectedState PeerConnectionState
|
||||
}{
|
||||
{unknownStr, RTCPeerConnectionState(Unknown)},
|
||||
{"new", RTCPeerConnectionStateNew},
|
||||
{"connecting", RTCPeerConnectionStateConnecting},
|
||||
{"connected", RTCPeerConnectionStateConnected},
|
||||
{"disconnected", RTCPeerConnectionStateDisconnected},
|
||||
{"failed", RTCPeerConnectionStateFailed},
|
||||
{"closed", RTCPeerConnectionStateClosed},
|
||||
{unknownStr, PeerConnectionState(Unknown)},
|
||||
{"new", PeerConnectionStateNew},
|
||||
{"connecting", PeerConnectionStateConnecting},
|
||||
{"connected", PeerConnectionStateConnected},
|
||||
{"disconnected", PeerConnectionStateDisconnected},
|
||||
{"failed", PeerConnectionStateFailed},
|
||||
{"closed", PeerConnectionStateClosed},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
assert.Equal(t,
|
||||
testCase.expectedState,
|
||||
newRTCPeerConnectionState(testCase.stateString),
|
||||
newPeerConnectionState(testCase.stateString),
|
||||
"testCase: %d %v", i, testCase,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRTCPeerConnectionState_String(t *testing.T) {
|
||||
func TestPeerConnectionState_String(t *testing.T) {
|
||||
testCases := []struct {
|
||||
state RTCPeerConnectionState
|
||||
state PeerConnectionState
|
||||
expectedString string
|
||||
}{
|
||||
{RTCPeerConnectionState(Unknown), unknownStr},
|
||||
{RTCPeerConnectionStateNew, "new"},
|
||||
{RTCPeerConnectionStateConnecting, "connecting"},
|
||||
{RTCPeerConnectionStateConnected, "connected"},
|
||||
{RTCPeerConnectionStateDisconnected, "disconnected"},
|
||||
{RTCPeerConnectionStateFailed, "failed"},
|
||||
{RTCPeerConnectionStateClosed, "closed"},
|
||||
{PeerConnectionState(Unknown), unknownStr},
|
||||
{PeerConnectionStateNew, "new"},
|
||||
{PeerConnectionStateConnecting, "connecting"},
|
||||
{PeerConnectionStateConnected, "connected"},
|
||||
{PeerConnectionStateDisconnected, "disconnected"},
|
||||
{PeerConnectionStateFailed, "failed"},
|
||||
{PeerConnectionStateClosed, "closed"},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
|
@@ -1,70 +1,70 @@
|
||||
package webrtc
|
||||
|
||||
// RTCPriorityType determines the priority type of a data channel.
|
||||
type RTCPriorityType int
|
||||
// PriorityType determines the priority type of a data channel.
|
||||
type PriorityType int
|
||||
|
||||
const (
|
||||
// RTCPriorityTypeVeryLow corresponds to "below normal".
|
||||
RTCPriorityTypeVeryLow RTCPriorityType = iota + 1
|
||||
// PriorityTypeVeryLow corresponds to "below normal".
|
||||
PriorityTypeVeryLow PriorityType = iota + 1
|
||||
|
||||
// RTCPriorityTypeLow corresponds to "normal".
|
||||
RTCPriorityTypeLow
|
||||
// PriorityTypeLow corresponds to "normal".
|
||||
PriorityTypeLow
|
||||
|
||||
// RTCPriorityTypeMedium corresponds to "high".
|
||||
RTCPriorityTypeMedium
|
||||
// PriorityTypeMedium corresponds to "high".
|
||||
PriorityTypeMedium
|
||||
|
||||
// RTCPriorityTypeHigh corresponds to "extra high".
|
||||
RTCPriorityTypeHigh
|
||||
// PriorityTypeHigh corresponds to "extra high".
|
||||
PriorityTypeHigh
|
||||
)
|
||||
|
||||
// This is done this way because of a linter.
|
||||
const (
|
||||
rtcPriorityTypeVeryLowStr = "very-low"
|
||||
rtcPriorityTypeLowStr = "low"
|
||||
rtcPriorityTypeMediumStr = "medium"
|
||||
rtcPriorityTypeHighStr = "high"
|
||||
priorityTypeVeryLowStr = "very-low"
|
||||
priorityTypeLowStr = "low"
|
||||
priorityTypeMediumStr = "medium"
|
||||
priorityTypeHighStr = "high"
|
||||
)
|
||||
|
||||
func newRTCPriorityTypeFromString(raw string) RTCPriorityType {
|
||||
func newPriorityTypeFromString(raw string) PriorityType {
|
||||
switch raw {
|
||||
case rtcPriorityTypeVeryLowStr:
|
||||
return RTCPriorityTypeVeryLow
|
||||
case rtcPriorityTypeLowStr:
|
||||
return RTCPriorityTypeLow
|
||||
case rtcPriorityTypeMediumStr:
|
||||
return RTCPriorityTypeMedium
|
||||
case rtcPriorityTypeHighStr:
|
||||
return RTCPriorityTypeHigh
|
||||
case priorityTypeVeryLowStr:
|
||||
return PriorityTypeVeryLow
|
||||
case priorityTypeLowStr:
|
||||
return PriorityTypeLow
|
||||
case priorityTypeMediumStr:
|
||||
return PriorityTypeMedium
|
||||
case priorityTypeHighStr:
|
||||
return PriorityTypeHigh
|
||||
default:
|
||||
return RTCPriorityType(Unknown)
|
||||
return PriorityType(Unknown)
|
||||
}
|
||||
}
|
||||
|
||||
func newRTCPriorityTypeFromUint16(raw uint16) RTCPriorityType {
|
||||
func newPriorityTypeFromUint16(raw uint16) PriorityType {
|
||||
switch {
|
||||
case raw <= 128:
|
||||
return RTCPriorityTypeVeryLow
|
||||
return PriorityTypeVeryLow
|
||||
case 129 <= raw && raw <= 256:
|
||||
return RTCPriorityTypeLow
|
||||
return PriorityTypeLow
|
||||
case 257 <= raw && raw <= 512:
|
||||
return RTCPriorityTypeMedium
|
||||
return PriorityTypeMedium
|
||||
case 513 <= raw:
|
||||
return RTCPriorityTypeHigh
|
||||
return PriorityTypeHigh
|
||||
default:
|
||||
return RTCPriorityType(Unknown)
|
||||
return PriorityType(Unknown)
|
||||
}
|
||||
}
|
||||
|
||||
func (p RTCPriorityType) String() string {
|
||||
func (p PriorityType) String() string {
|
||||
switch p {
|
||||
case RTCPriorityTypeVeryLow:
|
||||
return rtcPriorityTypeVeryLowStr
|
||||
case RTCPriorityTypeLow:
|
||||
return rtcPriorityTypeLowStr
|
||||
case RTCPriorityTypeMedium:
|
||||
return rtcPriorityTypeMediumStr
|
||||
case RTCPriorityTypeHigh:
|
||||
return rtcPriorityTypeHighStr
|
||||
case PriorityTypeVeryLow:
|
||||
return priorityTypeVeryLowStr
|
||||
case PriorityTypeLow:
|
||||
return priorityTypeLowStr
|
||||
case PriorityTypeMedium:
|
||||
return priorityTypeMediumStr
|
||||
case PriorityTypeHigh:
|
||||
return priorityTypeHighStr
|
||||
default:
|
||||
return ErrUnknownType.Error()
|
||||
}
|
||||
|
@@ -6,49 +6,49 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewRTCPriorityType(t *testing.T) {
|
||||
func TestNewPriorityType(t *testing.T) {
|
||||
testCases := []struct {
|
||||
priorityString string
|
||||
priorityUint16 uint16
|
||||
expectedPriority RTCPriorityType
|
||||
expectedPriority PriorityType
|
||||
}{
|
||||
{unknownStr, 0, RTCPriorityType(Unknown)},
|
||||
{"very-low", 100, RTCPriorityTypeVeryLow},
|
||||
{"low", 200, RTCPriorityTypeLow},
|
||||
{"medium", 300, RTCPriorityTypeMedium},
|
||||
{"high", 1000, RTCPriorityTypeHigh},
|
||||
{unknownStr, 0, PriorityType(Unknown)},
|
||||
{"very-low", 100, PriorityTypeVeryLow},
|
||||
{"low", 200, PriorityTypeLow},
|
||||
{"medium", 300, PriorityTypeMedium},
|
||||
{"high", 1000, PriorityTypeHigh},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
assert.Equal(t,
|
||||
testCase.expectedPriority,
|
||||
newRTCPriorityTypeFromString(testCase.priorityString),
|
||||
newPriorityTypeFromString(testCase.priorityString),
|
||||
"testCase: %d %v", i, testCase,
|
||||
)
|
||||
|
||||
// There is no uint that produces generate RTCPriorityType(Unknown).
|
||||
// There is no uint that produces generate PriorityType(Unknown).
|
||||
if i == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
assert.Equal(t,
|
||||
testCase.expectedPriority,
|
||||
newRTCPriorityTypeFromUint16(testCase.priorityUint16),
|
||||
newPriorityTypeFromUint16(testCase.priorityUint16),
|
||||
"testCase: %d %v", i, testCase,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRTCPriorityType_String(t *testing.T) {
|
||||
func TestPriorityType_String(t *testing.T) {
|
||||
testCases := []struct {
|
||||
priority RTCPriorityType
|
||||
priority PriorityType
|
||||
expectedString string
|
||||
}{
|
||||
{RTCPriorityType(Unknown), unknownStr},
|
||||
{RTCPriorityTypeVeryLow, "very-low"},
|
||||
{RTCPriorityTypeLow, "low"},
|
||||
{RTCPriorityTypeMedium, "medium"},
|
||||
{RTCPriorityTypeHigh, "high"},
|
||||
{PriorityType(Unknown), unknownStr},
|
||||
{PriorityTypeVeryLow, "very-low"},
|
||||
{PriorityTypeLow, "low"},
|
||||
{PriorityTypeMedium, "medium"},
|
||||
{PriorityTypeHigh, "high"},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package webrtc
|
||||
|
||||
// RTCQuicParameters holds information relating to QUIC configuration.
|
||||
type RTCQuicParameters struct {
|
||||
Role RTCQuicRole `json:"role"`
|
||||
Fingerprints []RTCDtlsFingerprint `json:"fingerprints"`
|
||||
// QUICParameters holds information relating to QUIC configuration.
|
||||
type QUICParameters struct {
|
||||
Role QUICRole `json:"role"`
|
||||
Fingerprints []DTLSFingerprint `json:"fingerprints"`
|
||||
}
|
||||
|
@@ -1,28 +1,28 @@
|
||||
package webrtc
|
||||
|
||||
// RTCQuicRole indicates the role of the Quic transport.
|
||||
type RTCQuicRole byte
|
||||
// QUICRole indicates the role of the Quic transport.
|
||||
type QUICRole byte
|
||||
|
||||
const (
|
||||
// RTCQuicRoleAuto defines the Quic role is determined based on
|
||||
// QUICRoleAuto defines the Quic role is determined based on
|
||||
// the resolved ICE role: the ICE controlled role acts as the Quic
|
||||
// client and the ICE controlling role acts as the Quic server.
|
||||
RTCQuicRoleAuto RTCQuicRole = iota + 1
|
||||
QUICRoleAuto QUICRole = iota + 1
|
||||
|
||||
// RTCQuicRoleClient defines the Quic client role.
|
||||
RTCQuicRoleClient
|
||||
// QUICRoleClient defines the Quic client role.
|
||||
QUICRoleClient
|
||||
|
||||
// RTCQuicRoleServer defines the Quic server role.
|
||||
RTCQuicRoleServer
|
||||
// QUICRoleServer defines the Quic server role.
|
||||
QUICRoleServer
|
||||
)
|
||||
|
||||
func (r RTCQuicRole) String() string {
|
||||
func (r QUICRole) String() string {
|
||||
switch r {
|
||||
case RTCQuicRoleAuto:
|
||||
case QUICRoleAuto:
|
||||
return "auto"
|
||||
case RTCQuicRoleClient:
|
||||
case QUICRoleClient:
|
||||
return "client"
|
||||
case RTCQuicRoleServer:
|
||||
case QUICRoleServer:
|
||||
return "server"
|
||||
default:
|
||||
return unknownStr
|
||||
|
@@ -6,15 +6,15 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRTCQuicRole_String(t *testing.T) {
|
||||
func TestQUICRole_String(t *testing.T) {
|
||||
testCases := []struct {
|
||||
role RTCQuicRole
|
||||
role QUICRole
|
||||
expectedString string
|
||||
}{
|
||||
{RTCQuicRole(Unknown), unknownStr},
|
||||
{RTCQuicRoleAuto, "auto"},
|
||||
{RTCQuicRoleClient, "client"},
|
||||
{RTCQuicRoleServer, "server"},
|
||||
{QUICRole(Unknown), unknownStr},
|
||||
{QUICRoleAuto, "auto"},
|
||||
{QUICRoleClient, "client"},
|
||||
{QUICRoleServer, "server"},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
|
@@ -17,25 +17,25 @@ import (
|
||||
"github.com/pions/webrtc/pkg/rtcerr"
|
||||
)
|
||||
|
||||
// RTCQuicTransport is a specialization of QuicTransportBase focused on
|
||||
// QUICTransport is a specialization of QuicTransportBase focused on
|
||||
// peer-to-peer use cases and includes information relating to use of a
|
||||
// QUIC transport with an ICE transport.
|
||||
type RTCQuicTransport struct {
|
||||
type QUICTransport struct {
|
||||
lock sync.RWMutex
|
||||
quic.TransportBase
|
||||
|
||||
iceTransport *RTCIceTransport
|
||||
certificates []RTCCertificate
|
||||
iceTransport *ICETransport
|
||||
certificates []Certificate
|
||||
}
|
||||
|
||||
// NewRTCQuicTransport creates a new RTCQuicTransport.
|
||||
// NewQUICTransport creates a new QUICTransport.
|
||||
// This constructor is part of the ORTC API. It is not
|
||||
// meant to be used together with the basic WebRTC API.
|
||||
// Note that the Quic transport is a draft and therefore
|
||||
// highly experimental. It is currently not supported by
|
||||
// any browsers yet.
|
||||
func (api *API) NewRTCQuicTransport(transport *RTCIceTransport, certificates []RTCCertificate) (*RTCQuicTransport, error) {
|
||||
t := &RTCQuicTransport{iceTransport: transport}
|
||||
func (api *API) NewQUICTransport(transport *ICETransport, certificates []Certificate) (*QUICTransport, error) {
|
||||
t := &QUICTransport{iceTransport: transport}
|
||||
|
||||
if len(certificates) > 0 {
|
||||
now := time.Now()
|
||||
@@ -54,29 +54,29 @@ func (api *API) NewRTCQuicTransport(transport *RTCIceTransport, certificates []R
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
t.certificates = []RTCCertificate{*certificate}
|
||||
t.certificates = []Certificate{*certificate}
|
||||
}
|
||||
|
||||
return t, nil
|
||||
}
|
||||
|
||||
// GetLocalParameters returns the Quic parameters of the local RTCQuicParameters upon construction.
|
||||
func (t *RTCQuicTransport) GetLocalParameters() RTCQuicParameters {
|
||||
fingerprints := []RTCDtlsFingerprint{}
|
||||
// GetLocalParameters returns the Quic parameters of the local QUICParameters upon construction.
|
||||
func (t *QUICTransport) GetLocalParameters() QUICParameters {
|
||||
fingerprints := []DTLSFingerprint{}
|
||||
|
||||
for _, c := range t.certificates {
|
||||
prints := c.GetFingerprints() // TODO: Should be only one?
|
||||
fingerprints = append(fingerprints, prints...)
|
||||
}
|
||||
|
||||
return RTCQuicParameters{
|
||||
Role: RTCQuicRoleAuto, // always returns the default role
|
||||
return QUICParameters{
|
||||
Role: QUICRoleAuto, // always returns the default role
|
||||
Fingerprints: fingerprints,
|
||||
}
|
||||
}
|
||||
|
||||
// Start Quic transport with the parameters of the remote
|
||||
func (t *RTCQuicTransport) Start(remoteParameters RTCQuicParameters) error {
|
||||
func (t *QUICTransport) Start(remoteParameters QUICParameters) error {
|
||||
t.lock.Lock()
|
||||
defer t.lock.Unlock()
|
||||
|
||||
@@ -89,12 +89,12 @@ func (t *RTCQuicTransport) Start(remoteParameters RTCQuicParameters) error {
|
||||
|
||||
isClient := true
|
||||
switch remoteParameters.Role {
|
||||
case RTCQuicRoleClient:
|
||||
case QUICRoleClient:
|
||||
isClient = true
|
||||
case RTCQuicRoleServer:
|
||||
case QUICRoleServer:
|
||||
isClient = false
|
||||
default:
|
||||
if t.iceTransport.Role() == RTCIceRoleControlling {
|
||||
if t.iceTransport.Role() == ICERoleControlling {
|
||||
isClient = false
|
||||
}
|
||||
}
|
||||
@@ -125,7 +125,7 @@ func (t *RTCQuicTransport) Start(remoteParameters RTCQuicParameters) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *RTCQuicTransport) validateFingerPrint(remoteParameters RTCQuicParameters, remoteCert *x509.Certificate) error {
|
||||
func (t *QUICTransport) validateFingerPrint(remoteParameters QUICParameters, remoteCert *x509.Certificate) error {
|
||||
for _, fp := range remoteParameters.Fingerprints {
|
||||
hashAlgo, err := dtls.HashAlgorithmString(fp.Algorithm)
|
||||
if err != nil {
|
||||
@@ -145,7 +145,7 @@ func (t *RTCQuicTransport) validateFingerPrint(remoteParameters RTCQuicParameter
|
||||
return errors.New("No matching fingerprint")
|
||||
}
|
||||
|
||||
func (t *RTCQuicTransport) ensureICEConn() error {
|
||||
func (t *QUICTransport) ensureICEConn() error {
|
||||
if t.iceTransport == nil ||
|
||||
t.iceTransport.conn == nil ||
|
||||
t.iceTransport.mux == nil {
|
||||
|
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/pions/webrtc/pkg/quic"
|
||||
)
|
||||
|
||||
func TestRTCQuicTransport_E2E(t *testing.T) {
|
||||
func TestQUICTransport_E2E(t *testing.T) {
|
||||
// Limit runtime in case of deadlocks
|
||||
lim := test.TimeOut(time.Second * 20)
|
||||
defer lim.Stop()
|
||||
@@ -74,16 +74,16 @@ func quicReadLoop(s *quic.BidirectionalStream) {
|
||||
}
|
||||
|
||||
type testQuicStack struct {
|
||||
gatherer *RTCIceGatherer
|
||||
ice *RTCIceTransport
|
||||
quic *RTCQuicTransport
|
||||
gatherer *ICEGatherer
|
||||
ice *ICETransport
|
||||
quic *QUICTransport
|
||||
api *API
|
||||
}
|
||||
|
||||
func (s *testQuicStack) setSignal(sig *testQuicSignal, isOffer bool) error {
|
||||
iceRole := RTCIceRoleControlled
|
||||
iceRole := ICERoleControlled
|
||||
if isOffer {
|
||||
iceRole = RTCIceRoleControlling
|
||||
iceRole = ICERoleControlling
|
||||
}
|
||||
|
||||
err := s.ice.SetRemoteCandidates(sig.ICECandidates)
|
||||
@@ -147,9 +147,9 @@ func (s *testQuicStack) close() error {
|
||||
}
|
||||
|
||||
type testQuicSignal struct {
|
||||
ICECandidates []RTCIceCandidate `json:"iceCandidates"`
|
||||
ICEParameters RTCIceParameters `json:"iceParameters"`
|
||||
QuicParameters RTCQuicParameters `json:"quicParameters"`
|
||||
ICECandidates []ICECandidate `json:"iceCandidates"`
|
||||
ICEParameters ICEParameters `json:"iceParameters"`
|
||||
QuicParameters QUICParameters `json:"quicParameters"`
|
||||
}
|
||||
|
||||
func newQuicPair() (stackA *testQuicStack, stackB *testQuicStack, err error) {
|
||||
@@ -169,16 +169,16 @@ func newQuicPair() (stackA *testQuicStack, stackB *testQuicStack, err error) {
|
||||
func newQuicStack() (*testQuicStack, error) {
|
||||
api := NewAPI()
|
||||
// Create the ICE gatherer
|
||||
gatherer, err := api.NewRTCIceGatherer(RTCIceGatherOptions{})
|
||||
gatherer, err := api.NewICEGatherer(ICEGatherOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Construct the ICE transport
|
||||
ice := api.NewRTCIceTransport(gatherer)
|
||||
ice := api.NewICETransport(gatherer)
|
||||
|
||||
// Construct the Quic transport
|
||||
qt, err := api.NewRTCQuicTransport(ice, nil)
|
||||
qt, err := api.NewQUICTransport(ice, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@@ -1,45 +1,45 @@
|
||||
package webrtc
|
||||
|
||||
// RTCRtcpMuxPolicy affects what ICE candidates are gathered to support
|
||||
// RTCPMuxPolicy affects what ICE candidates are gathered to support
|
||||
// non-multiplexed RTCP.
|
||||
type RTCRtcpMuxPolicy int
|
||||
type RTCPMuxPolicy int
|
||||
|
||||
const (
|
||||
// RTCRtcpMuxPolicyNegotiate indicates to gather ICE candidates for both
|
||||
// RTCPMuxPolicyNegotiate indicates to gather ICE candidates for both
|
||||
// RTP and RTCP candidates. If the remote-endpoint is capable of
|
||||
// multiplexing RTCP, multiplex RTCP on the RTP candidates. If it is not,
|
||||
// use both the RTP and RTCP candidates separately.
|
||||
RTCRtcpMuxPolicyNegotiate RTCRtcpMuxPolicy = iota + 1
|
||||
RTCPMuxPolicyNegotiate RTCPMuxPolicy = iota + 1
|
||||
|
||||
// RTCRtcpMuxPolicyRequire indicates to gather ICE candidates only for
|
||||
// RTCPMuxPolicyRequire indicates to gather ICE candidates only for
|
||||
// RTP and multiplex RTCP on the RTP candidates. If the remote endpoint is
|
||||
// not capable of rtcp-mux, session negotiation will fail.
|
||||
RTCRtcpMuxPolicyRequire
|
||||
RTCPMuxPolicyRequire
|
||||
)
|
||||
|
||||
// This is done this way because of a linter.
|
||||
const (
|
||||
rtcRtcpMuxPolicyNegotiateStr = "negotiate"
|
||||
rtcRtcpMuxPolicyRequireStr = "require"
|
||||
rtcpMuxPolicyNegotiateStr = "negotiate"
|
||||
rtcpMuxPolicyRequireStr = "require"
|
||||
)
|
||||
|
||||
func newRTCRtcpMuxPolicy(raw string) RTCRtcpMuxPolicy {
|
||||
func newRTCPMuxPolicy(raw string) RTCPMuxPolicy {
|
||||
switch raw {
|
||||
case rtcRtcpMuxPolicyNegotiateStr:
|
||||
return RTCRtcpMuxPolicyNegotiate
|
||||
case rtcRtcpMuxPolicyRequireStr:
|
||||
return RTCRtcpMuxPolicyRequire
|
||||
case rtcpMuxPolicyNegotiateStr:
|
||||
return RTCPMuxPolicyNegotiate
|
||||
case rtcpMuxPolicyRequireStr:
|
||||
return RTCPMuxPolicyRequire
|
||||
default:
|
||||
return RTCRtcpMuxPolicy(Unknown)
|
||||
return RTCPMuxPolicy(Unknown)
|
||||
}
|
||||
}
|
||||
|
||||
func (t RTCRtcpMuxPolicy) String() string {
|
||||
func (t RTCPMuxPolicy) String() string {
|
||||
switch t {
|
||||
case RTCRtcpMuxPolicyNegotiate:
|
||||
return rtcRtcpMuxPolicyNegotiateStr
|
||||
case RTCRtcpMuxPolicyRequire:
|
||||
return rtcRtcpMuxPolicyRequireStr
|
||||
case RTCPMuxPolicyNegotiate:
|
||||
return rtcpMuxPolicyNegotiateStr
|
||||
case RTCPMuxPolicyRequire:
|
||||
return rtcpMuxPolicyRequireStr
|
||||
default:
|
||||
return ErrUnknownType.Error()
|
||||
}
|
||||
|
@@ -6,33 +6,33 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewRTCRtcpMuxPolicy(t *testing.T) {
|
||||
func TestNewRTCPMuxPolicy(t *testing.T) {
|
||||
testCases := []struct {
|
||||
policyString string
|
||||
expectedPolicy RTCRtcpMuxPolicy
|
||||
expectedPolicy RTCPMuxPolicy
|
||||
}{
|
||||
{unknownStr, RTCRtcpMuxPolicy(Unknown)},
|
||||
{"negotiate", RTCRtcpMuxPolicyNegotiate},
|
||||
{"require", RTCRtcpMuxPolicyRequire},
|
||||
{unknownStr, RTCPMuxPolicy(Unknown)},
|
||||
{"negotiate", RTCPMuxPolicyNegotiate},
|
||||
{"require", RTCPMuxPolicyRequire},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
assert.Equal(t,
|
||||
testCase.expectedPolicy,
|
||||
newRTCRtcpMuxPolicy(testCase.policyString),
|
||||
newRTCPMuxPolicy(testCase.policyString),
|
||||
"testCase: %d %v", i, testCase,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRTCRtcpMuxPolicy_String(t *testing.T) {
|
||||
func TestRTCPMuxPolicy_String(t *testing.T) {
|
||||
testCases := []struct {
|
||||
policy RTCRtcpMuxPolicy
|
||||
policy RTCPMuxPolicy
|
||||
expectedString string
|
||||
}{
|
||||
{RTCRtcpMuxPolicy(Unknown), unknownStr},
|
||||
{RTCRtcpMuxPolicyNegotiate, "negotiate"},
|
||||
{RTCRtcpMuxPolicyRequire, "require"},
|
||||
{RTCPMuxPolicy(Unknown), unknownStr},
|
||||
{RTCPMuxPolicyNegotiate, "negotiate"},
|
||||
{RTCPMuxPolicyRequire, "require"},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package webrtc
|
||||
|
||||
// RTCRtpCodingParameters provides information relating to both encoding and decoding.
|
||||
// RTPCodingParameters provides information relating to both encoding and decoding.
|
||||
// This is a subset of the RFC since Pion WebRTC doesn't implement encoding/decoding itself
|
||||
// http://draft.ortc.org/#dom-rtcrtpcodingparameters
|
||||
type RTCRtpCodingParameters struct {
|
||||
type RTPCodingParameters struct {
|
||||
SSRC uint32 `json:"ssrc"`
|
||||
PayloadType uint8 `json:"payloadType"`
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package webrtc
|
||||
|
||||
// RTCRtpDecodingParameters provides information relating to both encoding and decoding.
|
||||
// RTPDecodingParameters provides information relating to both encoding and decoding.
|
||||
// This is a subset of the RFC since Pion WebRTC doesn't implement decoding itself
|
||||
// http://draft.ortc.org/#dom-rtcrtpdecodingparameters
|
||||
type RTCRtpDecodingParameters struct {
|
||||
RTCRtpCodingParameters
|
||||
type RTPDecodingParameters struct {
|
||||
RTPCodingParameters
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package webrtc
|
||||
|
||||
// RTCRtpEncodingParameters provides information relating to both encoding and decoding.
|
||||
// RTPEncodingParameters provides information relating to both encoding and decoding.
|
||||
// This is a subset of the RFC since Pion WebRTC doesn't implement encoding itself
|
||||
// http://draft.ortc.org/#dom-rtcrtpencodingparameters
|
||||
type RTCRtpEncodingParameters struct {
|
||||
RTCRtpCodingParameters
|
||||
type RTPEncodingParameters struct {
|
||||
RTPCodingParameters
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package webrtc
|
||||
|
||||
// RTCRtpReceiveParameters contains the RTP stack settings used by receivers
|
||||
type RTCRtpReceiveParameters struct {
|
||||
encodings RTCRtpDecodingParameters
|
||||
// RTPReceiveParameters contains the RTP stack settings used by receivers
|
||||
type RTPReceiveParameters struct {
|
||||
encodings RTPDecodingParameters
|
||||
}
|
||||
|
@@ -9,14 +9,14 @@ import (
|
||||
"github.com/pions/srtp"
|
||||
)
|
||||
|
||||
// RTCRtpReceiver allows an application to inspect the receipt of a RTCTrack
|
||||
type RTCRtpReceiver struct {
|
||||
kind RTCRtpCodecType
|
||||
transport *RTCDtlsTransport
|
||||
// RTPReceiver allows an application to inspect the receipt of a Track
|
||||
type RTPReceiver struct {
|
||||
kind RTPCodecType
|
||||
transport *DTLSTransport
|
||||
|
||||
hasRecv chan bool
|
||||
|
||||
Track *RTCTrack
|
||||
Track *Track
|
||||
|
||||
closed bool
|
||||
mu sync.Mutex
|
||||
@@ -30,9 +30,9 @@ type RTCRtpReceiver struct {
|
||||
rtcpOutDone chan bool
|
||||
}
|
||||
|
||||
// NewRTCRtpReceiver constructs a new RTCRtpReceiver
|
||||
func NewRTCRtpReceiver(kind RTCRtpCodecType, transport *RTCDtlsTransport) *RTCRtpReceiver {
|
||||
return &RTCRtpReceiver{
|
||||
// NewRTPReceiver constructs a new RTPReceiver
|
||||
func NewRTPReceiver(kind RTPCodecType, transport *DTLSTransport) *RTPReceiver {
|
||||
return &RTPReceiver{
|
||||
kind: kind,
|
||||
transport: transport,
|
||||
|
||||
@@ -46,10 +46,10 @@ func NewRTCRtpReceiver(kind RTCRtpCodecType, transport *RTCDtlsTransport) *RTCRt
|
||||
}
|
||||
}
|
||||
|
||||
// Receive blocks until the RTCTrack is available
|
||||
func (r *RTCRtpReceiver) Receive(parameters RTCRtpReceiveParameters) chan bool {
|
||||
// Receive blocks until the Track is available
|
||||
func (r *RTPReceiver) Receive(parameters RTPReceiveParameters) chan bool {
|
||||
// TODO atomic only allow this to fire once
|
||||
r.Track = &RTCTrack{
|
||||
r.Track = &Track{
|
||||
Kind: r.kind,
|
||||
Ssrc: parameters.encodings.SSRC,
|
||||
Packets: r.rtpOut,
|
||||
@@ -69,13 +69,13 @@ func (r *RTCRtpReceiver) Receive(parameters RTCRtpReceiveParameters) chan bool {
|
||||
|
||||
srtpSession, err := r.transport.getSRTPSession()
|
||||
if err != nil {
|
||||
pcLog.Warnf("Failed to open SRTPSession, RTCTrack done for: %v %d \n", err, parameters.encodings.SSRC)
|
||||
pcLog.Warnf("Failed to open SRTPSession, Track done for: %v %d \n", err, parameters.encodings.SSRC)
|
||||
return
|
||||
}
|
||||
|
||||
readStream, err := srtpSession.OpenReadStream(parameters.encodings.SSRC)
|
||||
if err != nil {
|
||||
pcLog.Warnf("Failed to open RTCP ReadStream, RTCTrack done for: %v %d \n", err, parameters.encodings.SSRC)
|
||||
pcLog.Warnf("Failed to open RTCP ReadStream, Track done for: %v %d \n", err, parameters.encodings.SSRC)
|
||||
return
|
||||
}
|
||||
r.mu.Lock()
|
||||
@@ -86,7 +86,7 @@ func (r *RTCRtpReceiver) Receive(parameters RTCRtpReceiveParameters) chan bool {
|
||||
for {
|
||||
rtpLen, err := readStream.Read(readBuf)
|
||||
if err != nil {
|
||||
pcLog.Warnf("Failed to read, RTCTrack done for: %v %d \n", err, parameters.encodings.SSRC)
|
||||
pcLog.Warnf("Failed to read, Track done for: %v %d \n", err, parameters.encodings.SSRC)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -118,13 +118,13 @@ func (r *RTCRtpReceiver) Receive(parameters RTCRtpReceiveParameters) chan bool {
|
||||
|
||||
srtcpSession, err := r.transport.getSRTCPSession()
|
||||
if err != nil {
|
||||
pcLog.Warnf("Failed to open SRTCPSession, RTCTrack done for: %v %d \n", err, parameters.encodings.SSRC)
|
||||
pcLog.Warnf("Failed to open SRTCPSession, Track done for: %v %d \n", err, parameters.encodings.SSRC)
|
||||
return
|
||||
}
|
||||
|
||||
readStream, err := srtcpSession.OpenReadStream(parameters.encodings.SSRC)
|
||||
if err != nil {
|
||||
pcLog.Warnf("Failed to open RTCP ReadStream, RTCTrack done for: %v %d \n", err, parameters.encodings.SSRC)
|
||||
pcLog.Warnf("Failed to open RTCP ReadStream, Track done for: %v %d \n", err, parameters.encodings.SSRC)
|
||||
return
|
||||
}
|
||||
r.mu.Lock()
|
||||
@@ -135,7 +135,7 @@ func (r *RTCRtpReceiver) Receive(parameters RTCRtpReceiveParameters) chan bool {
|
||||
for {
|
||||
rtcpLen, err := readStream.Read(readBuf)
|
||||
if err != nil {
|
||||
pcLog.Warnf("Failed to read, RTCTrack done for: %v %d \n", err, parameters.encodings.SSRC)
|
||||
pcLog.Warnf("Failed to read, Track done for: %v %d \n", err, parameters.encodings.SSRC)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -154,19 +154,19 @@ func (r *RTCRtpReceiver) Receive(parameters RTCRtpReceiveParameters) chan bool {
|
||||
return r.hasRecv
|
||||
}
|
||||
|
||||
// Stop irreversibly stops the RTCRtpReceiver
|
||||
func (r *RTCRtpReceiver) Stop() error {
|
||||
// Stop irreversibly stops the RTPReceiver
|
||||
func (r *RTPReceiver) Stop() error {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
if r.closed {
|
||||
return fmt.Errorf("RTCRtpReceiver has already been closed")
|
||||
return fmt.Errorf("RTPReceiver has already been closed")
|
||||
}
|
||||
|
||||
select {
|
||||
case <-r.hasRecv:
|
||||
default:
|
||||
return fmt.Errorf("RTCRtpReceiver has not been started")
|
||||
return fmt.Errorf("RTPReceiver has not been started")
|
||||
}
|
||||
|
||||
if err := r.rtcpReadStream.Close(); err != nil {
|
||||
|
@@ -8,21 +8,21 @@ import (
|
||||
|
||||
const rtpOutboundMTU = 1400
|
||||
|
||||
// RTCRtpSender allows an application to control how a given RTCTrack is encoded and transmitted to a remote peer
|
||||
type RTCRtpSender struct {
|
||||
Track *RTCTrack
|
||||
// RTPSender allows an application to control how a given Track is encoded and transmitted to a remote peer
|
||||
type RTPSender struct {
|
||||
Track *Track
|
||||
|
||||
transport *RTCDtlsTransport
|
||||
transport *DTLSTransport
|
||||
}
|
||||
|
||||
// NewRTCRtpSender constructs a new RTCRtpSender
|
||||
func NewRTCRtpSender(track *RTCTrack, transport *RTCDtlsTransport) *RTCRtpSender {
|
||||
r := &RTCRtpSender{
|
||||
// NewRTPSender constructs a new RTPSender
|
||||
func NewRTPSender(track *Track, transport *DTLSTransport) *RTPSender {
|
||||
r := &RTPSender{
|
||||
Track: track,
|
||||
transport: transport,
|
||||
}
|
||||
|
||||
r.Track.sampleInput = make(chan media.RTCSample, 15) // Is the buffering needed?
|
||||
r.Track.sampleInput = make(chan media.Sample, 15) // Is the buffering needed?
|
||||
r.Track.rawInput = make(chan *rtp.Packet, 15) // Is the buffering needed?
|
||||
r.Track.rtcpInput = make(chan rtcp.Packet, 15) // Is the buffering needed?
|
||||
|
||||
@@ -40,7 +40,7 @@ func NewRTCRtpSender(track *RTCTrack, transport *RTCDtlsTransport) *RTCRtpSender
|
||||
}
|
||||
|
||||
// Send Attempts to set the parameters controlling the sending of media.
|
||||
func (r *RTCRtpSender) Send(parameters RTCRtpSendParameters) {
|
||||
func (r *RTPSender) Send(parameters RTPSendParameters) {
|
||||
if r.Track.isRawRTP {
|
||||
go r.handleRawRTP(r.Track.rawInput)
|
||||
} else {
|
||||
@@ -50,8 +50,8 @@ func (r *RTCRtpSender) Send(parameters RTCRtpSendParameters) {
|
||||
go r.handleRTCP(r.transport, r.Track.rtcpInput)
|
||||
}
|
||||
|
||||
// Stop irreversibly stops the RTCRtpSender
|
||||
func (r *RTCRtpSender) Stop() {
|
||||
// Stop irreversibly stops the RTPSender
|
||||
func (r *RTPSender) Stop() {
|
||||
if r.Track.isRawRTP {
|
||||
close(r.Track.RawRTP)
|
||||
} else {
|
||||
@@ -61,7 +61,7 @@ func (r *RTCRtpSender) Stop() {
|
||||
// TODO properly tear down all loops (and test that)
|
||||
}
|
||||
|
||||
func (r *RTCRtpSender) handleRawRTP(rtpPackets chan *rtp.Packet) {
|
||||
func (r *RTPSender) handleRawRTP(rtpPackets chan *rtp.Packet) {
|
||||
for {
|
||||
p, ok := <-rtpPackets
|
||||
if !ok {
|
||||
@@ -72,7 +72,7 @@ func (r *RTCRtpSender) handleRawRTP(rtpPackets chan *rtp.Packet) {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *RTCRtpSender) handleSampleRTP(rtpPackets chan media.RTCSample) {
|
||||
func (r *RTPSender) handleSampleRTP(rtpPackets chan media.Sample) {
|
||||
packetizer := rtp.NewPacketizer(
|
||||
rtpOutboundMTU,
|
||||
r.Track.PayloadType,
|
||||
@@ -95,16 +95,16 @@ func (r *RTCRtpSender) handleSampleRTP(rtpPackets chan media.RTCSample) {
|
||||
|
||||
}
|
||||
|
||||
func (r *RTCRtpSender) handleRTCP(transport *RTCDtlsTransport, rtcpPackets chan rtcp.Packet) {
|
||||
func (r *RTPSender) handleRTCP(transport *DTLSTransport, rtcpPackets chan rtcp.Packet) {
|
||||
srtcpSession, err := transport.getSRTCPSession()
|
||||
if err != nil {
|
||||
pcLog.Warnf("Failed to open SRTCPSession, RTCTrack done for: %v %d \n", err, r.Track.Ssrc)
|
||||
pcLog.Warnf("Failed to open SRTCPSession, Track done for: %v %d \n", err, r.Track.Ssrc)
|
||||
return
|
||||
}
|
||||
|
||||
readStream, err := srtcpSession.OpenReadStream(r.Track.Ssrc)
|
||||
if err != nil {
|
||||
pcLog.Warnf("Failed to open RTCP ReadStream, RTCTrack done for: %v %d \n", err, r.Track.Ssrc)
|
||||
pcLog.Warnf("Failed to open RTCP ReadStream, Track done for: %v %d \n", err, r.Track.Ssrc)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ func (r *RTCRtpSender) handleRTCP(transport *RTCDtlsTransport, rtcpPackets chan
|
||||
rtcpBuf := make([]byte, receiveMTU)
|
||||
i, err := readStream.Read(rtcpBuf)
|
||||
if err != nil {
|
||||
pcLog.Warnf("Failed to read, RTCTrack done for: %v %d \n", err, r.Track.Ssrc)
|
||||
pcLog.Warnf("Failed to read, Track done for: %v %d \n", err, r.Track.Ssrc)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ func (r *RTCRtpSender) handleRTCP(transport *RTCDtlsTransport, rtcpPackets chan
|
||||
|
||||
}
|
||||
|
||||
func (r *RTCRtpSender) sendRTP(packet *rtp.Packet) {
|
||||
func (r *RTPSender) sendRTP(packet *rtp.Packet) {
|
||||
srtpSession, err := r.transport.getSRTPSession()
|
||||
if err != nil {
|
||||
pcLog.Warnf("SendRTP failed to open SrtpSession: %v", err)
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package webrtc
|
||||
|
||||
// RTCRtpSendParameters contains the RTP stack settings used by receivers
|
||||
type RTCRtpSendParameters struct {
|
||||
encodings RTCRtpEncodingParameters
|
||||
// RTPSendParameters contains the RTP stack settings used by receivers
|
||||
type RTPSendParameters struct {
|
||||
encodings RTPEncodingParameters
|
||||
}
|
||||
|
@@ -4,34 +4,34 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// RTCRtpTransceiver represents a combination of an RTCRtpSender and an RTCRtpReceiver that share a common mid.
|
||||
type RTCRtpTransceiver struct {
|
||||
// RTPTransceiver represents a combination of an RTPSender and an RTPReceiver that share a common mid.
|
||||
type RTPTransceiver struct {
|
||||
Mid string
|
||||
Sender *RTCRtpSender
|
||||
Receiver *RTCRtpReceiver
|
||||
Direction RTCRtpTransceiverDirection
|
||||
// currentDirection RTCRtpTransceiverDirection
|
||||
// firedDirection RTCRtpTransceiverDirection
|
||||
Sender *RTPSender
|
||||
Receiver *RTPReceiver
|
||||
Direction RTPTransceiverDirection
|
||||
// currentDirection RTPTransceiverDirection
|
||||
// firedDirection RTPTransceiverDirection
|
||||
// receptive bool
|
||||
stopped bool
|
||||
}
|
||||
|
||||
func (t *RTCRtpTransceiver) setSendingTrack(track *RTCTrack) error {
|
||||
func (t *RTPTransceiver) setSendingTrack(track *Track) error {
|
||||
t.Sender.Track = track
|
||||
|
||||
switch t.Direction {
|
||||
case RTCRtpTransceiverDirectionRecvonly:
|
||||
t.Direction = RTCRtpTransceiverDirectionSendrecv
|
||||
case RTCRtpTransceiverDirectionInactive:
|
||||
t.Direction = RTCRtpTransceiverDirectionSendonly
|
||||
case RTPTransceiverDirectionRecvonly:
|
||||
t.Direction = RTPTransceiverDirectionSendrecv
|
||||
case RTPTransceiverDirectionInactive:
|
||||
t.Direction = RTPTransceiverDirectionSendonly
|
||||
default:
|
||||
return errors.Errorf("Invalid state change in RTCRtpTransceiver.setSending")
|
||||
return errors.Errorf("Invalid state change in RTPTransceiver.setSending")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Stop irreversibly stops the RTCRtpTransceiver
|
||||
func (t *RTCRtpTransceiver) Stop() error {
|
||||
// Stop irreversibly stops the RTPTransceiver
|
||||
func (t *RTPTransceiver) Stop() error {
|
||||
if t.Sender != nil {
|
||||
t.Sender.Stop()
|
||||
}
|
||||
|
@@ -1,61 +1,61 @@
|
||||
package webrtc
|
||||
|
||||
// RTCRtpTransceiverDirection indicates the direction of the RTCRtpTransceiver.
|
||||
type RTCRtpTransceiverDirection int
|
||||
// RTPTransceiverDirection indicates the direction of the RTPTransceiver.
|
||||
type RTPTransceiverDirection int
|
||||
|
||||
const (
|
||||
// RTCRtpTransceiverDirectionSendrecv indicates the RTCRtpSender will offer
|
||||
// to send RTP and RTCRtpReceiver the will offer to receive RTP.
|
||||
RTCRtpTransceiverDirectionSendrecv RTCRtpTransceiverDirection = iota + 1
|
||||
// RTPTransceiverDirectionSendrecv indicates the RTPSender will offer
|
||||
// to send RTP and RTPReceiver the will offer to receive RTP.
|
||||
RTPTransceiverDirectionSendrecv RTPTransceiverDirection = iota + 1
|
||||
|
||||
// RTCRtpTransceiverDirectionSendonly indicates the RTCRtpSender will offer
|
||||
// RTPTransceiverDirectionSendonly indicates the RTPSender will offer
|
||||
// to send RTP.
|
||||
RTCRtpTransceiverDirectionSendonly
|
||||
RTPTransceiverDirectionSendonly
|
||||
|
||||
// RTCRtpTransceiverDirectionRecvonly indicates the RTCRtpReceiver the will
|
||||
// RTPTransceiverDirectionRecvonly indicates the RTPReceiver the will
|
||||
// offer to receive RTP.
|
||||
RTCRtpTransceiverDirectionRecvonly
|
||||
RTPTransceiverDirectionRecvonly
|
||||
|
||||
// RTCRtpTransceiverDirectionInactive indicates the RTCRtpSender won't offer
|
||||
// to send RTP and RTCRtpReceiver the won't offer to receive RTP.
|
||||
RTCRtpTransceiverDirectionInactive
|
||||
// RTPTransceiverDirectionInactive indicates the RTPSender won't offer
|
||||
// to send RTP and RTPReceiver the won't offer to receive RTP.
|
||||
RTPTransceiverDirectionInactive
|
||||
)
|
||||
|
||||
// This is done this way because of a linter.
|
||||
const (
|
||||
rtcRtpTransceiverDirectionSendrecvStr = "sendrecv"
|
||||
rtcRtpTransceiverDirectionSendonlyStr = "sendonly"
|
||||
rtcRtpTransceiverDirectionRecvonlyStr = "recvonly"
|
||||
rtcRtpTransceiverDirectionInactiveStr = "inactive"
|
||||
rtpTransceiverDirectionSendrecvStr = "sendrecv"
|
||||
rtpTransceiverDirectionSendonlyStr = "sendonly"
|
||||
rtpTransceiverDirectionRecvonlyStr = "recvonly"
|
||||
rtpTransceiverDirectionInactiveStr = "inactive"
|
||||
)
|
||||
|
||||
// NewRTCRtpTransceiverDirection defines a procedure for creating a new
|
||||
// RTCRtpTransceiverDirection from a raw string naming the transceiver direction.
|
||||
func NewRTCRtpTransceiverDirection(raw string) RTCRtpTransceiverDirection {
|
||||
// NewRTPTransceiverDirection defines a procedure for creating a new
|
||||
// RTPTransceiverDirection from a raw string naming the transceiver direction.
|
||||
func NewRTPTransceiverDirection(raw string) RTPTransceiverDirection {
|
||||
switch raw {
|
||||
case rtcRtpTransceiverDirectionSendrecvStr:
|
||||
return RTCRtpTransceiverDirectionSendrecv
|
||||
case rtcRtpTransceiverDirectionSendonlyStr:
|
||||
return RTCRtpTransceiverDirectionSendonly
|
||||
case rtcRtpTransceiverDirectionRecvonlyStr:
|
||||
return RTCRtpTransceiverDirectionRecvonly
|
||||
case rtcRtpTransceiverDirectionInactiveStr:
|
||||
return RTCRtpTransceiverDirectionInactive
|
||||
case rtpTransceiverDirectionSendrecvStr:
|
||||
return RTPTransceiverDirectionSendrecv
|
||||
case rtpTransceiverDirectionSendonlyStr:
|
||||
return RTPTransceiverDirectionSendonly
|
||||
case rtpTransceiverDirectionRecvonlyStr:
|
||||
return RTPTransceiverDirectionRecvonly
|
||||
case rtpTransceiverDirectionInactiveStr:
|
||||
return RTPTransceiverDirectionInactive
|
||||
default:
|
||||
return RTCRtpTransceiverDirection(Unknown)
|
||||
return RTPTransceiverDirection(Unknown)
|
||||
}
|
||||
}
|
||||
|
||||
func (t RTCRtpTransceiverDirection) String() string {
|
||||
func (t RTPTransceiverDirection) String() string {
|
||||
switch t {
|
||||
case RTCRtpTransceiverDirectionSendrecv:
|
||||
return rtcRtpTransceiverDirectionSendrecvStr
|
||||
case RTCRtpTransceiverDirectionSendonly:
|
||||
return rtcRtpTransceiverDirectionSendonlyStr
|
||||
case RTCRtpTransceiverDirectionRecvonly:
|
||||
return rtcRtpTransceiverDirectionRecvonlyStr
|
||||
case RTCRtpTransceiverDirectionInactive:
|
||||
return rtcRtpTransceiverDirectionInactiveStr
|
||||
case RTPTransceiverDirectionSendrecv:
|
||||
return rtpTransceiverDirectionSendrecvStr
|
||||
case RTPTransceiverDirectionSendonly:
|
||||
return rtpTransceiverDirectionSendonlyStr
|
||||
case RTPTransceiverDirectionRecvonly:
|
||||
return rtpTransceiverDirectionRecvonlyStr
|
||||
case RTPTransceiverDirectionInactive:
|
||||
return rtpTransceiverDirectionInactiveStr
|
||||
default:
|
||||
return ErrUnknownType.Error()
|
||||
}
|
||||
|
@@ -6,37 +6,37 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewRTCRtpTransceiverDirection(t *testing.T) {
|
||||
func TestNewRTPTransceiverDirection(t *testing.T) {
|
||||
testCases := []struct {
|
||||
priorityString string
|
||||
expectedPriority RTCRtpTransceiverDirection
|
||||
expectedPriority RTPTransceiverDirection
|
||||
}{
|
||||
{unknownStr, RTCRtpTransceiverDirection(Unknown)},
|
||||
{"sendrecv", RTCRtpTransceiverDirectionSendrecv},
|
||||
{"sendonly", RTCRtpTransceiverDirectionSendonly},
|
||||
{"recvonly", RTCRtpTransceiverDirectionRecvonly},
|
||||
{"inactive", RTCRtpTransceiverDirectionInactive},
|
||||
{unknownStr, RTPTransceiverDirection(Unknown)},
|
||||
{"sendrecv", RTPTransceiverDirectionSendrecv},
|
||||
{"sendonly", RTPTransceiverDirectionSendonly},
|
||||
{"recvonly", RTPTransceiverDirectionRecvonly},
|
||||
{"inactive", RTPTransceiverDirectionInactive},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
assert.Equal(t,
|
||||
NewRTCRtpTransceiverDirection(testCase.priorityString),
|
||||
NewRTPTransceiverDirection(testCase.priorityString),
|
||||
testCase.expectedPriority,
|
||||
"testCase: %d %v", i, testCase,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRTCRtpTransceiverDirection_String(t *testing.T) {
|
||||
func TestRTPTransceiverDirection_String(t *testing.T) {
|
||||
testCases := []struct {
|
||||
priority RTCRtpTransceiverDirection
|
||||
priority RTPTransceiverDirection
|
||||
expectedString string
|
||||
}{
|
||||
{RTCRtpTransceiverDirection(Unknown), unknownStr},
|
||||
{RTCRtpTransceiverDirectionSendrecv, "sendrecv"},
|
||||
{RTCRtpTransceiverDirectionSendonly, "sendonly"},
|
||||
{RTCRtpTransceiverDirectionRecvonly, "recvonly"},
|
||||
{RTCRtpTransceiverDirectionInactive, "inactive"},
|
||||
{RTPTransceiverDirection(Unknown), unknownStr},
|
||||
{RTPTransceiverDirectionSendrecv, "sendrecv"},
|
||||
{RTPTransceiverDirectionSendonly, "sendonly"},
|
||||
{RTPTransceiverDirectionRecvonly, "recvonly"},
|
||||
{RTPTransceiverDirectionInactive, "inactive"},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user