diff --git a/README.md b/README.md index 1d6b7ae6e77..78ce7fb1c03 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/api.go b/api.go index 71e9de50dae..cf4442bd702 100644 --- a/api.go +++ b/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) } diff --git a/errors.go b/errors.go index 8ffea424a08..e2216ceda35 100644 --- a/errors.go +++ b/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. diff --git a/examples/data-channels-close/main.go b/examples/data-channels-close/main.go index 837c5452b8c..32045aaabb5 100644 --- a/examples/data-channels-close/main.go +++ b/examples/data-channels-close/main.go @@ -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 diff --git a/examples/data-channels-create/main.go b/examples/data-channels-create/main.go index 984b84313f8..ca80fbb0e41 100644 --- a/examples/data-channels-create/main.go +++ b/examples/data-channels-create/main.go @@ -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 diff --git a/examples/data-channels-detach-create/main.go b/examples/data-channels-detach-create/main.go index 16c4f3ab0dc..7f760f67e7e 100644 --- a/examples/data-channels-detach-create/main.go +++ b/examples/data-channels-detach-create/main.go @@ -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 diff --git a/examples/data-channels-detach/main.go b/examples/data-channels-detach/main.go index f21e4e6f0ba..4964f253957 100644 --- a/examples/data-channels-detach/main.go +++ b/examples/data-channels-detach/main.go @@ -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 diff --git a/examples/data-channels/main.go b/examples/data-channels/main.go index cbed1856b7d..9585ffda780 100644 --- a/examples/data-channels/main.go +++ b/examples/data-channels/main.go @@ -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 diff --git a/examples/gstreamer-receive/main.go b/examples/gstreamer-receive/main.go index 95daaa0c569..1cc21ffe3dc 100644 --- a/examples/gstreamer-receive/main.go +++ b/examples/gstreamer-receive/main.go @@ -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 diff --git a/examples/gstreamer-send-offer/main.go b/examples/gstreamer-send-offer/main.go index 9c917b38e47..71ff4a204eb 100644 --- a/examples/gstreamer-send-offer/main.go +++ b/examples/gstreamer-send-offer/main.go @@ -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 diff --git a/examples/gstreamer-send/main.go b/examples/gstreamer-send/main.go index ebfc02b2cc0..18791cf690a 100644 --- a/examples/gstreamer-send/main.go +++ b/examples/gstreamer-send/main.go @@ -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 diff --git a/examples/janus-gateway/streaming/main.go b/examples/janus-gateway/streaming/main.go index c91cb3c9e72..2ccc9275b23 100644 --- a/examples/janus-gateway/streaming/main.go +++ b/examples/janus-gateway/streaming/main.go @@ -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) diff --git a/examples/janus-gateway/video-room/main.go b/examples/janus-gateway/video-room/main.go index c95115f1df6..fe78ece6e00 100644 --- a/examples/janus-gateway/video-room/main.go +++ b/examples/janus-gateway/video-room/main.go @@ -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) diff --git a/examples/ortc-quic/main.go b/examples/ortc-quic/main.go index 4e9d5889601..d9e7b09ac5c 100644 --- a/examples/ortc-quic/main.go +++ b/examples/ortc-quic/main.go @@ -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 diff --git a/examples/ortc/main.go b/examples/ortc/main.go index e016cc8be8e..a8eaf259a92 100644 --- a/examples/ortc/main.go +++ b/examples/ortc/main.go @@ -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: diff --git a/examples/pion-to-pion/answer/main.go b/examples/pion-to-pion/answer/main.go index 795f70ddb8a..710d301578f 100644 --- a/examples/pion-to-pion/answer/main.go +++ b/examples/pion-to-pion/answer/main.go @@ -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) diff --git a/examples/pion-to-pion/offer/main.go b/examples/pion-to-pion/offer/main.go index 0e9ede6cc44..371f5a29c2c 100644 --- a/examples/pion-to-pion/offer/main.go +++ b/examples/pion-to-pion/offer/main.go @@ -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) diff --git a/examples/save-to-disk/main.go b/examples/save-to-disk/main.go index 4772f1fcd90..bdd8ca6d172 100644 --- a/examples/save-to-disk/main.go +++ b/examples/save-to-disk/main.go @@ -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 diff --git a/examples/sfu/main.go b/examples/sfu/main.go index 6398cb45ae8..e6adb5dd513 100644 --- a/examples/sfu/main.go +++ b/examples/sfu/main.go @@ -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 diff --git a/examples/util/gstreamer-src/gst.go b/examples/util/gstreamer-src/gst.go index a286c3e7d7f..c717ae20e48 100644 --- a/examples/util/gstreamer-src/gst.go +++ b/examples/util/gstreamer-src/gst.go @@ -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 { diff --git a/mediaengine.go b/mediaengine.go index 4593f02b066..fe6f9579636 100644 --- a/mediaengine.go +++ b/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 } diff --git a/pkg/media/media.go b/pkg/media/media.go index 1237623e961..888234b2346 100644 --- a/pkg/media/media.go +++ b/pkg/media/media.go @@ -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 } diff --git a/pkg/media/samplebuilder/samplebuilder.go b/pkg/media/samplebuilder/samplebuilder.go index 0cdb3adeb35..480dc907512 100644 --- a/pkg/media/samplebuilder/samplebuilder.go +++ b/pkg/media/samplebuilder/samplebuilder.go @@ -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 diff --git a/pkg/media/samplebuilder/samplebuilder_test.go b/pkg/media/samplebuilder/samplebuilder_test.go index 24a44b35384..92da5c34080 100644 --- a/pkg/media/samplebuilder/samplebuilder_test.go +++ b/pkg/media/samplebuilder/samplebuilder_test.go @@ -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") } diff --git a/pkg/quic/transportbase.go b/pkg/quic/transportbase.go index 79ba68135cf..c6ae39342c0 100644 --- a/pkg/quic/transportbase.go +++ b/pkg/quic/transportbase.go @@ -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 diff --git a/rtcbundlepolicy.go b/rtcbundlepolicy.go index ffb0c25302b..91e6f979dbf 100644 --- a/rtcbundlepolicy.go +++ b/rtcbundlepolicy.go @@ -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() } diff --git a/rtcbundlepolicy_test.go b/rtcbundlepolicy_test.go index ec561c82875..818b0853d0b 100644 --- a/rtcbundlepolicy_test.go +++ b/rtcbundlepolicy_test.go @@ -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 { diff --git a/rtccertificate.go b/rtccertificate.go index d02f0d84684..893e4e4576a 100644 --- a/rtccertificate.go +++ b/rtccertificate.go @@ -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, diff --git a/rtcconfiguration.go b/rtcconfiguration.go index b35a91a66ce..a78bb2ed4ef 100644 --- a/rtcconfiguration.go +++ b/rtcconfiguration.go @@ -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 { diff --git a/rtcconfiguration_test.go b/rtcconfiguration_test.go index 8d1796fc7ea..f49a4633e01 100644 --- a/rtcconfiguration_test.go +++ b/rtcconfiguration_test.go @@ -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) }) } diff --git a/rtcdatachannel.go b/rtcdatachannel.go index e7b4875ca26..0f4e746c415 100644 --- a/rtcdatachannel.go +++ b/rtcdatachannel.go @@ -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() } diff --git a/rtcdatachannel_ortc_test.go b/rtcdatachannel_ortc_test.go index ec1cd568d26..6aab050a0ff 100644 --- a/rtcdatachannel_ortc_test.go +++ b/rtcdatachannel_ortc_test.go @@ -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, diff --git a/rtcdatachannel_test.go b/rtcdatachannel_test.go index ac388decd78..1fb745433e0 100644 --- a/rtcdatachannel_test.go +++ b/rtcdatachannel_test.go @@ -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) diff --git a/rtcdatachannelinit.go b/rtcdatachannelinit.go index 1e8cc71f9bf..eeb49a22e0d 100644 --- a/rtcdatachannelinit.go +++ b/rtcdatachannelinit.go @@ -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 } diff --git a/rtcdatachannelparameters.go b/rtcdatachannelparameters.go index acdd94b6aef..8abec00ab02 100644 --- a/rtcdatachannelparameters.go +++ b/rtcdatachannelparameters.go @@ -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"` } diff --git a/rtcdatachannelstate.go b/rtcdatachannelstate.go index 732e3f8f125..a2c7b95de30 100644 --- a/rtcdatachannelstate.go +++ b/rtcdatachannelstate.go @@ -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() } diff --git a/rtcdatachannelstate_test.go b/rtcdatachannelstate_test.go index bd001419eff..780b3b2be60 100644 --- a/rtcdatachannelstate_test.go +++ b/rtcdatachannelstate_test.go @@ -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 { diff --git a/rtcdtlsfingerprint.go b/rtcdtlsfingerprint.go index e829add5cec..db13d3ec648 100644 --- a/rtcdtlsfingerprint.go +++ b/rtcdtlsfingerprint.go @@ -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"` diff --git a/rtcdtlsparameters.go b/rtcdtlsparameters.go index eb725a42385..4b4b56836fe 100644 --- a/rtcdtlsparameters.go +++ b/rtcdtlsparameters.go @@ -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"` } diff --git a/rtcdtlsrole.go b/rtcdtlsrole.go index 820d6bb95df..35dae4150fc 100644 --- a/rtcdtlsrole.go +++ b/rtcdtlsrole.go @@ -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 diff --git a/rtcdtlsrole_test.go b/rtcdtlsrole_test.go index 48ffb88f910..247b2753878 100644 --- a/rtcdtlsrole_test.go +++ b/rtcdtlsrole_test.go @@ -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 { diff --git a/rtcdtlstransport.go b/rtcdtlstransport.go index 0a6319e8be7..c8b1a7b482d 100644 --- a/rtcdtlstransport.go +++ b/rtcdtlstransport.go @@ -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 { diff --git a/rtcdtlstransportstate.go b/rtcdtlstransportstate.go index 529ab951db7..1960b072685 100644 --- a/rtcdtlstransportstate.go +++ b/rtcdtlstransportstate.go @@ -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() } diff --git a/rtcdtlstransportstate_test.go b/rtcdtlstransportstate_test.go index ada26c5d503..f23ddad508a 100644 --- a/rtcdtlstransportstate_test.go +++ b/rtcdtlstransportstate_test.go @@ -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 { diff --git a/rtcicecandidate.go b/rtcicecandidate.go index 19d0916a1a2..9541617b5b3 100644 --- a/rtcicecandidate.go +++ b/rtcicecandidate.go @@ -9,31 +9,31 @@ import ( "github.com/pions/webrtc/pkg/ice" ) -// RTCIceCandidate represents a ice candidate -type RTCIceCandidate struct { - Foundation string `json:"foundation"` - Priority uint32 `json:"priority"` - IP string `json:"ip"` - Protocol RTCIceProtocol `json:"protocol"` - Port uint16 `json:"port"` - Typ RTCIceCandidateType `json:"type"` - Component uint16 `json:"component"` - RelatedAddress string `json:"relatedAddress"` - RelatedPort uint16 `json:"relatedPort"` +// ICECandidate represents a ice candidate +type ICECandidate struct { + Foundation string `json:"foundation"` + Priority uint32 `json:"priority"` + IP string `json:"ip"` + Protocol ICEProtocol `json:"protocol"` + Port uint16 `json:"port"` + Typ ICECandidateType `json:"type"` + Component uint16 `json:"component"` + RelatedAddress string `json:"relatedAddress"` + RelatedPort uint16 `json:"relatedPort"` } // 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) } } diff --git a/rtcicecandidate_test.go b/rtcicecandidate_test.go index 1b1223e1701..a0c1a0e2430 100644 --- a/rtcicecandidate_test.go +++ b/rtcicecandidate_test.go @@ -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") } }) } diff --git a/rtcicecandidatetype.go b/rtcicecandidatetype.go index 6cb50966c0d..cdcb3e6465e 100644 --- a/rtcicecandidatetype.go +++ b/rtcicecandidatetype.go @@ -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() } diff --git a/rtcicecandidatetype_test.go b/rtcicecandidatetype_test.go index 74d6d4896ec..c90d42d7123 100644 --- a/rtcicecandidatetype_test.go +++ b/rtcicecandidatetype_test.go @@ -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 { diff --git a/rtcicecomponent.go b/rtcicecomponent.go index 0740af46241..1f03ec5b062 100644 --- a/rtcicecomponent.go +++ b/rtcicecomponent.go @@ -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() } diff --git a/rtcicecomponent_test.go b/rtcicecomponent_test.go index e257233281f..399cd81fd8e 100644 --- a/rtcicecomponent_test.go +++ b/rtcicecomponent_test.go @@ -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 { diff --git a/rtciceconnectionstate.go b/rtciceconnectionstate.go index 651a6c694fe..6fec660ddb0 100644 --- a/rtciceconnectionstate.go +++ b/rtciceconnectionstate.go @@ -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() } diff --git a/rtciceconnectionstate_test.go b/rtciceconnectionstate_test.go index 8e3c637fc8d..cd3a2f2b2cc 100644 --- a/rtciceconnectionstate_test.go +++ b/rtciceconnectionstate_test.go @@ -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 { diff --git a/rtcicecredentialtype.go b/rtcicecredentialtype.go index 8e58b9e3dab..03e6e5979bd 100644 --- a/rtcicecredentialtype.go +++ b/rtcicecredentialtype.go @@ -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() } diff --git a/rtcicecredentialtype_test.go b/rtcicecredentialtype_test.go index 070512f754c..87fd75f5fc2 100644 --- a/rtcicecredentialtype_test.go +++ b/rtcicecredentialtype_test.go @@ -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 { diff --git a/rtcicegatherer.go b/rtcicegatherer.go index a810a4ada9a..ef6034f912c 100644 --- a/rtcicegatherer.go +++ b/rtcicegatherer.go @@ -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) } diff --git a/rtcicegatherer_test.go b/rtcicegatherer_test.go index 323a96c3e6a..9aea01b852b 100644 --- a/rtcicegatherer_test.go +++ b/rtcicegatherer_test.go @@ -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") } diff --git a/rtcicegathererstate.go b/rtcicegathererstate.go index fafb8201c72..56133d38102 100644 --- a/rtcicegathererstate.go +++ b/rtcicegathererstate.go @@ -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 diff --git a/rtcicegathererstate_test.go b/rtcicegathererstate_test.go index a770bb2a676..7dd2eb80454 100644 --- a/rtcicegathererstate_test.go +++ b/rtcicegathererstate_test.go @@ -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 { diff --git a/rtcicegatheringstate.go b/rtcicegatheringstate.go index ea002daa594..818ee703d9f 100644 --- a/rtcicegatheringstate.go +++ b/rtcicegatheringstate.go @@ -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() } diff --git a/rtcicegatheringstate_test.go b/rtcicegatheringstate_test.go index f7e9298b364..966cdd6af96 100644 --- a/rtcicegatheringstate_test.go +++ b/rtcicegatheringstate_test.go @@ -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 { diff --git a/rtcicegatheroptions.go b/rtcicegatheroptions.go index 82a0158e206..1b1017161b0 100644 --- a/rtcicegatheroptions.go +++ b/rtcicegatheroptions.go @@ -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 } diff --git a/rtciceparameters.go b/rtciceparameters.go index 965390a943c..0c03a88bf2f 100644 --- a/rtciceparameters.go +++ b/rtciceparameters.go @@ -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"` } diff --git a/rtciceprotocol.go b/rtciceprotocol.go index b166cf99b80..b066cae10b1 100644 --- a/rtciceprotocol.go +++ b/rtciceprotocol.go @@ -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() } diff --git a/rtciceprotocol_test.go b/rtciceprotocol_test.go index d2325c701a9..151c90bd47b 100644 --- a/rtciceprotocol_test.go +++ b/rtciceprotocol_test.go @@ -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 { diff --git a/rtcicerole.go b/rtcicerole.go index 54e6e54daf2..11187863b16 100644 --- a/rtcicerole.go +++ b/rtcicerole.go @@ -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() } diff --git a/rtcicerole_test.go b/rtcicerole_test.go index 31185fb259d..4e9f9c484d1 100644 --- a/rtcicerole_test.go +++ b/rtcicerole_test.go @@ -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 { diff --git a/rtciceserver.go b/rtciceserver.go index 002fbc05ddd..e0685d9b013 100644 --- a/rtciceserver.go +++ b/rtciceserver.go @@ -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} } diff --git a/rtciceserver_test.go b/rtciceserver_test.go index 379e32adaa4..2304a5335de 100644 --- a/rtciceserver_test.go +++ b/rtciceserver_test.go @@ -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}}, } diff --git a/rtcicetransport.go b/rtcicetransport.go index de421d17fd6..9cd3f90fd1e 100644 --- a/rtcicetransport.go +++ b/rtcicetransport.go @@ -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") diff --git a/rtcicetransportpolicy.go b/rtcicetransportpolicy.go index 96e5af4d85c..15a9e57db95 100644 --- a/rtcicetransportpolicy.go +++ b/rtcicetransportpolicy.go @@ -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() } diff --git a/rtcicetransportpolicy_test.go b/rtcicetransportpolicy_test.go index 8d0d0cb69e3..70b3609d68a 100644 --- a/rtcicetransportpolicy_test.go +++ b/rtcicetransportpolicy_test.go @@ -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 { diff --git a/rtcicetransportstate.go b/rtcicetransportstate.go index 84afd21e6d8..5442c24f4e2 100644 --- a/rtcicetransportstate.go +++ b/rtcicetransportstate.go @@ -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) diff --git a/rtcicetransportstate_test.go b/rtcicetransportstate_test.go index 8590d51a8ac..b925d93147a 100644 --- a/rtcicetransportstate_test.go +++ b/rtcicetransportstate_test.go @@ -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, ) } diff --git a/rtcoauthcredential.go b/rtcoauthcredential.go index ece95601245..b0f070bcb4c 100644 --- a/rtcoauthcredential.go +++ b/rtcoauthcredential.go @@ -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 diff --git a/rtcofferansweroptions.go b/rtcofferansweroptions.go index 7c6bfa3acf6..2a34aed43af 100644 --- a/rtcofferansweroptions.go +++ b/rtcofferansweroptions.go @@ -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 } diff --git a/rtcpeerconnection.go b/rtcpeerconnection.go index b0ed132b6dd..ca590be5b79 100644 --- a/rtcpeerconnection.go +++ b/rtcpeerconnection.go @@ -32,55 +32,55 @@ const ( receiveMTU = 8192 ) -// RTCPeerConnection represents a WebRTC connection that establishes a -// peer-to-peer communications with another RTCPeerConnection instance in a +// PeerConnection represents a WebRTC connection that establishes a +// peer-to-peer communications with another PeerConnection instance in a // browser, or to another endpoint implementing the required protocols. -type RTCPeerConnection struct { +type PeerConnection struct { mu sync.RWMutex - configuration RTCConfiguration + configuration Configuration // CurrentLocalDescription represents the local description that was - // successfully negotiated the last time the RTCPeerConnection transitioned + // successfully negotiated the last time the PeerConnection transitioned // into the stable state plus any local candidates that have been generated - // by the IceAgent since the offer or answer was created. - CurrentLocalDescription *RTCSessionDescription + // by the ICEAgent since the offer or answer was created. + CurrentLocalDescription *SessionDescription // PendingLocalDescription represents a local description that is in the // process of being negotiated plus any local candidates that have been - // generated by the IceAgent since the offer or answer was created. If the - // RTCPeerConnection is in the stable state, the value is null. - PendingLocalDescription *RTCSessionDescription + // generated by the ICEAgent since the offer or answer was created. If the + // PeerConnection is in the stable state, the value is null. + PendingLocalDescription *SessionDescription // CurrentRemoteDescription represents the last remote description that was - // successfully negotiated the last time the RTCPeerConnection transitioned + // successfully negotiated the last time the PeerConnection transitioned // into the stable state plus any remote candidates that have been supplied - // via AddIceCandidate() since the offer or answer was created. - CurrentRemoteDescription *RTCSessionDescription + // via AddICECandidate() since the offer or answer was created. + CurrentRemoteDescription *SessionDescription // PendingRemoteDescription represents a remote description that is in the // process of being negotiated, complete with any remote candidates that - // have been supplied via AddIceCandidate() since the offer or answer was - // created. If the RTCPeerConnection is in the stable state, the value is + // have been supplied via AddICECandidate() since the offer or answer was + // created. If the PeerConnection is in the stable state, the value is // null. - PendingRemoteDescription *RTCSessionDescription + PendingRemoteDescription *SessionDescription // SignalingState attribute returns the signaling state of the - // RTCPeerConnection instance. - SignalingState RTCSignalingState + // PeerConnection instance. + SignalingState SignalingState - // IceGatheringState attribute returns the ICE gathering state of the - // RTCPeerConnection instance. - IceGatheringState RTCIceGatheringState // FIXME NOT-USED + // ICEGatheringState attribute returns the ICE gathering state of the + // PeerConnection instance. + ICEGatheringState ICEGatheringState // FIXME NOT-USED - // IceConnectionState attribute returns the ICE connection state of the - // RTCPeerConnection instance. - // IceConnectionState RTCIceConnectionState // FIXME SWAP-FOR-THIS - IceConnectionState ice.ConnectionState // FIXME REMOVE + // ICEConnectionState attribute returns the ICE connection state of the + // PeerConnection instance. + // ICEConnectionState ICEConnectionState // FIXME SWAP-FOR-THIS + ICEConnectionState ice.ConnectionState // FIXME REMOVE // ConnectionState attribute returns the connection state of the - // RTCPeerConnection instance. - ConnectionState RTCPeerConnectionState + // PeerConnection instance. + ConnectionState PeerConnectionState idpLoginURL *string @@ -90,56 +90,56 @@ type RTCPeerConnection struct { lastOffer string lastAnswer string - rtpTransceivers []*RTCRtpTransceiver + rtpTransceivers []*RTPTransceiver // DataChannels - dataChannels map[uint16]*RTCDataChannel + dataChannels map[uint16]*DataChannel // OnNegotiationNeeded func() // FIXME NOT-USED - // OnIceCandidate func() // FIXME NOT-USED - // OnIceCandidateError func() // FIXME NOT-USED + // OnICECandidate func() // FIXME NOT-USED + // OnICECandidateError func() // FIXME NOT-USED - // OnIceGatheringStateChange func() // FIXME NOT-USED + // OnICEGatheringStateChange func() // FIXME NOT-USED // OnConnectionStateChange func() // FIXME NOT-USED - onSignalingStateChangeHandler func(RTCSignalingState) + onSignalingStateChangeHandler func(SignalingState) onICEConnectionStateChangeHandler func(ice.ConnectionState) - onTrackHandler func(*RTCTrack) - onDataChannelHandler func(*RTCDataChannel) + onTrackHandler func(*Track) + onDataChannelHandler func(*DataChannel) - iceGatherer *RTCIceGatherer - iceTransport *RTCIceTransport - dtlsTransport *RTCDtlsTransport - sctpTransport *RTCSctpTransport + iceGatherer *ICEGatherer + iceTransport *ICETransport + dtlsTransport *DTLSTransport + sctpTransport *SCTPTransport // A reference to the associated API state used by this connection api *API } -// NewRTCPeerConnection creates a new RTCPeerConnection with the provided configuration against the received API object -func (api *API) NewRTCPeerConnection(configuration RTCConfiguration) (*RTCPeerConnection, error) { +// NewPeerConnection creates a new PeerConnection with the provided configuration against the received API object +func (api *API) NewPeerConnection(configuration Configuration) (*PeerConnection, error) { // https://w3c.github.io/webrtc-pc/#constructor (Step #2) // Some variables defined explicitly despite their implicit zero values to // allow better readability to understand what is happening. - pc := &RTCPeerConnection{ - configuration: RTCConfiguration{ - IceServers: []RTCIceServer{}, - IceTransportPolicy: RTCIceTransportPolicyAll, - BundlePolicy: RTCBundlePolicyBalanced, - RtcpMuxPolicy: RTCRtcpMuxPolicyRequire, - Certificates: []RTCCertificate{}, - IceCandidatePoolSize: 0, + pc := &PeerConnection{ + configuration: Configuration{ + ICEServers: []ICEServer{}, + ICETransportPolicy: ICETransportPolicyAll, + BundlePolicy: BundlePolicyBalanced, + RTCPMuxPolicy: RTCPMuxPolicyRequire, + Certificates: []Certificate{}, + ICECandidatePoolSize: 0, }, isClosed: false, negotiationNeeded: false, lastOffer: "", lastAnswer: "", - SignalingState: RTCSignalingStateStable, - // IceConnectionState: RTCIceConnectionStateNew, // FIXME SWAP-FOR-THIS - IceConnectionState: ice.ConnectionStateNew, // FIXME REMOVE - IceGatheringState: RTCIceGatheringStateNew, - ConnectionState: RTCPeerConnectionStateNew, - dataChannels: make(map[uint16]*RTCDataChannel), + SignalingState: SignalingStateStable, + // ICEConnectionState: ICEConnectionStateNew, // FIXME SWAP-FOR-THIS + ICEConnectionState: ice.ConnectionStateNew, // FIXME REMOVE + ICEGatheringState: ICEGatheringStateNew, + ConnectionState: PeerConnectionStateNew, + dataChannels: make(map[uint16]*DataChannel), api: api, } @@ -150,7 +150,7 @@ func (api *API) NewRTCPeerConnection(configuration RTCConfiguration) (*RTCPeerCo } // For now we eagerly allocate and start the gatherer - gatherer, err := pc.createIceGatherer() + gatherer, err := pc.createICEGatherer() if err != nil { return nil, err } @@ -176,12 +176,12 @@ func (api *API) NewRTCPeerConnection(configuration RTCConfiguration) (*RTCPeerCo return pc, nil } -// initConfiguration defines validation of the specified RTCConfiguration and +// initConfiguration defines validation of the specified Configuration and // its assignment to the internal configuration variable. This function differs // from its SetConfiguration counterpart because most of the checks do not // include verification statements related to the existing state. Thus the // function describes only minor verification of some the struct variables. -func (pc *RTCPeerConnection) initConfiguration(configuration RTCConfiguration) error { +func (pc *PeerConnection) initConfiguration(configuration Configuration) error { if configuration.PeerIdentity != "" { pc.configuration.PeerIdentity = configuration.PeerIdentity } @@ -204,45 +204,45 @@ func (pc *RTCPeerConnection) initConfiguration(configuration RTCConfiguration) e if err != nil { return err } - pc.configuration.Certificates = []RTCCertificate{*certificate} + pc.configuration.Certificates = []Certificate{*certificate} } - if configuration.BundlePolicy != RTCBundlePolicy(Unknown) { + if configuration.BundlePolicy != BundlePolicy(Unknown) { pc.configuration.BundlePolicy = configuration.BundlePolicy } - if configuration.RtcpMuxPolicy != RTCRtcpMuxPolicy(Unknown) { - pc.configuration.RtcpMuxPolicy = configuration.RtcpMuxPolicy + if configuration.RTCPMuxPolicy != RTCPMuxPolicy(Unknown) { + pc.configuration.RTCPMuxPolicy = configuration.RTCPMuxPolicy } - if configuration.IceCandidatePoolSize != 0 { - pc.configuration.IceCandidatePoolSize = configuration.IceCandidatePoolSize + if configuration.ICECandidatePoolSize != 0 { + pc.configuration.ICECandidatePoolSize = configuration.ICECandidatePoolSize } - if configuration.IceTransportPolicy != RTCIceTransportPolicy(Unknown) { - pc.configuration.IceTransportPolicy = configuration.IceTransportPolicy + if configuration.ICETransportPolicy != ICETransportPolicy(Unknown) { + pc.configuration.ICETransportPolicy = configuration.ICETransportPolicy } - if len(configuration.IceServers) > 0 { - for _, server := range configuration.IceServers { + if len(configuration.ICEServers) > 0 { + for _, server := range configuration.ICEServers { if _, err := server.validate(); err != nil { return err } } - pc.configuration.IceServers = configuration.IceServers + pc.configuration.ICEServers = configuration.ICEServers } return nil } // OnSignalingStateChange sets an event handler which is invoked when the // peer connection's signaling state changes -func (pc *RTCPeerConnection) OnSignalingStateChange(f func(RTCSignalingState)) { +func (pc *PeerConnection) OnSignalingStateChange(f func(SignalingState)) { pc.mu.Lock() defer pc.mu.Unlock() pc.onSignalingStateChangeHandler = f } -func (pc *RTCPeerConnection) onSignalingStateChange(newState RTCSignalingState) (done chan struct{}) { +func (pc *PeerConnection) onSignalingStateChange(newState SignalingState) (done chan struct{}) { pc.mu.RLock() hdlr := pc.onSignalingStateChangeHandler pc.mu.RUnlock() @@ -264,7 +264,7 @@ func (pc *RTCPeerConnection) onSignalingStateChange(newState RTCSignalingState) // OnDataChannel sets an event handler which is invoked when a data // channel message arrives from a remote peer. -func (pc *RTCPeerConnection) OnDataChannel(f func(*RTCDataChannel)) { +func (pc *PeerConnection) OnDataChannel(f func(*DataChannel)) { pc.mu.Lock() defer pc.mu.Unlock() pc.onDataChannelHandler = f @@ -272,13 +272,13 @@ func (pc *RTCPeerConnection) OnDataChannel(f func(*RTCDataChannel)) { // OnTrack sets an event handler which is called when remote track // arrives from a remote peer. -func (pc *RTCPeerConnection) OnTrack(f func(*RTCTrack)) { +func (pc *PeerConnection) OnTrack(f func(*Track)) { pc.mu.Lock() defer pc.mu.Unlock() pc.onTrackHandler = f } -func (pc *RTCPeerConnection) onTrack(t *RTCTrack) (done chan struct{}) { +func (pc *PeerConnection) onTrack(t *Track) (done chan struct{}) { pc.mu.RLock() hdlr := pc.onTrackHandler pc.mu.RUnlock() @@ -300,13 +300,13 @@ func (pc *RTCPeerConnection) onTrack(t *RTCTrack) (done chan struct{}) { // OnICEConnectionStateChange sets an event handler which is called // when an ICE connection state is changed. -func (pc *RTCPeerConnection) OnICEConnectionStateChange(f func(ice.ConnectionState)) { +func (pc *PeerConnection) OnICEConnectionStateChange(f func(ice.ConnectionState)) { pc.mu.Lock() defer pc.mu.Unlock() pc.onICEConnectionStateChangeHandler = f } -func (pc *RTCPeerConnection) onICEConnectionStateChange(cs ice.ConnectionState) (done chan struct{}) { +func (pc *PeerConnection) onICEConnectionStateChange(cs ice.ConnectionState) (done chan struct{}) { pc.mu.RLock() hdlr := pc.onICEConnectionStateChangeHandler pc.mu.RUnlock() @@ -326,8 +326,8 @@ func (pc *RTCPeerConnection) onICEConnectionStateChange(cs ice.ConnectionState) return } -// SetConfiguration updates the configuration of this RTCPeerConnection object. -func (pc *RTCPeerConnection) SetConfiguration(configuration RTCConfiguration) error { +// SetConfiguration updates the configuration of this PeerConnection object. +func (pc *PeerConnection) SetConfiguration(configuration Configuration) error { // https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-setconfiguration (step #2) if pc.isClosed { return &rtcerr.InvalidStateError{Err: ErrConnectionClosed} @@ -356,7 +356,7 @@ func (pc *RTCPeerConnection) SetConfiguration(configuration RTCConfiguration) er } // https://www.w3.org/TR/webrtc/#set-the-configuration (step #5) - if configuration.BundlePolicy != RTCBundlePolicy(Unknown) { + if configuration.BundlePolicy != BundlePolicy(Unknown) { if configuration.BundlePolicy != pc.configuration.BundlePolicy { return &rtcerr.InvalidModificationError{Err: ErrModifyingBundlePolicy} } @@ -364,46 +364,46 @@ func (pc *RTCPeerConnection) SetConfiguration(configuration RTCConfiguration) er } // https://www.w3.org/TR/webrtc/#set-the-configuration (step #6) - if configuration.RtcpMuxPolicy != RTCRtcpMuxPolicy(Unknown) { - if configuration.RtcpMuxPolicy != pc.configuration.RtcpMuxPolicy { - return &rtcerr.InvalidModificationError{Err: ErrModifyingRtcpMuxPolicy} + if configuration.RTCPMuxPolicy != RTCPMuxPolicy(Unknown) { + if configuration.RTCPMuxPolicy != pc.configuration.RTCPMuxPolicy { + return &rtcerr.InvalidModificationError{Err: ErrModifyingRTCPMuxPolicy} } - pc.configuration.RtcpMuxPolicy = configuration.RtcpMuxPolicy + pc.configuration.RTCPMuxPolicy = configuration.RTCPMuxPolicy } // https://www.w3.org/TR/webrtc/#set-the-configuration (step #7) - if configuration.IceCandidatePoolSize != 0 { - if pc.configuration.IceCandidatePoolSize != configuration.IceCandidatePoolSize && + if configuration.ICECandidatePoolSize != 0 { + if pc.configuration.ICECandidatePoolSize != configuration.ICECandidatePoolSize && pc.LocalDescription() != nil { - return &rtcerr.InvalidModificationError{Err: ErrModifyingIceCandidatePoolSize} + return &rtcerr.InvalidModificationError{Err: ErrModifyingICECandidatePoolSize} } - pc.configuration.IceCandidatePoolSize = configuration.IceCandidatePoolSize + pc.configuration.ICECandidatePoolSize = configuration.ICECandidatePoolSize } // https://www.w3.org/TR/webrtc/#set-the-configuration (step #8) - if configuration.IceTransportPolicy != RTCIceTransportPolicy(Unknown) { - pc.configuration.IceTransportPolicy = configuration.IceTransportPolicy + if configuration.ICETransportPolicy != ICETransportPolicy(Unknown) { + pc.configuration.ICETransportPolicy = configuration.ICETransportPolicy } // https://www.w3.org/TR/webrtc/#set-the-configuration (step #11) - if len(configuration.IceServers) > 0 { + if len(configuration.ICEServers) > 0 { // https://www.w3.org/TR/webrtc/#set-the-configuration (step #11.3) - for _, server := range configuration.IceServers { + for _, server := range configuration.ICEServers { if _, err := server.validate(); err != nil { return err } } - pc.configuration.IceServers = configuration.IceServers + pc.configuration.ICEServers = configuration.ICEServers } return nil } -// GetConfiguration returns an RTCConfiguration object representing the current -// configuration of this RTCPeerConnection object. The returned object is a +// GetConfiguration returns a Configuration object representing the current +// configuration of this PeerConnection object. The returned object is a // copy and direct mutation on it will not take affect until SetConfiguration -// has been called with RTCConfiguration passed as its only argument. +// has been called with Configuration passed as its only argument. // https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-getconfiguration -func (pc *RTCPeerConnection) GetConfiguration() RTCConfiguration { +func (pc *PeerConnection) GetConfiguration() Configuration { return pc.configuration } @@ -411,15 +411,15 @@ func (pc *RTCPeerConnection) GetConfiguration() RTCConfiguration { // --- FIXME - BELOW CODE NEEDS REVIEW/CLEANUP // ------------------------------------------------------------------------ -// CreateOffer starts the RTCPeerConnection and generates the localDescription -func (pc *RTCPeerConnection) CreateOffer(options *RTCOfferOptions) (RTCSessionDescription, error) { +// CreateOffer starts the PeerConnection and generates the localDescription +func (pc *PeerConnection) CreateOffer(options *OfferOptions) (SessionDescription, error) { useIdentity := pc.idpLoginURL != nil if options != nil { - return RTCSessionDescription{}, errors.Errorf("TODO handle options") + return SessionDescription{}, errors.Errorf("TODO handle options") } else if useIdentity { - return RTCSessionDescription{}, errors.Errorf("TODO handle identity provider") + return SessionDescription{}, errors.Errorf("TODO handle identity provider") } else if pc.isClosed { - return RTCSessionDescription{}, &rtcerr.InvalidStateError{Err: ErrConnectionClosed} + return SessionDescription{}, &rtcerr.InvalidStateError{Err: ErrConnectionClosed} } d := sdp.NewJSEPSessionDescription(useIdentity) @@ -427,20 +427,20 @@ func (pc *RTCPeerConnection) CreateOffer(options *RTCOfferOptions) (RTCSessionDe iceParams, err := pc.iceGatherer.GetLocalParameters() if err != nil { - return RTCSessionDescription{}, err + return SessionDescription{}, err } candidates, err := pc.iceGatherer.GetLocalCandidates() if err != nil { - return RTCSessionDescription{}, err + return SessionDescription{}, err } bundleValue := "BUNDLE" - if pc.addRTPMediaSection(d, RTCRtpCodecTypeAudio, "audio", iceParams, RTCRtpTransceiverDirectionSendrecv, candidates, sdp.ConnectionRoleActpass) { + if pc.addRTPMediaSection(d, RTPCodecTypeAudio, "audio", iceParams, RTPTransceiverDirectionSendrecv, candidates, sdp.ConnectionRoleActpass) { bundleValue += " audio" } - if pc.addRTPMediaSection(d, RTCRtpCodecTypeVideo, "video", iceParams, RTCRtpTransceiverDirectionSendrecv, candidates, sdp.ConnectionRoleActpass) { + if pc.addRTPMediaSection(d, RTPCodecTypeVideo, "video", iceParams, RTPTransceiverDirectionSendrecv, candidates, sdp.ConnectionRoleActpass) { bundleValue += " video" } @@ -451,8 +451,8 @@ func (pc *RTCPeerConnection) CreateOffer(options *RTCOfferOptions) (RTCSessionDe m.WithPropertyAttribute("setup:actpass") } - desc := RTCSessionDescription{ - Type: RTCSdpTypeOffer, + desc := SessionDescription{ + Type: SDPTypeOffer, Sdp: d.Marshal(), parsed: d, } @@ -460,9 +460,9 @@ func (pc *RTCPeerConnection) CreateOffer(options *RTCOfferOptions) (RTCSessionDe return desc, nil } -func (pc *RTCPeerConnection) createIceGatherer() (*RTCIceGatherer, error) { - g, err := pc.api.NewRTCIceGatherer(RTCIceGatherOptions{ - ICEServers: pc.configuration.IceServers, +func (pc *PeerConnection) createICEGatherer() (*ICEGatherer, error) { + g, err := pc.api.NewICEGatherer(ICEGatherOptions{ + ICEServers: pc.configuration.ICEServers, // TODO: GatherPolicy }) if err != nil { @@ -472,14 +472,14 @@ func (pc *RTCPeerConnection) createIceGatherer() (*RTCIceGatherer, error) { return g, nil } -func (pc *RTCPeerConnection) gather() error { +func (pc *PeerConnection) gather() error { return pc.iceGatherer.Gather() } -func (pc *RTCPeerConnection) createICETransport() *RTCIceTransport { - t := pc.api.NewRTCIceTransport(pc.iceGatherer) +func (pc *PeerConnection) createICETransport() *ICETransport { + t := pc.api.NewICETransport(pc.iceGatherer) - t.OnConnectionStateChange(func(state RTCIceTransportState) { + t.OnConnectionStateChange(func(state ICETransportState) { // We convert the state back to the ICE state to not brake the // existing public API at this point. iceState := state.toICE() @@ -489,30 +489,30 @@ func (pc *RTCPeerConnection) createICETransport() *RTCIceTransport { return t } -func (pc *RTCPeerConnection) createDTLSTransport() (*RTCDtlsTransport, error) { - dtlsTransport, err := pc.api.NewRTCDtlsTransport(pc.iceTransport, pc.configuration.Certificates) +func (pc *PeerConnection) createDTLSTransport() (*DTLSTransport, error) { + dtlsTransport, err := pc.api.NewDTLSTransport(pc.iceTransport, pc.configuration.Certificates) return dtlsTransport, err } -// CreateAnswer starts the RTCPeerConnection and generates the localDescription -func (pc *RTCPeerConnection) CreateAnswer(options *RTCAnswerOptions) (RTCSessionDescription, error) { +// CreateAnswer starts the PeerConnection and generates the localDescription +func (pc *PeerConnection) CreateAnswer(options *AnswerOptions) (SessionDescription, error) { useIdentity := pc.idpLoginURL != nil if options != nil { - return RTCSessionDescription{}, errors.Errorf("TODO handle options") + return SessionDescription{}, errors.Errorf("TODO handle options") } else if useIdentity { - return RTCSessionDescription{}, errors.Errorf("TODO handle identity provider") + return SessionDescription{}, errors.Errorf("TODO handle identity provider") } else if pc.isClosed { - return RTCSessionDescription{}, &rtcerr.InvalidStateError{Err: ErrConnectionClosed} + return SessionDescription{}, &rtcerr.InvalidStateError{Err: ErrConnectionClosed} } iceParams, err := pc.iceGatherer.GetLocalParameters() if err != nil { - return RTCSessionDescription{}, err + return SessionDescription{}, err } candidates, err := pc.iceGatherer.GetLocalCandidates() if err != nil { - return RTCSessionDescription{}, err + return SessionDescription{}, err } d := sdp.NewJSEPSessionDescription(useIdentity) @@ -521,17 +521,17 @@ func (pc *RTCPeerConnection) CreateAnswer(options *RTCAnswerOptions) (RTCSession bundleValue := "BUNDLE" for _, remoteMedia := range pc.RemoteDescription().parsed.MediaDescriptions { // TODO @trivigy better SDP parser - var peerDirection RTCRtpTransceiverDirection + var peerDirection RTPTransceiverDirection midValue := "" for _, a := range remoteMedia.Attributes { if strings.HasPrefix(*a.String(), "mid") { midValue = (*a.String())[len("mid:"):] } else if strings.HasPrefix(*a.String(), "sendrecv") { - peerDirection = RTCRtpTransceiverDirectionSendrecv + peerDirection = RTPTransceiverDirectionSendrecv } else if strings.HasPrefix(*a.String(), "sendonly") { - peerDirection = RTCRtpTransceiverDirectionSendonly + peerDirection = RTPTransceiverDirectionSendonly } else if strings.HasPrefix(*a.String(), "recvonly") { - peerDirection = RTCRtpTransceiverDirectionRecvonly + peerDirection = RTPTransceiverDirectionRecvonly } } @@ -540,11 +540,11 @@ func (pc *RTCPeerConnection) CreateAnswer(options *RTCAnswerOptions) (RTCSession } if strings.HasPrefix(*remoteMedia.MediaName.String(), "audio") { - if pc.addRTPMediaSection(d, RTCRtpCodecTypeAudio, midValue, iceParams, peerDirection, candidates, sdp.ConnectionRoleActive) { + if pc.addRTPMediaSection(d, RTPCodecTypeAudio, midValue, iceParams, peerDirection, candidates, sdp.ConnectionRoleActive) { appendBundle() } } else if strings.HasPrefix(*remoteMedia.MediaName.String(), "video") { - if pc.addRTPMediaSection(d, RTCRtpCodecTypeVideo, midValue, iceParams, peerDirection, candidates, sdp.ConnectionRoleActive) { + if pc.addRTPMediaSection(d, RTPCodecTypeVideo, midValue, iceParams, peerDirection, candidates, sdp.ConnectionRoleActive) { appendBundle() } } else if strings.HasPrefix(*remoteMedia.MediaName.String(), "application") { @@ -555,8 +555,8 @@ func (pc *RTCPeerConnection) CreateAnswer(options *RTCAnswerOptions) (RTCSession d = d.WithValueAttribute(sdp.AttrKeyGroup, bundleValue) - desc := RTCSessionDescription{ - Type: RTCSdpTypeAnswer, + desc := SessionDescription{ + Type: SDPTypeAnswer, Sdp: d.Marshal(), parsed: d, } @@ -564,56 +564,56 @@ func (pc *RTCPeerConnection) CreateAnswer(options *RTCAnswerOptions) (RTCSession return desc, nil } -// 4.4.1.6 Set the RTCSessionDescription -func (pc *RTCPeerConnection) setDescription(sd *RTCSessionDescription, op rtcStateChangeOp) error { +// 4.4.1.6 Set the SessionDescription +func (pc *PeerConnection) setDescription(sd *SessionDescription, op stateChangeOp) error { if pc.isClosed { return &rtcerr.InvalidStateError{Err: ErrConnectionClosed} } cur := pc.SignalingState - setLocal := rtcStateChangeOpSetLocal - setRemote := rtcStateChangeOpSetRemote + setLocal := stateChangeOpSetLocal + setRemote := stateChangeOpSetRemote newSdpDoesNotMatchOffer := &rtcerr.InvalidModificationError{Err: errors.New("New sdp does not match previous offer")} newSdpDoesNotMatchAnswer := &rtcerr.InvalidModificationError{Err: errors.New("New sdp does not match previous answer")} - var nextState RTCSignalingState + var nextState SignalingState var err error switch op { case setLocal: switch sd.Type { // stable->SetLocal(offer)->have-local-offer - case RTCSdpTypeOffer: + case SDPTypeOffer: if sd.Sdp != pc.lastOffer { return newSdpDoesNotMatchOffer } - nextState, err = checkNextSignalingState(cur, RTCSignalingStateHaveLocalOffer, setLocal, sd.Type) + nextState, err = checkNextSignalingState(cur, SignalingStateHaveLocalOffer, setLocal, sd.Type) if err == nil { pc.PendingLocalDescription = sd } // have-remote-offer->SetLocal(answer)->stable // have-local-pranswer->SetLocal(answer)->stable - case RTCSdpTypeAnswer: + case SDPTypeAnswer: if sd.Sdp != pc.lastAnswer { return newSdpDoesNotMatchAnswer } - nextState, err = checkNextSignalingState(cur, RTCSignalingStateStable, setLocal, sd.Type) + nextState, err = checkNextSignalingState(cur, SignalingStateStable, setLocal, sd.Type) if err == nil { pc.CurrentLocalDescription = sd pc.CurrentRemoteDescription = pc.PendingRemoteDescription pc.PendingRemoteDescription = nil pc.PendingLocalDescription = nil } - case RTCSdpTypeRollback: - nextState, err = checkNextSignalingState(cur, RTCSignalingStateStable, setLocal, sd.Type) + case SDPTypeRollback: + nextState, err = checkNextSignalingState(cur, SignalingStateStable, setLocal, sd.Type) if err == nil { pc.PendingLocalDescription = nil } // have-remote-offer->SetLocal(pranswer)->have-local-pranswer - case RTCSdpTypePranswer: + case SDPTypePranswer: if sd.Sdp != pc.lastAnswer { return newSdpDoesNotMatchAnswer } - nextState, err = checkNextSignalingState(cur, RTCSignalingStateHaveLocalPranswer, setLocal, sd.Type) + nextState, err = checkNextSignalingState(cur, SignalingStateHaveLocalPranswer, setLocal, sd.Type) if err == nil { pc.PendingLocalDescription = sd } @@ -623,29 +623,29 @@ func (pc *RTCPeerConnection) setDescription(sd *RTCSessionDescription, op rtcSta case setRemote: switch sd.Type { // stable->SetRemote(offer)->have-remote-offer - case RTCSdpTypeOffer: - nextState, err = checkNextSignalingState(cur, RTCSignalingStateHaveRemoteOffer, setRemote, sd.Type) + case SDPTypeOffer: + nextState, err = checkNextSignalingState(cur, SignalingStateHaveRemoteOffer, setRemote, sd.Type) if err == nil { pc.PendingRemoteDescription = sd } // have-local-offer->SetRemote(answer)->stable // have-remote-pranswer->SetRemote(answer)->stable - case RTCSdpTypeAnswer: - nextState, err = checkNextSignalingState(cur, RTCSignalingStateStable, setRemote, sd.Type) + case SDPTypeAnswer: + nextState, err = checkNextSignalingState(cur, SignalingStateStable, setRemote, sd.Type) if err == nil { pc.CurrentRemoteDescription = sd pc.CurrentLocalDescription = pc.PendingLocalDescription pc.PendingRemoteDescription = nil pc.PendingLocalDescription = nil } - case RTCSdpTypeRollback: - nextState, err = checkNextSignalingState(cur, RTCSignalingStateStable, setRemote, sd.Type) + case SDPTypeRollback: + nextState, err = checkNextSignalingState(cur, SignalingStateStable, setRemote, sd.Type) if err == nil { pc.PendingRemoteDescription = nil } // have-local-offer->SetRemote(pranswer)->have-remote-pranswer - case RTCSdpTypePranswer: - nextState, err = checkNextSignalingState(cur, RTCSignalingStateHaveRemotePranswer, setRemote, sd.Type) + case SDPTypePranswer: + nextState, err = checkNextSignalingState(cur, SignalingStateHaveRemotePranswer, setRemote, sd.Type) if err == nil { pc.PendingRemoteDescription = sd } @@ -664,7 +664,7 @@ func (pc *RTCPeerConnection) setDescription(sd *RTCSessionDescription, op rtcSta } // SetLocalDescription sets the SessionDescription of the local peer -func (pc *RTCPeerConnection) SetLocalDescription(desc RTCSessionDescription) error { +func (pc *PeerConnection) SetLocalDescription(desc SessionDescription) error { if pc.isClosed { return &rtcerr.InvalidStateError{Err: ErrConnectionClosed} } @@ -672,9 +672,9 @@ func (pc *RTCPeerConnection) SetLocalDescription(desc RTCSessionDescription) err // JSEP 5.4 if desc.Sdp == "" { switch desc.Type { - case RTCSdpTypeAnswer, RTCSdpTypePranswer: + case SDPTypeAnswer, SDPTypePranswer: desc.Sdp = pc.lastAnswer - case RTCSdpTypeOffer: + case SDPTypeOffer: desc.Sdp = pc.lastOffer default: return &rtcerr.InvalidModificationError{ @@ -689,14 +689,14 @@ func (pc *RTCPeerConnection) SetLocalDescription(desc RTCSessionDescription) err if err := desc.parsed.Unmarshal(desc.Sdp); err != nil { return err } - return pc.setDescription(&desc, rtcStateChangeOpSetLocal) + return pc.setDescription(&desc, stateChangeOpSetLocal) } // LocalDescription returns PendingLocalDescription if it is not null and // otherwise it returns CurrentLocalDescription. This property is used to // determine if setLocalDescription has already been called. // https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-localdescription -func (pc *RTCPeerConnection) LocalDescription() *RTCSessionDescription { +func (pc *PeerConnection) LocalDescription() *SessionDescription { if pc.PendingLocalDescription != nil { return pc.PendingLocalDescription } @@ -704,7 +704,7 @@ func (pc *RTCPeerConnection) LocalDescription() *RTCSessionDescription { } // SetRemoteDescription sets the SessionDescription of the remote peer -func (pc *RTCPeerConnection) SetRemoteDescription(desc RTCSessionDescription) error { +func (pc *PeerConnection) SetRemoteDescription(desc SessionDescription) error { // FIXME: Remove this when renegotiation is supported if pc.CurrentRemoteDescription != nil { return errors.Errorf("remoteDescription is already defined, SetRemoteDescription can only be called once") @@ -717,14 +717,14 @@ func (pc *RTCPeerConnection) SetRemoteDescription(desc RTCSessionDescription) er if err := desc.parsed.Unmarshal(desc.Sdp); err != nil { return err } - if err := pc.setDescription(&desc, rtcStateChangeOpSetRemote); err != nil { + if err := pc.setDescription(&desc, stateChangeOpSetRemote); err != nil { return err } weOffer := true remoteUfrag := "" remotePwd := "" - if desc.Type == RTCSdpTypeOffer { + if desc.Type == SDPTypeOffer { weOffer = false } @@ -736,7 +736,7 @@ func (pc *RTCPeerConnection) SetRemoteDescription(desc RTCSessionDescription) er return err } - candidate, err := newRTCIceCandidateFromSDP(sdpCandidate) + candidate, err := newICECandidateFromSDP(sdpCandidate) if err != nil { return err } @@ -768,11 +768,11 @@ func (pc *RTCPeerConnection) SetRemoteDescription(desc RTCSessionDescription) er fingerprintHash = parts[0] // Create the SCTP transport - sctp := pc.api.NewRTCSctpTransport(pc.dtlsTransport) + sctp := pc.api.NewSCTPTransport(pc.dtlsTransport) pc.sctpTransport = sctp // Wire up the on datachannel handler - sctp.OnDataChannel(func(d *RTCDataChannel) { + sctp.OnDataChannel(func(d *DataChannel) { pc.mu.RLock() hdlr := pc.onDataChannelHandler pc.mu.RUnlock() @@ -786,16 +786,16 @@ func (pc *RTCPeerConnection) SetRemoteDescription(desc RTCSessionDescription) er // the connection is actually established. // Start the ice transport - iceRole := RTCIceRoleControlled + iceRole := ICERoleControlled if weOffer { - iceRole = RTCIceRoleControlling + iceRole = ICERoleControlling } err := pc.iceTransport.Start( pc.iceGatherer, - RTCIceParameters{ + ICEParameters{ UsernameFragment: remoteUfrag, Password: remotePwd, - IceLite: false, + ICELite: false, }, &iceRole, ) @@ -807,9 +807,9 @@ func (pc *RTCPeerConnection) SetRemoteDescription(desc RTCSessionDescription) er } // Start the dtls transport - err = pc.dtlsTransport.Start(RTCDtlsParameters{ - Role: RTCDtlsRoleAuto, - Fingerprints: []RTCDtlsFingerprint{{Algorithm: fingerprintHash, Value: fingerprint}}, + err = pc.dtlsTransport.Start(DTLSParameters{ + Role: DTLSRoleAuto, + Fingerprints: []DTLSFingerprint{{Algorithm: fingerprintHash, Value: fingerprint}}, }) if err != nil { // TODO: Handle error @@ -825,9 +825,9 @@ func (pc *RTCPeerConnection) SetRemoteDescription(desc RTCSessionDescription) er for _, tranceiver := range pc.rtpTransceivers { if tranceiver.Sender != nil { - tranceiver.Sender.Send(RTCRtpSendParameters{ - encodings: RTCRtpEncodingParameters{ - RTCRtpCodingParameters{SSRC: tranceiver.Sender.Track.Ssrc, PayloadType: tranceiver.Sender.Track.PayloadType}, + tranceiver.Sender.Send(RTPSendParameters{ + encodings: RTPEncodingParameters{ + RTPCodingParameters{SSRC: tranceiver.Sender.Track.Ssrc, PayloadType: tranceiver.Sender.Track.PayloadType}, }}) } } @@ -835,7 +835,7 @@ func (pc *RTCPeerConnection) SetRemoteDescription(desc RTCSessionDescription) er go pc.drainSRTP() // Start sctp - err = pc.sctpTransport.Start(RTCSctpCapabilities{ + err = pc.sctpTransport.Start(SCTPCapabilities{ MaxMessageSize: 0, }) if err != nil { @@ -852,7 +852,7 @@ func (pc *RTCPeerConnection) SetRemoteDescription(desc RTCSessionDescription) er } // openDataChannels opens the existing data channels -func (pc *RTCPeerConnection) openDataChannels() { +func (pc *PeerConnection) openDataChannels() { for _, d := range pc.dataChannels { err := d.open(pc.sctpTransport) if err != nil { @@ -863,16 +863,16 @@ func (pc *RTCPeerConnection) openDataChannels() { } // openSRTP opens knows inbound SRTP streams from the RemoteDescription -func (pc *RTCPeerConnection) openSRTP() { - incomingSSRCes := map[uint32]RTCRtpCodecType{} +func (pc *PeerConnection) openSRTP() { + incomingSSRCes := map[uint32]RTPCodecType{} for _, media := range pc.RemoteDescription().parsed.MediaDescriptions { for _, attr := range media.Attributes { - var codecType RTCRtpCodecType + var codecType RTPCodecType if media.MediaName.Media == "audio" { - codecType = RTCRtpCodecTypeAudio + codecType = RTPCodecTypeAudio } else if media.MediaName.Media == "video" { - codecType = RTCRtpCodecTypeVideo + codecType = RTPCodecTypeVideo } else { continue } @@ -890,11 +890,11 @@ func (pc *RTCPeerConnection) openSRTP() { } for i := range incomingSSRCes { - go func(ssrc uint32, codecType RTCRtpCodecType) { - receiver := NewRTCRtpReceiver(codecType, pc.dtlsTransport) - <-receiver.Receive(RTCRtpReceiveParameters{ - encodings: RTCRtpDecodingParameters{ - RTCRtpCodingParameters{SSRC: ssrc}, + go func(ssrc uint32, codecType RTPCodecType) { + receiver := NewRTPReceiver(codecType, pc.dtlsTransport) + <-receiver.Receive(RTPReceiveParameters{ + encodings: RTPDecodingParameters{ + RTPCodingParameters{SSRC: ssrc}, }}) sdpCodec, err := pc.CurrentLocalDescription.parsed.GetCodecForPayloadType(receiver.Track.PayloadType) @@ -911,10 +911,10 @@ func (pc *RTCPeerConnection) openSRTP() { receiver.Track.Kind = codec.Type receiver.Track.Codec = codec - pc.newRTCRtpTransceiver( + pc.newRTPTransceiver( receiver, nil, - RTCRtpTransceiverDirectionRecvonly, + RTPTransceiverDirectionRecvonly, ) pc.onTrack(receiver.Track) @@ -927,7 +927,7 @@ func (pc *RTCPeerConnection) openSRTP() { // These could be sent to the user, but right now we don't provide an API // to distribute orphaned RTCP messages. This is needed to make sure we don't block // and provides useful debugging messages -func (pc *RTCPeerConnection) drainSRTP() { +func (pc *PeerConnection) drainSRTP() { go func() { for { srtpSession, err := pc.dtlsTransport.getSRTPSession() @@ -1000,17 +1000,17 @@ func (pc *RTCPeerConnection) drainSRTP() { // otherwise it returns CurrentRemoteDescription. This property is used to // determine if setRemoteDescription has already been called. // https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-remotedescription -func (pc *RTCPeerConnection) RemoteDescription() *RTCSessionDescription { +func (pc *PeerConnection) RemoteDescription() *SessionDescription { if pc.PendingRemoteDescription != nil { return pc.PendingRemoteDescription } return pc.CurrentRemoteDescription } -// AddIceCandidate accepts an ICE candidate string and adds it +// AddICECandidate accepts an ICE candidate string and adds it // to the existing set of candidates -func (pc *RTCPeerConnection) AddIceCandidate(s string) error { - // TODO: AddIceCandidate should take RTCIceCandidateInit +func (pc *PeerConnection) AddICECandidate(s string) error { + // TODO: AddICECandidate should take ICECandidateInit if pc.RemoteDescription() == nil { return &rtcerr.InvalidStateError{Err: ErrNoRemoteDescription} } @@ -1023,7 +1023,7 @@ func (pc *RTCPeerConnection) AddIceCandidate(s string) error { return err } - candidate, err := newRTCIceCandidateFromSDP(sdpCandidate) + candidate, err := newICECandidateFromSDP(sdpCandidate) if err != nil { return err } @@ -1035,12 +1035,12 @@ func (pc *RTCPeerConnection) AddIceCandidate(s string) error { // --- FIXME - BELOW CODE NEEDS RE-ORGANIZATION - https://w3c.github.io/webrtc-pc/#rtp-media-api // ------------------------------------------------------------------------ -// GetSenders returns the RTCRtpSender that are currently attached to this RTCPeerConnection -func (pc *RTCPeerConnection) GetSenders() []*RTCRtpSender { +// GetSenders returns the RTPSender that are currently attached to this PeerConnection +func (pc *PeerConnection) GetSenders() []*RTPSender { pc.mu.Lock() defer pc.mu.Unlock() - result := make([]*RTCRtpSender, len(pc.rtpTransceivers)) + result := make([]*RTPSender, len(pc.rtpTransceivers)) for i, tranceiver := range pc.rtpTransceivers { if tranceiver.Sender != nil { result[i] = tranceiver.Sender @@ -1049,12 +1049,12 @@ func (pc *RTCPeerConnection) GetSenders() []*RTCRtpSender { return result } -// GetReceivers returns the RTCRtpReceivers that are currently attached to this RTCPeerConnection -func (pc *RTCPeerConnection) GetReceivers() []*RTCRtpReceiver { +// GetReceivers returns the RTPReceivers that are currently attached to this RTCPeerConnection +func (pc *PeerConnection) GetReceivers() []*RTPReceiver { pc.mu.Lock() defer pc.mu.Unlock() - result := make([]*RTCRtpReceiver, len(pc.rtpTransceivers)) + result := make([]*RTPReceiver, len(pc.rtpTransceivers)) for i, tranceiver := range pc.rtpTransceivers { if tranceiver.Receiver != nil { result[i] = tranceiver.Receiver @@ -1065,15 +1065,15 @@ func (pc *RTCPeerConnection) GetReceivers() []*RTCRtpReceiver { } // GetTransceivers returns the RTCRtpTransceiver that are currently attached to this RTCPeerConnection -func (pc *RTCPeerConnection) GetTransceivers() []*RTCRtpTransceiver { +func (pc *PeerConnection) GetTransceivers() []*RTPTransceiver { pc.mu.Lock() defer pc.mu.Unlock() return pc.rtpTransceivers } -// AddTrack adds a RTCTrack to the RTCPeerConnection -func (pc *RTCPeerConnection) AddTrack(track *RTCTrack) (*RTCRtpSender, error) { +// AddTrack adds a Track to the PeerConnection +func (pc *PeerConnection) AddTrack(track *Track) (*RTPSender, error) { if pc.isClosed { return nil, &rtcerr.InvalidStateError{Err: ErrConnectionClosed} } @@ -1085,7 +1085,7 @@ func (pc *RTCPeerConnection) AddTrack(track *RTCTrack) (*RTCRtpSender, error) { return nil, &rtcerr.InvalidAccessError{Err: ErrExistingTrack} } } - var transceiver *RTCRtpTransceiver + var transceiver *RTPTransceiver for _, t := range pc.rtpTransceivers { if !t.stopped && // t.Sender == nil && // TODO: check that the sender has never sent @@ -1101,11 +1101,11 @@ func (pc *RTCPeerConnection) AddTrack(track *RTCTrack) (*RTCRtpSender, error) { return nil, err } } else { - sender := NewRTCRtpSender(track, pc.dtlsTransport) - transceiver = pc.newRTCRtpTransceiver( + sender := NewRTPSender(track, pc.dtlsTransport) + transceiver = pc.newRTPTransceiver( nil, sender, - RTCRtpTransceiverDirectionSendonly, + RTPTransceiverDirectionSendonly, ) } @@ -1114,11 +1114,11 @@ func (pc *RTCPeerConnection) AddTrack(track *RTCTrack) (*RTCRtpSender, error) { return transceiver.Sender, nil } -// func (pc *RTCPeerConnection) RemoveTrack() { +// func (pc *PeerConnection) RemoveTrack() { // panic("not implemented yet") // FIXME NOT-IMPLEMENTED nolint // } -// func (pc *RTCPeerConnection) AddTransceiver() RTCRtpTransceiver { +// func (pc *PeerConnection) AddTransceiver() RTPTransceiver { // panic("not implemented yet") // FIXME NOT-IMPLEMENTED nolint // } @@ -1126,19 +1126,19 @@ func (pc *RTCPeerConnection) AddTrack(track *RTCTrack) (*RTCRtpSender, error) { // --- FIXME - BELOW CODE NEEDS RE-ORGANIZATION - https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api // ------------------------------------------------------------------------ -// CreateDataChannel creates a new RTCDataChannel object with the given label -// and optional RTCDataChannelInit used to configure properties of the +// CreateDataChannel creates a new DataChannel object with the given label +// and optional DataChannelInit used to configure properties of the // underlying channel such as data reliability. -func (pc *RTCPeerConnection) CreateDataChannel(label string, options *RTCDataChannelInit) (*RTCDataChannel, error) { +func (pc *PeerConnection) CreateDataChannel(label string, options *DataChannelInit) (*DataChannel, error) { // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #2) if pc.isClosed { return nil, &rtcerr.InvalidStateError{Err: ErrConnectionClosed} } - // TODO: Add additional options once implemented. RTCDataChannelInit - // implements all options. RTCDataChannelParameters implements the + // TODO: Add additional options once implemented. DataChannelInit + // implements all options. DataChannelParameters implements the // options that actually have an effect at this point. - params := &RTCDataChannelParameters{ + params := &DataChannelParameters{ Label: label, } @@ -1161,7 +1161,7 @@ func (pc *RTCPeerConnection) CreateDataChannel(label string, options *RTCDataCha // some members are set to a non zero value default due to the default // definitions in https://w3c.github.io/webrtc-pc/#dom-rtcdatachannelinit // which are later overwriten by the options if any were specified. - channel := RTCDataChannel{ + channel := DataChannel{ rtcPeerConnection: pc, // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #4) Label: label, @@ -1171,7 +1171,7 @@ func (pc *RTCPeerConnection) CreateDataChannel(label string, options *RTCDataCha Protocol: "", Negotiated: false, ID: nil, - Priority: RTCPriorityTypeLow, + Priority: PriorityTypeLow, // https://w3c.github.io/webrtc-pc/#dfn-create-an-rtcdatachannel (Step #3) BufferedAmount: 0, } @@ -1236,13 +1236,13 @@ func (pc *RTCPeerConnection) CreateDataChannel(label string, options *RTCDataCha return nil, &rtcerr.TypeError{Err: ErrMaxDataChannelID} } - if pc.sctpTransport.State == RTCSctpTransportStateConnected && + if pc.sctpTransport.State == SCTPTransportStateConnected && *channel.ID >= *pc.sctpTransport.MaxChannels { return nil, &rtcerr.OperationError{Err: ErrMaxDataChannelID} } */ - d, err := pc.api.newRTCDataChannel(params) + d, err := pc.api.newDataChannel(params) if err != nil { return nil, err } @@ -1261,7 +1261,7 @@ func (pc *RTCPeerConnection) CreateDataChannel(label string, options *RTCDataCha return d, nil } -func (pc *RTCPeerConnection) generateDataChannelID(client bool) (uint16, error) { +func (pc *PeerConnection) generateDataChannelID(client bool) (uint16, error) { var id uint16 if !client { id++ @@ -1282,13 +1282,13 @@ func (pc *RTCPeerConnection) generateDataChannelID(client bool) (uint16, error) } // SetIdentityProvider is used to configure an identity provider to generate identity assertions -func (pc *RTCPeerConnection) SetIdentityProvider(provider string) error { +func (pc *PeerConnection) SetIdentityProvider(provider string) error { return errors.Errorf("TODO SetIdentityProvider") } // SendRTCP sends a user provided RTCP packet to the connected peer // If no peer is connected the packet is discarded -func (pc *RTCPeerConnection) SendRTCP(pkt rtcp.Packet) error { +func (pc *PeerConnection) SendRTCP(pkt rtcp.Packet) error { raw, err := pkt.Marshal() if err != nil { return err @@ -1310,8 +1310,8 @@ func (pc *RTCPeerConnection) SendRTCP(pkt rtcp.Packet) error { return nil } -// Close ends the RTCPeerConnection -func (pc *RTCPeerConnection) Close() error { +// Close ends the PeerConnection +func (pc *PeerConnection) Close() error { // https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #2) if pc.isClosed { return nil @@ -1321,14 +1321,14 @@ func (pc *RTCPeerConnection) Close() error { pc.isClosed = true // https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #4) - pc.SignalingState = RTCSignalingStateClosed + pc.SignalingState = SignalingStateClosed // https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #11) - // pc.IceConnectionState = RTCIceConnectionStateClosed + // pc.ICEConnectionState = ICEConnectionStateClosed pc.iceStateChange(ice.ConnectionStateClosed) // FIXME REMOVE // https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #12) - pc.ConnectionState = RTCPeerConnectionStateClosed + pc.ConnectionState = PeerConnectionStateClosed // Try closing everything and collect the errors var closeErrs []error @@ -1385,35 +1385,35 @@ func flattenErrs(errs []error) error { return fmt.Errorf(strings.Join(errstrings, "\n")) } -func (pc *RTCPeerConnection) iceStateChange(newState ice.ConnectionState) { +func (pc *PeerConnection) iceStateChange(newState ice.ConnectionState) { pc.mu.Lock() - pc.IceConnectionState = newState + pc.ICEConnectionState = newState pc.mu.Unlock() pc.onICEConnectionStateChange(newState) } -func localDirection(weSend bool, peerDirection RTCRtpTransceiverDirection) RTCRtpTransceiverDirection { - theySend := (peerDirection == RTCRtpTransceiverDirectionSendrecv || peerDirection == RTCRtpTransceiverDirectionSendonly) +func localDirection(weSend bool, peerDirection RTPTransceiverDirection) RTPTransceiverDirection { + theySend := (peerDirection == RTPTransceiverDirectionSendrecv || peerDirection == RTPTransceiverDirectionSendonly) if weSend && theySend { - return RTCRtpTransceiverDirectionSendrecv + return RTPTransceiverDirectionSendrecv } else if weSend && !theySend { - return RTCRtpTransceiverDirectionSendonly + return RTPTransceiverDirectionSendonly } else if !weSend && theySend { - return RTCRtpTransceiverDirectionRecvonly + return RTPTransceiverDirectionRecvonly } - return RTCRtpTransceiverDirectionInactive + return RTPTransceiverDirectionInactive } -func (pc *RTCPeerConnection) addFingerprint(d *sdp.SessionDescription) { +func (pc *PeerConnection) addFingerprint(d *sdp.SessionDescription) { // TODO: Handle multiple certificates for _, fingerprint := range pc.configuration.Certificates[0].GetFingerprints() { d.WithFingerprint(fingerprint.Algorithm, strings.ToUpper(fingerprint.Value)) } } -func (pc *RTCPeerConnection) addRTPMediaSection(d *sdp.SessionDescription, codecType RTCRtpCodecType, midValue string, iceParams RTCIceParameters, peerDirection RTCRtpTransceiverDirection, candidates []RTCIceCandidate, dtlsRole sdp.ConnectionRole) bool { +func (pc *PeerConnection) addRTPMediaSection(d *sdp.SessionDescription, codecType RTPCodecType, midValue string, iceParams ICEParameters, peerDirection RTPTransceiverDirection, candidates []ICECandidate, dtlsRole sdp.ConnectionRole) bool { if codecs := pc.api.mediaEngine.getCodecsByKind(codecType); len(codecs) == 0 { return false } @@ -1454,7 +1454,7 @@ func (pc *RTCPeerConnection) addRTPMediaSection(d *sdp.SessionDescription, codec return true } -func (pc *RTCPeerConnection) addDataMediaSection(d *sdp.SessionDescription, midValue string, iceParams RTCIceParameters, candidates []RTCIceCandidate, dtlsRole sdp.ConnectionRole) { +func (pc *PeerConnection) addDataMediaSection(d *sdp.SessionDescription, midValue string, iceParams ICEParameters, candidates []ICECandidate, dtlsRole sdp.ConnectionRole) { media := (&sdp.MediaDescription{ MediaName: sdp.MediaName{ Media: "application", @@ -1472,7 +1472,7 @@ func (pc *RTCPeerConnection) addDataMediaSection(d *sdp.SessionDescription, midV }). WithValueAttribute(sdp.AttrKeyConnectionSetup, dtlsRole.String()). // TODO: Support other connection types WithValueAttribute(sdp.AttrKeyMID, midValue). - WithPropertyAttribute(RTCRtpTransceiverDirectionSendrecv.String()). + WithPropertyAttribute(RTPTransceiverDirectionSendrecv.String()). WithPropertyAttribute("sctpmap:5000 webrtc-datachannel 1024"). WithICECredentials(iceParams.UsernameFragment, iceParams.Password) @@ -1489,10 +1489,10 @@ func (pc *RTCPeerConnection) addDataMediaSection(d *sdp.SessionDescription, midV d.WithMedia(media) } -// NewRawRTPTrack Creates a new RTCTrack +// NewRawRTPTrack Creates a new Track // -// See NewRTCSampleTrack for documentation -func (pc *RTCPeerConnection) NewRawRTPTrack(payloadType uint8, ssrc uint32, id, label string) (*RTCTrack, error) { +// See NewSampleTrack for documentation +func (pc *PeerConnection) NewRawRTPTrack(payloadType uint8, ssrc uint32, id, label string) (*Track, error) { codec, err := pc.api.mediaEngine.getCodec(payloadType) if err != nil { return nil, err @@ -1503,10 +1503,10 @@ func (pc *RTCPeerConnection) NewRawRTPTrack(payloadType uint8, ssrc uint32, id, return NewRawRTPTrack(payloadType, ssrc, id, label, codec) } -// NewRTCSampleTrack Creates a new RTCTrack +// NewSampleTrack Creates a new Track // -// See NewRTCSampleTrack for documentation -func (pc *RTCPeerConnection) NewRTCSampleTrack(payloadType uint8, id, label string) (*RTCTrack, error) { +// See NewSampleTrack for documentation +func (pc *PeerConnection) NewSampleTrack(payloadType uint8, id, label string) (*Track, error) { codec, err := pc.api.mediaEngine.getCodec(payloadType) if err != nil { return nil, err @@ -1514,23 +1514,23 @@ func (pc *RTCPeerConnection) NewRTCSampleTrack(payloadType uint8, id, label stri return nil, errors.New("codec payloader not set") } - return NewRTCSampleTrack(payloadType, id, label, codec) + return NewSampleTrack(payloadType, id, label, codec) } -// NewRTCTrack is used to create a new RTCTrack +// NewTrack is used to create a new Track // -// Deprecated: Use NewRTCSampleTrack() instead -func (pc *RTCPeerConnection) NewRTCTrack(payloadType uint8, id, label string) (*RTCTrack, error) { - return pc.NewRTCSampleTrack(payloadType, id, label) +// Deprecated: Use NewSampleTrack() instead +func (pc *PeerConnection) NewTrack(payloadType uint8, id, label string) (*Track, error) { + return pc.NewSampleTrack(payloadType, id, label) } -func (pc *RTCPeerConnection) newRTCRtpTransceiver( - receiver *RTCRtpReceiver, - sender *RTCRtpSender, - direction RTCRtpTransceiverDirection, -) *RTCRtpTransceiver { +func (pc *PeerConnection) newRTPTransceiver( + receiver *RTPReceiver, + sender *RTPSender, + direction RTPTransceiverDirection, +) *RTPTransceiver { - t := &RTCRtpTransceiver{ + t := &RTPTransceiver{ Receiver: receiver, Sender: sender, Direction: direction, diff --git a/rtcpeerconnection_close_test.go b/rtcpeerconnection_close_test.go index f5f7fd7128e..190a24f15c0 100644 --- a/rtcpeerconnection_close_test.go +++ b/rtcpeerconnection_close_test.go @@ -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) }) diff --git a/rtcpeerconnection_media_test.go b/rtcpeerconnection_media_test.go index 4d1b5051fa9..296d4f9b333 100644 --- a/rtcpeerconnection_media_test.go +++ b/rtcpeerconnection_media_test.go @@ -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() diff --git a/rtcpeerconnection_test.go b/rtcpeerconnection_test.go index 6df44e8f5bc..e017667ed1e 100644 --- a/rtcpeerconnection_test.go +++ b/rtcpeerconnection_test.go @@ -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 { diff --git a/rtcpeerconnectionstate.go b/rtcpeerconnectionstate.go index 084920ed43e..be5d3c2bad7 100644 --- a/rtcpeerconnectionstate.go +++ b/rtcpeerconnectionstate.go @@ -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() } diff --git a/rtcpeerconnectionstate_test.go b/rtcpeerconnectionstate_test.go index 559f7a68f4f..61afbec2247 100644 --- a/rtcpeerconnectionstate_test.go +++ b/rtcpeerconnectionstate_test.go @@ -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 { diff --git a/rtcprioritytype.go b/rtcprioritytype.go index 5466c73ab4e..df34fc7a42b 100644 --- a/rtcprioritytype.go +++ b/rtcprioritytype.go @@ -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() } diff --git a/rtcprioritytype_test.go b/rtcprioritytype_test.go index d4fd9e44ab2..a199cc506a9 100644 --- a/rtcprioritytype_test.go +++ b/rtcprioritytype_test.go @@ -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 { diff --git a/rtcquicparameters.go b/rtcquicparameters.go index 4612c3d9c83..be562764bf2 100644 --- a/rtcquicparameters.go +++ b/rtcquicparameters.go @@ -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"` } diff --git a/rtcquicrole.go b/rtcquicrole.go index ecb693c5f5a..03cc22b0e7a 100644 --- a/rtcquicrole.go +++ b/rtcquicrole.go @@ -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 diff --git a/rtcquicrole_test.go b/rtcquicrole_test.go index 302cf41bb43..c9fa8b8076f 100644 --- a/rtcquicrole_test.go +++ b/rtcquicrole_test.go @@ -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 { diff --git a/rtcquictransport.go b/rtcquictransport.go index 5c19a0a554d..308a9fdaa35 100644 --- a/rtcquictransport.go +++ b/rtcquictransport.go @@ -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 { diff --git a/rtcquictransport_test.go b/rtcquictransport_test.go index 4da756d5e32..f9097b75e39 100644 --- a/rtcquictransport_test.go +++ b/rtcquictransport_test.go @@ -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 } diff --git a/rtcrtcpmuxpolicy.go b/rtcrtcpmuxpolicy.go index 9e08465c4db..d3fece1aaec 100644 --- a/rtcrtcpmuxpolicy.go +++ b/rtcrtcpmuxpolicy.go @@ -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() } diff --git a/rtcrtcpmuxpolicy_test.go b/rtcrtcpmuxpolicy_test.go index 4231daeeb84..68449cfde29 100644 --- a/rtcrtcpmuxpolicy_test.go +++ b/rtcrtcpmuxpolicy_test.go @@ -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 { diff --git a/rtcrtpcodingparameters.go b/rtcrtpcodingparameters.go index 05945bdf23b..a74c9f4e3ff 100644 --- a/rtcrtpcodingparameters.go +++ b/rtcrtpcodingparameters.go @@ -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"` } diff --git a/rtcrtpdecodingparameters.go b/rtcrtpdecodingparameters.go index 045ab8aeb7e..77aa1fc1c04 100644 --- a/rtcrtpdecodingparameters.go +++ b/rtcrtpdecodingparameters.go @@ -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 } diff --git a/rtcrtpencodingparameters.go b/rtcrtpencodingparameters.go index 1daf6c2d056..09481a5702b 100644 --- a/rtcrtpencodingparameters.go +++ b/rtcrtpencodingparameters.go @@ -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 } diff --git a/rtcrtpreceiveparameters.go b/rtcrtpreceiveparameters.go index 01b14a8c1e8..04bca10a6ba 100644 --- a/rtcrtpreceiveparameters.go +++ b/rtcrtpreceiveparameters.go @@ -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 } diff --git a/rtcrtpreceiver.go b/rtcrtpreceiver.go index 348e3e4f375..e1fb1c7fdf7 100644 --- a/rtcrtpreceiver.go +++ b/rtcrtpreceiver.go @@ -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 { diff --git a/rtcrtpsender.go b/rtcrtpsender.go index 3b5e6960ddc..e0d03c4106b 100644 --- a/rtcrtpsender.go +++ b/rtcrtpsender.go @@ -8,23 +8,23 @@ 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.rawInput = make(chan *rtp.Packet, 15) // Is the buffering needed? - r.Track.rtcpInput = make(chan rtcp.Packet, 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? r.Track.Samples = r.Track.sampleInput r.Track.RawRTP = r.Track.rawInput @@ -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) diff --git a/rtcrtpsendparameters.go b/rtcrtpsendparameters.go index 6dda19ba34a..f5079777acc 100644 --- a/rtcrtpsendparameters.go +++ b/rtcrtpsendparameters.go @@ -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 } diff --git a/rtcrtptranceiver.go b/rtcrtptranceiver.go index 1b3e25c9416..de524ddc153 100644 --- a/rtcrtptranceiver.go +++ b/rtcrtptranceiver.go @@ -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() } diff --git a/rtcrtptransceiverdirection.go b/rtcrtptransceiverdirection.go index 3dac3934a48..57f34b05fa7 100644 --- a/rtcrtptransceiverdirection.go +++ b/rtcrtptransceiverdirection.go @@ -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() } diff --git a/rtcrtptransceiverdirection_test.go b/rtcrtptransceiverdirection_test.go index aa8f2183346..bffdef9762d 100644 --- a/rtcrtptransceiverdirection_test.go +++ b/rtcrtptransceiverdirection_test.go @@ -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 { diff --git a/rtcsctpcapabilities.go b/rtcsctpcapabilities.go index c16b7415d61..34399d3b058 100644 --- a/rtcsctpcapabilities.go +++ b/rtcsctpcapabilities.go @@ -1,6 +1,6 @@ package webrtc -// RTCSctpCapabilities indicates the capabilities of the RTCSctpTransport. -type RTCSctpCapabilities struct { +// SCTPCapabilities indicates the capabilities of the SCTPTransport. +type SCTPCapabilities struct { MaxMessageSize uint32 `json:"maxMessageSize"` } diff --git a/rtcsctptransport.go b/rtcsctptransport.go index c89dd38f942..e57efa55ab9 100644 --- a/rtcsctptransport.go +++ b/rtcsctptransport.go @@ -12,40 +12,40 @@ import ( const sctpMaxChannels = uint16(65535) -// RTCSctpTransport provides details about the SCTP transport. -type RTCSctpTransport struct { +// SCTPTransport provides details about the SCTP transport. +type SCTPTransport struct { lock sync.RWMutex - dtlsTransport *RTCDtlsTransport + dtlsTransport *DTLSTransport // State represents the current state of the SCTP transport. - State RTCSctpTransportState + State SCTPTransportState port uint16 // MaxMessageSize represents the maximum size of data that can be passed to - // RTCDataChannel's send() method. + // DataChannel's send() method. MaxMessageSize float64 - // MaxChannels represents the maximum amount of RTCDataChannel's that can + // MaxChannels represents the maximum amount of DataChannel's that can // be used simultaneously. MaxChannels *uint16 // OnStateChange func() association *sctp.Association - onDataChannelHandler func(*RTCDataChannel) + onDataChannelHandler func(*DataChannel) api *API } -// NewRTCSctpTransport creates a new RTCSctpTransport. +// NewSCTPTransport creates a new SCTPTransport. // This constructor is part of the ORTC API. It is not // meant to be used together with the basic WebRTC API. -func (api *API) NewRTCSctpTransport(dtls *RTCDtlsTransport) *RTCSctpTransport { - res := &RTCSctpTransport{ +func (api *API) NewSCTPTransport(dtls *DTLSTransport) *SCTPTransport { + res := &SCTPTransport{ dtlsTransport: dtls, - State: RTCSctpTransportStateConnecting, + State: SCTPTransportStateConnecting, port: 5000, // TODO api: api, } @@ -56,25 +56,25 @@ func (api *API) NewRTCSctpTransport(dtls *RTCDtlsTransport) *RTCSctpTransport { return res } -// Transport returns the RTCDtlsTransport instance the RTCSctpTransport is sending over. -func (r *RTCSctpTransport) Transport() *RTCDtlsTransport { +// Transport returns the DTLSTransport instance the SCTPTransport is sending over. +func (r *SCTPTransport) Transport() *DTLSTransport { r.lock.RLock() defer r.lock.RUnlock() return r.dtlsTransport } -// GetCapabilities returns the RTCSctpCapabilities of the RTCSctpTransport. -func (r *RTCSctpTransport) GetCapabilities() RTCSctpCapabilities { - return RTCSctpCapabilities{ +// GetCapabilities returns the SCTPCapabilities of the SCTPTransport. +func (r *SCTPTransport) GetCapabilities() SCTPCapabilities { + return SCTPCapabilities{ MaxMessageSize: 0, } } -// Start the RTCSctpTransport. Since both local and remote parties must mutually -// create an RTCSctpTransport, SCTP SO (Simultaneous Open) is used to establish +// Start the SCTPTransport. Since both local and remote parties must mutually +// create an SCTPTransport, SCTP SO (Simultaneous Open) is used to establish // a connection over SCTP. -func (r *RTCSctpTransport) Start(remoteCaps RTCSctpCapabilities) error { +func (r *SCTPTransport) Start(remoteCaps SCTPCapabilities) error { r.lock.Lock() defer r.lock.Unlock() @@ -96,8 +96,8 @@ func (r *RTCSctpTransport) Start(remoteCaps RTCSctpCapabilities) error { return nil } -// Stop stops the RTCSctpTransport -func (r *RTCSctpTransport) Stop() error { +// Stop stops the SCTPTransport +func (r *SCTPTransport) Stop() error { r.lock.Lock() defer r.lock.Unlock() if r.association == nil { @@ -109,12 +109,12 @@ func (r *RTCSctpTransport) Stop() error { } r.association = nil - r.State = RTCSctpTransportStateClosed + r.State = SCTPTransportStateClosed return nil } -func (r *RTCSctpTransport) ensureDTLS() error { +func (r *SCTPTransport) ensureDTLS() error { if r.dtlsTransport == nil || r.dtlsTransport.conn == nil { return errors.New("DTLS not establisched") @@ -123,7 +123,7 @@ func (r *RTCSctpTransport) ensureDTLS() error { return nil } -func (r *RTCSctpTransport) acceptDataChannels() { +func (r *SCTPTransport) acceptDataChannels() { r.lock.RLock() a := r.association r.lock.RUnlock() @@ -136,10 +136,10 @@ func (r *RTCSctpTransport) acceptDataChannels() { } sid := dc.StreamIdentifier() - rtcDC := &RTCDataChannel{ + rtcDC := &DataChannel{ ID: &sid, Label: dc.Config.Label, - ReadyState: RTCDataChannelStateOpen, + ReadyState: DataChannelStateOpen, api: r.api, } @@ -150,13 +150,13 @@ func (r *RTCSctpTransport) acceptDataChannels() { // OnDataChannel sets an event handler which is invoked when a data // channel message arrives from a remote peer. -func (r *RTCSctpTransport) OnDataChannel(f func(*RTCDataChannel)) { +func (r *SCTPTransport) OnDataChannel(f func(*DataChannel)) { r.lock.Lock() defer r.lock.Unlock() r.onDataChannelHandler = f } -func (r *RTCSctpTransport) onDataChannel(dc *RTCDataChannel) (done chan struct{}) { +func (r *SCTPTransport) onDataChannel(dc *DataChannel) (done chan struct{}) { r.lock.Lock() hdlr := r.onDataChannelHandler r.lock.Unlock() @@ -177,14 +177,14 @@ func (r *RTCSctpTransport) onDataChannel(dc *RTCDataChannel) (done chan struct{} return } -func (r *RTCSctpTransport) updateMessageSize() { +func (r *SCTPTransport) updateMessageSize() { var remoteMaxMessageSize float64 = 65536 // TODO: get from SDP var canSendSize float64 = 65536 // TODO: Get from SCTP implementation r.MaxMessageSize = r.calcMessageSize(remoteMaxMessageSize, canSendSize) } -func (r *RTCSctpTransport) calcMessageSize(remoteMaxMessageSize, canSendSize float64) float64 { +func (r *SCTPTransport) calcMessageSize(remoteMaxMessageSize, canSendSize float64) float64 { switch { case remoteMaxMessageSize == 0 && canSendSize == 0: @@ -204,7 +204,7 @@ func (r *RTCSctpTransport) calcMessageSize(remoteMaxMessageSize, canSendSize flo } } -func (r *RTCSctpTransport) updateMaxChannels() { +func (r *SCTPTransport) updateMaxChannels() { val := sctpMaxChannels r.MaxChannels = &val } diff --git a/rtcsctptransportstate.go b/rtcsctptransportstate.go index 903bc927722..8dc79416240 100644 --- a/rtcsctptransportstate.go +++ b/rtcsctptransportstate.go @@ -1,53 +1,53 @@ package webrtc -// RTCSctpTransportState indicates the state of the SCTP transport. -type RTCSctpTransportState int +// SCTPTransportState indicates the state of the SCTP transport. +type SCTPTransportState int const ( - // RTCSctpTransportStateConnecting indicates the RTCSctpTransport is in the + // SCTPTransportStateConnecting indicates the SCTPTransport is in the // process of negotiating an association. This is the initial state of the - // SctpTransportState when an RTCSctpTransport is created. - RTCSctpTransportStateConnecting RTCSctpTransportState = iota + 1 + // SCTPTransportState when an SCTPTransport is created. + SCTPTransportStateConnecting SCTPTransportState = iota + 1 - // RTCSctpTransportStateConnected indicates the negotiation of an + // SCTPTransportStateConnected indicates the negotiation of an // association is completed. - RTCSctpTransportStateConnected + SCTPTransportStateConnected - // RTCSctpTransportStateClosed indicates a SHUTDOWN or ABORT chunk is + // SCTPTransportStateClosed indicates a SHUTDOWN or ABORT chunk is // received or when the SCTP association has been closed intentionally, // such as by closing the peer connection or applying a remote description // that rejects data or changes the SCTP port. - RTCSctpTransportStateClosed + SCTPTransportStateClosed ) // This is done this way because of a linter. const ( - rtcSctpTransportStateConnectingStr = "connecting" - rtcSctpTransportStateConnectedStr = "connected" - rtcSctpTransportStateClosedStr = "closed" + sctpTransportStateConnectingStr = "connecting" + sctpTransportStateConnectedStr = "connected" + sctpTransportStateClosedStr = "closed" ) -func newRTCSctpTransportState(raw string) RTCSctpTransportState { +func newSCTPTransportState(raw string) SCTPTransportState { switch raw { - case rtcSctpTransportStateConnectingStr: - return RTCSctpTransportStateConnecting - case rtcSctpTransportStateConnectedStr: - return RTCSctpTransportStateConnected - case rtcSctpTransportStateClosedStr: - return RTCSctpTransportStateClosed + case sctpTransportStateConnectingStr: + return SCTPTransportStateConnecting + case sctpTransportStateConnectedStr: + return SCTPTransportStateConnected + case sctpTransportStateClosedStr: + return SCTPTransportStateClosed default: - return RTCSctpTransportState(Unknown) + return SCTPTransportState(Unknown) } } -func (s RTCSctpTransportState) String() string { +func (s SCTPTransportState) String() string { switch s { - case RTCSctpTransportStateConnecting: - return rtcSctpTransportStateConnectingStr - case RTCSctpTransportStateConnected: - return rtcSctpTransportStateConnectedStr - case RTCSctpTransportStateClosed: - return rtcSctpTransportStateClosedStr + case SCTPTransportStateConnecting: + return sctpTransportStateConnectingStr + case SCTPTransportStateConnected: + return sctpTransportStateConnectedStr + case SCTPTransportStateClosed: + return sctpTransportStateClosedStr default: return ErrUnknownType.Error() } diff --git a/rtcsctptransportstate_test.go b/rtcsctptransportstate_test.go index 5a0f575f48a..36550a03617 100644 --- a/rtcsctptransportstate_test.go +++ b/rtcsctptransportstate_test.go @@ -6,35 +6,35 @@ import ( "github.com/stretchr/testify/assert" ) -func TestNewRTCSctpTransportState(t *testing.T) { +func TestNewSCTPTransportState(t *testing.T) { testCases := []struct { transportStateString string - expectedTransportState RTCSctpTransportState + expectedTransportState SCTPTransportState }{ - {unknownStr, RTCSctpTransportState(Unknown)}, - {"connecting", RTCSctpTransportStateConnecting}, - {"connected", RTCSctpTransportStateConnected}, - {"closed", RTCSctpTransportStateClosed}, + {unknownStr, SCTPTransportState(Unknown)}, + {"connecting", SCTPTransportStateConnecting}, + {"connected", SCTPTransportStateConnected}, + {"closed", SCTPTransportStateClosed}, } for i, testCase := range testCases { assert.Equal(t, testCase.expectedTransportState, - newRTCSctpTransportState(testCase.transportStateString), + newSCTPTransportState(testCase.transportStateString), "testCase: %d %v", i, testCase, ) } } -func TestRTCSctpTransportState_String(t *testing.T) { +func TestSCTPTransportState_String(t *testing.T) { testCases := []struct { - transportState RTCSctpTransportState + transportState SCTPTransportState expectedString string }{ - {RTCSctpTransportState(Unknown), unknownStr}, - {RTCSctpTransportStateConnecting, "connecting"}, - {RTCSctpTransportStateConnected, "connected"}, - {RTCSctpTransportStateClosed, "closed"}, + {SCTPTransportState(Unknown), unknownStr}, + {SCTPTransportStateConnecting, "connecting"}, + {SCTPTransportStateConnected, "connected"}, + {SCTPTransportStateClosed, "closed"}, } for i, testCase := range testCases { diff --git a/rtcsdptype.go b/rtcsdptype.go index 6542279561c..432a72615c8 100644 --- a/rtcsdptype.go +++ b/rtcsdptype.go @@ -5,79 +5,79 @@ import ( "strings" ) -// RTCSdpType describes the type of an RTCSessionDescription. -type RTCSdpType int +// SDPType describes the type of an SessionDescription. +type SDPType int const ( - // RTCSdpTypeOffer indicates that a description MUST be treated as an SDP + // SDPTypeOffer indicates that a description MUST be treated as an SDP // offer. - RTCSdpTypeOffer RTCSdpType = iota + 1 + SDPTypeOffer SDPType = iota + 1 - // RTCSdpTypePranswer indicates that a description MUST be treated as an + // SDPTypePranswer indicates that a description MUST be treated as an // SDP answer, but not a final answer. A description used as an SDP // pranswer may be applied as a response to an SDP offer, or an update to // a previously sent SDP pranswer. - RTCSdpTypePranswer + SDPTypePranswer - // RTCSdpTypeAnswer indicates that a description MUST be treated as an SDP + // SDPTypeAnswer indicates that a description MUST be treated as an SDP // final answer, and the offer-answer exchange MUST be considered complete. // A description used as an SDP answer may be applied as a response to an // SDP offer or as an update to a previously sent SDP pranswer. - RTCSdpTypeAnswer + SDPTypeAnswer - // RTCSdpTypeRollback indicates that a description MUST be treated as + // SDPTypeRollback indicates that a description MUST be treated as // canceling the current SDP negotiation and moving the SDP offer and // answer back to what it was in the previous stable state. Note the // local or remote SDP descriptions in the previous stable state could be // null if there has not yet been a successful offer-answer negotiation. - RTCSdpTypeRollback + SDPTypeRollback ) // This is done this way because of a linter. const ( - rtcSdpTypeOfferStr = "offer" - rtcSdpTypePranswerStr = "pranswer" - rtcSdpTypeAnswerStr = "answer" - rtcSdpTypeRollbackStr = "rollback" + sdpTypeOfferStr = "offer" + sdpTypePranswerStr = "pranswer" + sdpTypeAnswerStr = "answer" + sdpTypeRollbackStr = "rollback" ) -func newRTCSdpType(raw string) RTCSdpType { +func newSDPType(raw string) SDPType { switch raw { - case rtcSdpTypeOfferStr: - return RTCSdpTypeOffer - case rtcSdpTypePranswerStr: - return RTCSdpTypePranswer - case rtcSdpTypeAnswerStr: - return RTCSdpTypeAnswer - case rtcSdpTypeRollbackStr: - return RTCSdpTypeRollback + case sdpTypeOfferStr: + return SDPTypeOffer + case sdpTypePranswerStr: + return SDPTypePranswer + case sdpTypeAnswerStr: + return SDPTypeAnswer + case sdpTypeRollbackStr: + return SDPTypeRollback default: - return RTCSdpType(Unknown) + return SDPType(Unknown) } } -func (t RTCSdpType) String() string { +func (t SDPType) String() string { switch t { - case RTCSdpTypeOffer: - return rtcSdpTypeOfferStr - case RTCSdpTypePranswer: - return rtcSdpTypePranswerStr - case RTCSdpTypeAnswer: - return rtcSdpTypeAnswerStr - case RTCSdpTypeRollback: - return rtcSdpTypeRollbackStr + case SDPTypeOffer: + return sdpTypeOfferStr + case SDPTypePranswer: + return sdpTypePranswerStr + case SDPTypeAnswer: + return sdpTypeAnswerStr + case SDPTypeRollback: + return sdpTypeRollbackStr default: return ErrUnknownType.Error() } } -// MarshalJSON enables JSON marshaling of a RTCSdpType -func (t RTCSdpType) MarshalJSON() ([]byte, error) { +// MarshalJSON enables JSON marshaling of a SDPType +func (t SDPType) MarshalJSON() ([]byte, error) { return json.Marshal(t.String()) } -// UnmarshalJSON enables JSON unmarshaling of a RTCSdpType -func (t *RTCSdpType) UnmarshalJSON(b []byte) error { +// UnmarshalJSON enables JSON unmarshaling of a SDPType +func (t *SDPType) UnmarshalJSON(b []byte) error { var s string if err := json.Unmarshal(b, &s); err != nil { return err @@ -86,13 +86,13 @@ func (t *RTCSdpType) UnmarshalJSON(b []byte) error { default: return ErrUnknownType case "offer": - *t = RTCSdpTypeOffer + *t = SDPTypeOffer case "pranswer": - *t = RTCSdpTypePranswer + *t = SDPTypePranswer case "answer": - *t = RTCSdpTypeAnswer + *t = SDPTypeAnswer case "rollback": - *t = RTCSdpTypeRollback + *t = SDPTypeRollback } return nil diff --git a/rtcsdptype_test.go b/rtcsdptype_test.go index 05b5f4be824..9ecd4ecaa8a 100644 --- a/rtcsdptype_test.go +++ b/rtcsdptype_test.go @@ -6,37 +6,37 @@ import ( "github.com/stretchr/testify/assert" ) -func TestNewRTCSdpType(t *testing.T) { +func TestNewSDPType(t *testing.T) { testCases := []struct { sdpTypeString string - expectedSdpType RTCSdpType + expectedSdpType SDPType }{ - {unknownStr, RTCSdpType(Unknown)}, - {"offer", RTCSdpTypeOffer}, - {"pranswer", RTCSdpTypePranswer}, - {"answer", RTCSdpTypeAnswer}, - {"rollback", RTCSdpTypeRollback}, + {unknownStr, SDPType(Unknown)}, + {"offer", SDPTypeOffer}, + {"pranswer", SDPTypePranswer}, + {"answer", SDPTypeAnswer}, + {"rollback", SDPTypeRollback}, } for i, testCase := range testCases { assert.Equal(t, testCase.expectedSdpType, - newRTCSdpType(testCase.sdpTypeString), + newSDPType(testCase.sdpTypeString), "testCase: %d %v", i, testCase, ) } } -func TestRTCSdpType_String(t *testing.T) { +func TestSDPType_String(t *testing.T) { testCases := []struct { - sdpType RTCSdpType + sdpType SDPType expectedString string }{ - {RTCSdpType(Unknown), unknownStr}, - {RTCSdpTypeOffer, "offer"}, - {RTCSdpTypePranswer, "pranswer"}, - {RTCSdpTypeAnswer, "answer"}, - {RTCSdpTypeRollback, "rollback"}, + {SDPType(Unknown), unknownStr}, + {SDPTypeOffer, "offer"}, + {SDPTypePranswer, "pranswer"}, + {SDPTypeAnswer, "answer"}, + {SDPTypeRollback, "rollback"}, } for i, testCase := range testCases { diff --git a/rtcsessiondescription.go b/rtcsessiondescription.go index 170ac31bc47..48d7b2776e2 100644 --- a/rtcsessiondescription.go +++ b/rtcsessiondescription.go @@ -4,10 +4,10 @@ import ( "github.com/pions/sdp" ) -// RTCSessionDescription is used to expose local and remote session descriptions. -type RTCSessionDescription struct { - Type RTCSdpType `json:"type"` - Sdp string `json:"sdp"` +// SessionDescription is used to expose local and remote session descriptions. +type SessionDescription struct { + Type SDPType `json:"type"` + Sdp string `json:"sdp"` // This will never be initialized by callers, internal use only parsed *sdp.SessionDescription diff --git a/rtcsessiondescription_test.go b/rtcsessiondescription_test.go index 3eb49f7b9cb..01302921e3f 100644 --- a/rtcsessiondescription_test.go +++ b/rtcsessiondescription_test.go @@ -7,17 +7,17 @@ import ( "github.com/stretchr/testify/assert" ) -func TestRTCSessionDescription_JSON(t *testing.T) { +func TestSessionDescription_JSON(t *testing.T) { testCases := []struct { - desc RTCSessionDescription + desc SessionDescription expectedString string unmarshalErr error }{ - {RTCSessionDescription{Type: RTCSdpTypeOffer, Sdp: "sdp"}, `{"type":"offer","sdp":"sdp"}`, nil}, - {RTCSessionDescription{Type: RTCSdpTypePranswer, Sdp: "sdp"}, `{"type":"pranswer","sdp":"sdp"}`, nil}, - {RTCSessionDescription{Type: RTCSdpTypeAnswer, Sdp: "sdp"}, `{"type":"answer","sdp":"sdp"}`, nil}, - {RTCSessionDescription{Type: RTCSdpTypeRollback, Sdp: "sdp"}, `{"type":"rollback","sdp":"sdp"}`, nil}, - {RTCSessionDescription{Type: RTCSdpType(Unknown), Sdp: "sdp"}, `{"type":"unknown","sdp":"sdp"}`, ErrUnknownType}, + {SessionDescription{Type: SDPTypeOffer, Sdp: "sdp"}, `{"type":"offer","sdp":"sdp"}`, nil}, + {SessionDescription{Type: SDPTypePranswer, Sdp: "sdp"}, `{"type":"pranswer","sdp":"sdp"}`, nil}, + {SessionDescription{Type: SDPTypeAnswer, Sdp: "sdp"}, `{"type":"answer","sdp":"sdp"}`, nil}, + {SessionDescription{Type: SDPTypeRollback, Sdp: "sdp"}, `{"type":"rollback","sdp":"sdp"}`, nil}, + {SessionDescription{Type: SDPType(Unknown), Sdp: "sdp"}, `{"type":"unknown","sdp":"sdp"}`, ErrUnknownType}, } for i, testCase := range testCases { @@ -33,7 +33,7 @@ func TestRTCSessionDescription_JSON(t *testing.T) { "testCase: %d %v", i, testCase, ) - var desc RTCSessionDescription + var desc SessionDescription err = json.Unmarshal(descData, &desc) if testCase.unmarshalErr != nil { diff --git a/rtcsignalingstate.go b/rtcsignalingstate.go index 0ca1346c7e6..5575f3f287e 100644 --- a/rtcsignalingstate.go +++ b/rtcsignalingstate.go @@ -7,106 +7,106 @@ import ( "github.com/pkg/errors" ) -type rtcStateChangeOp int +type stateChangeOp int const ( - rtcStateChangeOpSetLocal rtcStateChangeOp = iota + 1 - rtcStateChangeOpSetRemote + stateChangeOpSetLocal stateChangeOp = iota + 1 + stateChangeOpSetRemote ) -func (op rtcStateChangeOp) String() string { +func (op stateChangeOp) String() string { switch op { - case rtcStateChangeOpSetLocal: + case stateChangeOpSetLocal: return "SetLocal" - case rtcStateChangeOpSetRemote: + case stateChangeOpSetRemote: return "SetRemote" default: return "Unknown State Change Operation" } } -// RTCSignalingState indicates the signaling state of the offer/answer process. -type RTCSignalingState int +// SignalingState indicates the signaling state of the offer/answer process. +type SignalingState int const ( - // RTCSignalingStateStable indicates there is no offer/answer exchange in + // SignalingStateStable indicates there is no offer/answer exchange in // progress. This is also the initial state, in which case the local and // remote descriptions are nil. - RTCSignalingStateStable RTCSignalingState = iota + 1 + SignalingStateStable SignalingState = iota + 1 - // RTCSignalingStateHaveLocalOffer indicates that a local description, of + // SignalingStateHaveLocalOffer indicates that a local description, of // type "offer", has been successfully applied. - RTCSignalingStateHaveLocalOffer + SignalingStateHaveLocalOffer - // RTCSignalingStateHaveRemoteOffer indicates that a remote description, of + // SignalingStateHaveRemoteOffer indicates that a remote description, of // type "offer", has been successfully applied. - RTCSignalingStateHaveRemoteOffer + SignalingStateHaveRemoteOffer - // RTCSignalingStateHaveLocalPranswer indicates that a remote description + // SignalingStateHaveLocalPranswer indicates that a remote description // of type "offer" has been successfully applied and a local description // of type "pranswer" has been successfully applied. - RTCSignalingStateHaveLocalPranswer + SignalingStateHaveLocalPranswer - // RTCSignalingStateHaveRemotePranswer indicates that a local description + // SignalingStateHaveRemotePranswer indicates that a local description // of type "offer" has been successfully applied and a remote description // of type "pranswer" has been successfully applied. - RTCSignalingStateHaveRemotePranswer + SignalingStateHaveRemotePranswer - // RTCSignalingStateClosed indicates The RTCPeerConnection has been closed. - RTCSignalingStateClosed + // SignalingStateClosed indicates The PeerConnection has been closed. + SignalingStateClosed ) // This is done this way because of a linter. const ( - rtcSignalingStateStableStr = "stable" - rtcSignalingStateHaveLocalOfferStr = "have-local-offer" - rtcSignalingStateHaveRemoteOfferStr = "have-remote-offer" - rtcSignalingStateHaveLocalPranswerStr = "have-local-pranswer" - rtcSignalingStateHaveRemotePranswerStr = "have-remote-pranswer" - rtcSignalingStateClosedStr = "closed" + signalingStateStableStr = "stable" + signalingStateHaveLocalOfferStr = "have-local-offer" + signalingStateHaveRemoteOfferStr = "have-remote-offer" + signalingStateHaveLocalPranswerStr = "have-local-pranswer" + signalingStateHaveRemotePranswerStr = "have-remote-pranswer" + signalingStateClosedStr = "closed" ) -func newRTCSignalingState(raw string) RTCSignalingState { +func newSignalingState(raw string) SignalingState { switch raw { - case rtcSignalingStateStableStr: - return RTCSignalingStateStable - case rtcSignalingStateHaveLocalOfferStr: - return RTCSignalingStateHaveLocalOffer - case rtcSignalingStateHaveRemoteOfferStr: - return RTCSignalingStateHaveRemoteOffer - case rtcSignalingStateHaveLocalPranswerStr: - return RTCSignalingStateHaveLocalPranswer - case rtcSignalingStateHaveRemotePranswerStr: - return RTCSignalingStateHaveRemotePranswer - case rtcSignalingStateClosedStr: - return RTCSignalingStateClosed + case signalingStateStableStr: + return SignalingStateStable + case signalingStateHaveLocalOfferStr: + return SignalingStateHaveLocalOffer + case signalingStateHaveRemoteOfferStr: + return SignalingStateHaveRemoteOffer + case signalingStateHaveLocalPranswerStr: + return SignalingStateHaveLocalPranswer + case signalingStateHaveRemotePranswerStr: + return SignalingStateHaveRemotePranswer + case signalingStateClosedStr: + return SignalingStateClosed default: - return RTCSignalingState(Unknown) + return SignalingState(Unknown) } } -func (t RTCSignalingState) String() string { +func (t SignalingState) String() string { switch t { - case RTCSignalingStateStable: - return rtcSignalingStateStableStr - case RTCSignalingStateHaveLocalOffer: - return rtcSignalingStateHaveLocalOfferStr - case RTCSignalingStateHaveRemoteOffer: - return rtcSignalingStateHaveRemoteOfferStr - case RTCSignalingStateHaveLocalPranswer: - return rtcSignalingStateHaveLocalPranswerStr - case RTCSignalingStateHaveRemotePranswer: - return rtcSignalingStateHaveRemotePranswerStr - case RTCSignalingStateClosed: - return rtcSignalingStateClosedStr + case SignalingStateStable: + return signalingStateStableStr + case SignalingStateHaveLocalOffer: + return signalingStateHaveLocalOfferStr + case SignalingStateHaveRemoteOffer: + return signalingStateHaveRemoteOfferStr + case SignalingStateHaveLocalPranswer: + return signalingStateHaveLocalPranswerStr + case SignalingStateHaveRemotePranswer: + return signalingStateHaveRemotePranswerStr + case SignalingStateClosed: + return signalingStateClosedStr default: return ErrUnknownType.Error() } } -func checkNextSignalingState(cur, next RTCSignalingState, op rtcStateChangeOp, sdpType RTCSdpType) (RTCSignalingState, error) { +func checkNextSignalingState(cur, next SignalingState, op stateChangeOp, sdpType SDPType) (SignalingState, error) { // Special case for rollbacks - if sdpType == RTCSdpTypeRollback && cur == RTCSignalingStateStable { + if sdpType == SDPTypeRollback && cur == SignalingStateStable { return cur, &rtcerr.InvalidModificationError{ Err: errors.New("Can't rollback from stable state"), } @@ -114,60 +114,60 @@ func checkNextSignalingState(cur, next RTCSignalingState, op rtcStateChangeOp, s // 4.3.1 valid state transitions switch cur { - case RTCSignalingStateStable: + case SignalingStateStable: switch op { - case rtcStateChangeOpSetLocal: + case stateChangeOpSetLocal: // stable->SetLocal(offer)->have-local-offer - if sdpType == RTCSdpTypeOffer && next == RTCSignalingStateHaveLocalOffer { + if sdpType == SDPTypeOffer && next == SignalingStateHaveLocalOffer { return next, nil } - case rtcStateChangeOpSetRemote: + case stateChangeOpSetRemote: // stable->SetRemote(offer)->have-remote-offer - if sdpType == RTCSdpTypeOffer && next == RTCSignalingStateHaveRemoteOffer { + if sdpType == SDPTypeOffer && next == SignalingStateHaveRemoteOffer { return next, nil } } - case RTCSignalingStateHaveLocalOffer: - if op == rtcStateChangeOpSetRemote { + case SignalingStateHaveLocalOffer: + if op == stateChangeOpSetRemote { switch sdpType { // have-local-offer->SetRemote(answer)->stable - case RTCSdpTypeAnswer: - if next == RTCSignalingStateStable { + case SDPTypeAnswer: + if next == SignalingStateStable { return next, nil } // have-local-offer->SetRemote(pranswer)->have-remote-pranswer - case RTCSdpTypePranswer: - if next == RTCSignalingStateHaveRemotePranswer { + case SDPTypePranswer: + if next == SignalingStateHaveRemotePranswer { return next, nil } } } - case RTCSignalingStateHaveRemotePranswer: - if op == rtcStateChangeOpSetRemote && sdpType == RTCSdpTypeAnswer { + case SignalingStateHaveRemotePranswer: + if op == stateChangeOpSetRemote && sdpType == SDPTypeAnswer { // have-remote-pranswer->SetRemote(answer)->stable - if next == RTCSignalingStateStable { + if next == SignalingStateStable { return next, nil } } - case RTCSignalingStateHaveRemoteOffer: - if op == rtcStateChangeOpSetLocal { + case SignalingStateHaveRemoteOffer: + if op == stateChangeOpSetLocal { switch sdpType { // have-remote-offer->SetLocal(answer)->stable - case RTCSdpTypeAnswer: - if next == RTCSignalingStateStable { + case SDPTypeAnswer: + if next == SignalingStateStable { return next, nil } // have-remote-offer->SetLocal(pranswer)->have-local-pranswer - case RTCSdpTypePranswer: - if next == RTCSignalingStateHaveLocalPranswer { + case SDPTypePranswer: + if next == SignalingStateHaveLocalPranswer { return next, nil } } } - case RTCSignalingStateHaveLocalPranswer: - if op == rtcStateChangeOpSetLocal && sdpType == RTCSdpTypeAnswer { + case SignalingStateHaveLocalPranswer: + if op == stateChangeOpSetLocal && sdpType == SDPTypeAnswer { // have-local-pranswer->SetLocal(answer)->stable - if next == RTCSignalingStateStable { + if next == SignalingStateStable { return next, nil } } diff --git a/rtcsignalingstate_test.go b/rtcsignalingstate_test.go index cd1a890867c..391fa4c9a05 100644 --- a/rtcsignalingstate_test.go +++ b/rtcsignalingstate_test.go @@ -8,41 +8,41 @@ import ( "github.com/stretchr/testify/assert" ) -func TestNewRTCSignalingState(t *testing.T) { +func TestNewSignalingState(t *testing.T) { testCases := []struct { stateString string - expectedState RTCSignalingState + expectedState SignalingState }{ - {unknownStr, RTCSignalingState(Unknown)}, - {"stable", RTCSignalingStateStable}, - {"have-local-offer", RTCSignalingStateHaveLocalOffer}, - {"have-remote-offer", RTCSignalingStateHaveRemoteOffer}, - {"have-local-pranswer", RTCSignalingStateHaveLocalPranswer}, - {"have-remote-pranswer", RTCSignalingStateHaveRemotePranswer}, - {"closed", RTCSignalingStateClosed}, + {unknownStr, SignalingState(Unknown)}, + {"stable", SignalingStateStable}, + {"have-local-offer", SignalingStateHaveLocalOffer}, + {"have-remote-offer", SignalingStateHaveRemoteOffer}, + {"have-local-pranswer", SignalingStateHaveLocalPranswer}, + {"have-remote-pranswer", SignalingStateHaveRemotePranswer}, + {"closed", SignalingStateClosed}, } for i, testCase := range testCases { assert.Equal(t, testCase.expectedState, - newRTCSignalingState(testCase.stateString), + newSignalingState(testCase.stateString), "testCase: %d %v", i, testCase, ) } } -func TestRTCSignalingState_String(t *testing.T) { +func TestSignalingState_String(t *testing.T) { testCases := []struct { - state RTCSignalingState + state SignalingState expectedString string }{ - {RTCSignalingState(Unknown), unknownStr}, - {RTCSignalingStateStable, "stable"}, - {RTCSignalingStateHaveLocalOffer, "have-local-offer"}, - {RTCSignalingStateHaveRemoteOffer, "have-remote-offer"}, - {RTCSignalingStateHaveLocalPranswer, "have-local-pranswer"}, - {RTCSignalingStateHaveRemotePranswer, "have-remote-pranswer"}, - {RTCSignalingStateClosed, "closed"}, + {SignalingState(Unknown), unknownStr}, + {SignalingStateStable, "stable"}, + {SignalingStateHaveLocalOffer, "have-local-offer"}, + {SignalingStateHaveRemoteOffer, "have-remote-offer"}, + {SignalingStateHaveLocalPranswer, "have-local-pranswer"}, + {SignalingStateHaveRemotePranswer, "have-remote-pranswer"}, + {SignalingStateClosed, "closed"}, } for i, testCase := range testCases { @@ -54,93 +54,93 @@ func TestRTCSignalingState_String(t *testing.T) { } } -func TestRTCSignalingState_Transitions(t *testing.T) { +func TestSignalingState_Transitions(t *testing.T) { testCases := []struct { desc string - current RTCSignalingState - next RTCSignalingState - op rtcStateChangeOp - sdpType RTCSdpType + current SignalingState + next SignalingState + op stateChangeOp + sdpType SDPType expectedErr error }{ { "stable->SetLocal(offer)->have-local-offer", - RTCSignalingStateStable, - RTCSignalingStateHaveLocalOffer, - rtcStateChangeOpSetLocal, - RTCSdpTypeOffer, + SignalingStateStable, + SignalingStateHaveLocalOffer, + stateChangeOpSetLocal, + SDPTypeOffer, nil, }, { "stable->SetRemote(offer)->have-remote-offer", - RTCSignalingStateStable, - RTCSignalingStateHaveRemoteOffer, - rtcStateChangeOpSetRemote, - RTCSdpTypeOffer, + SignalingStateStable, + SignalingStateHaveRemoteOffer, + stateChangeOpSetRemote, + SDPTypeOffer, nil, }, { "have-local-offer->SetRemote(answer)->stable", - RTCSignalingStateHaveLocalOffer, - RTCSignalingStateStable, - rtcStateChangeOpSetRemote, - RTCSdpTypeAnswer, + SignalingStateHaveLocalOffer, + SignalingStateStable, + stateChangeOpSetRemote, + SDPTypeAnswer, nil, }, { "have-local-offer->SetRemote(pranswer)->have-remote-pranswer", - RTCSignalingStateHaveLocalOffer, - RTCSignalingStateHaveRemotePranswer, - rtcStateChangeOpSetRemote, - RTCSdpTypePranswer, + SignalingStateHaveLocalOffer, + SignalingStateHaveRemotePranswer, + stateChangeOpSetRemote, + SDPTypePranswer, nil, }, { "have-remote-pranswer->SetRemote(answer)->stable", - RTCSignalingStateHaveRemotePranswer, - RTCSignalingStateStable, - rtcStateChangeOpSetRemote, - RTCSdpTypeAnswer, + SignalingStateHaveRemotePranswer, + SignalingStateStable, + stateChangeOpSetRemote, + SDPTypeAnswer, nil, }, { "have-remote-offer->SetLocal(answer)->stable", - RTCSignalingStateHaveRemoteOffer, - RTCSignalingStateStable, - rtcStateChangeOpSetLocal, - RTCSdpTypeAnswer, + SignalingStateHaveRemoteOffer, + SignalingStateStable, + stateChangeOpSetLocal, + SDPTypeAnswer, nil, }, { "have-remote-offer->SetLocal(pranswer)->have-local-pranswer", - RTCSignalingStateHaveRemoteOffer, - RTCSignalingStateHaveLocalPranswer, - rtcStateChangeOpSetLocal, - RTCSdpTypePranswer, + SignalingStateHaveRemoteOffer, + SignalingStateHaveLocalPranswer, + stateChangeOpSetLocal, + SDPTypePranswer, nil, }, { "have-local-pranswer->SetLocal(answer)->stable", - RTCSignalingStateHaveLocalPranswer, - RTCSignalingStateStable, - rtcStateChangeOpSetLocal, - RTCSdpTypeAnswer, + SignalingStateHaveLocalPranswer, + SignalingStateStable, + stateChangeOpSetLocal, + SDPTypeAnswer, nil, }, { "(invalid) stable->SetRemote(pranswer)->have-remote-pranswer", - RTCSignalingStateStable, - RTCSignalingStateHaveRemotePranswer, - rtcStateChangeOpSetRemote, - RTCSdpTypePranswer, + SignalingStateStable, + SignalingStateHaveRemotePranswer, + stateChangeOpSetRemote, + SDPTypePranswer, &rtcerr.InvalidModificationError{}, }, { "(invalid) stable->SetRemote(rollback)->have-local-offer", - RTCSignalingStateStable, - RTCSignalingStateHaveLocalOffer, - rtcStateChangeOpSetRemote, - RTCSdpTypeRollback, + SignalingStateStable, + SignalingStateHaveLocalOffer, + stateChangeOpSetRemote, + SDPTypeRollback, &rtcerr.InvalidModificationError{}, }, } diff --git a/rtctrack.go b/rtctrack.go index c6c9c1e666e..8c66dc74d5e 100644 --- a/rtctrack.go +++ b/rtctrack.go @@ -10,37 +10,37 @@ import ( "github.com/pkg/errors" ) -// RTCTrack represents a track that is communicated -type RTCTrack struct { +// Track represents a track that is communicated +type Track struct { isRawRTP bool - sampleInput chan media.RTCSample + sampleInput chan media.Sample rawInput chan *rtp.Packet rtcpInput chan rtcp.Packet ID string PayloadType uint8 - Kind RTCRtpCodecType + Kind RTPCodecType Label string Ssrc uint32 - Codec *RTCRtpCodec + Codec *RTPCodec Packets <-chan *rtp.Packet RTCPPackets <-chan rtcp.Packet - Samples chan<- media.RTCSample + Samples chan<- media.Sample RawRTP chan<- *rtp.Packet } -// NewRawRTPTrack initializes a new *RTCTrack configured to accept raw *rtp.Packet +// NewRawRTPTrack initializes a new *Track configured to accept raw *rtp.Packet // // NB: If the source RTP stream is being broadcast to multiple tracks, each track // must receive its own copies of the source packets in order to avoid packet corruption. -func NewRawRTPTrack(payloadType uint8, ssrc uint32, id, label string, codec *RTCRtpCodec) (*RTCTrack, error) { +func NewRawRTPTrack(payloadType uint8, ssrc uint32, id, label string, codec *RTPCodec) (*Track, error) { if ssrc == 0 { return nil, errors.New("SSRC supplied to NewRawRTPTrack() must be non-zero") } - return &RTCTrack{ + return &Track{ isRawRTP: true, ID: id, @@ -52,10 +52,10 @@ func NewRawRTPTrack(payloadType uint8, ssrc uint32, id, label string, codec *RTC }, nil } -// NewRTCSampleTrack initializes a new *RTCTrack configured to accept media.RTCSample -func NewRTCSampleTrack(payloadType uint8, id, label string, codec *RTCRtpCodec) (*RTCTrack, error) { +// NewSampleTrack initializes a new *Track configured to accept media.Sample +func NewSampleTrack(payloadType uint8, id, label string, codec *RTPCodec) (*Track, error) { if codec == nil { - return nil, errors.New("codec supplied to NewRTCSampleTrack() must not be nil") + return nil, errors.New("codec supplied to NewSampleTrack() must not be nil") } buf := make([]byte, 4) @@ -63,7 +63,7 @@ func NewRTCSampleTrack(payloadType uint8, id, label string, codec *RTCRtpCodec) return nil, errors.New("failed to generate random value") } - return &RTCTrack{ + return &Track{ isRawRTP: false, ID: id, diff --git a/settingengine.go b/settingengine.go index 1eb362d70b5..580388d07dd 100644 --- a/settingengine.go +++ b/settingengine.go @@ -25,7 +25,7 @@ type SettingEngine struct { // DetachDataChannels enables detaching data channels. When enabled // data channels have to be detached in the OnOpen callback using the -// RTCDataChannel.Detach method. +// DataChannel.Detach method. func (e *SettingEngine) DetachDataChannels() { e.detach.DataChannels = true }