Repository: pions/webrtc (go)

Issue:
WriteRTP / SendRTCP API is inconsistent
`track.WriteRTP()` is used to send RTP packets. `pc.SendRTCP()` is used to send RTCP packets.

We should use the same prefix for both of these methods so there is consistency.

I was using WriteRTP in my code and when I needed to start sending RTCP packets I expected the method to be called WriteRTCP. I tried finding the method using autocomplete but could not find it because the prefix was different.

Pull request description:
Rename SendRTCP -> WriteRTCP
To make it consistent with WriteRTP

Fixes #557

Patch:
diff --git a/examples/gstreamer-receive/main.go b/examples/gstreamer-receive/main.go
index 02b12c71..6b1d13c3 100644
--- a/examples/gstreamer-receive/main.go
+++ b/examples/gstreamer-receive/main.go
@@ -40,7 +40,7 @@ func gstreamerReceiveMain() {
 		go func() {
 			ticker := time.NewTicker(time.Second * 3)
 			for range ticker.C {
-				rtcpSendErr := peerConnection.SendRTCP(&rtcp.PictureLossIndication{MediaSSRC: track.SSRC()})
+				rtcpSendErr := peerConnection.WriteRTCP(&rtcp.PictureLossIndication{MediaSSRC: track.SSRC()})
 				if rtcpSendErr != nil {
 					fmt.Println(rtcpSendErr)
 				}
diff --git a/examples/save-to-disk/main.go b/examples/save-to-disk/main.go
index 8d581141..0d03491d 100644
--- a/examples/save-to-disk/main.go
+++ b/examples/save-to-disk/main.go
@@ -78,7 +78,7 @@ func main() {
 		go func() {
 			ticker := time.NewTicker(time.Second * 3)
 			for range ticker.C {
-				errSend := peerConnection.SendRTCP(&rtcp.PictureLossIndication{MediaSSRC: track.SSRC()})
+				errSend := peerConnection.WriteRTCP(&rtcp.PictureLossIndication{MediaSSRC: track.SSRC()})
 				if errSend != nil {
 					fmt.Println(errSend)
 				}
diff --git a/examples/sfu-minimal/main.go b/examples/sfu-minimal/main.go
index fc107a94..b1999eb0 100644
--- a/examples/sfu-minimal/main.go
+++ b/examples/sfu-minimal/main.go
@@ -55,7 +55,7 @@ func main() {
 		go func() {
 			ticker := time.NewTicker(rtcpPLIInterval)
 			for range ticker.C {
-				if rtcpSendErr := peerConnection.SendRTCP(&rtcp.PictureLossIndication{MediaSSRC: remoteTrack.SSRC()}); rtcpSendErr != nil {
+				if rtcpSendErr := peerConnection.WriteRTCP(&rtcp.PictureLossIndication{MediaSSRC: remoteTrack.SSRC()}); rtcpSendErr != nil {
 					fmt.Println(rtcpSendErr)
 				}
 			}
diff --git a/examples/sfu-ws/go.sum b/examples/sfu-ws/go.sum
index ed0edf21..4f8875b7 100644
--- a/examples/sfu-ws/go.sum
+++ b/examples/sfu-ws/go.sum
@@ -30,6 +30,8 @@ github.com/pions/dtls v1.2.2 h1:izn/74bIBxVuHb+NdirkmWMH/yFNd8PBVXJgeH/ofGU=
 github.com/pions/dtls v1.2.2/go.mod h1:5o0cLHyBEl8CvuA88enDDM6aBwn4SNo8md2dPhcynfc=
 github.com/pions/ice v0.1.0 h1:V3RaaUV7QEFUrNk2tHzRqNo3ldCwwnghEpDIQ8+m/eA=
 github.com/pions/ice v0.1.0/go.mod h1:vGnMrwYxOMmfR093luGSh2yMm1DDpPqj8lGRNsmo9VQ=
+github.com/pions/ice v0.1.1 h1:SZouAvl9RnrNnCHxSnurOfzqK2+oD0ZeURSoxuOs0tI=
+github.com/pions/ice v0.1.1/go.mod h1:vGnMrwYxOMmfR093luGSh2yMm1DDpPqj8lGRNsmo9VQ=
 github.com/pions/logging v0.1.0 h1:vr+vInmjaRI06CqPWErEQpywxaqoIZcUjQ2eN68jRbk=
 github.com/pions/logging v0.1.0/go.mod h1:duuz9/Se8ujqvq7OPzbnPpRlha6A0fk1Ba2wrbn4zew=
 github.com/pions/qtls-vendor-extracted v0.0.0-20190210024908-018998217c65 h1:skcEQZ2eUdm1WKlYu7y1y0HBzOwa1pgSAwvhG6PrI2s=
diff --git a/examples/sfu-ws/room.go b/examples/sfu-ws/room.go
index edf5971c..976addf4 100644
--- a/examples/sfu-ws/room.go
+++ b/examples/sfu-ws/room.go
@@ -83,7 +83,7 @@ func room(w http.ResponseWriter, r *http.Request) {
 				go func() {
 					ticker := time.NewTicker(rtcpPLIInterval)
 					for range ticker.C {
-						checkError(pubReceiver.SendRTCP(&rtcp.PictureLossIndication{MediaSSRC: videoTrack.SSRC()}))
+						checkError(pubReceiver.WriteRTCP(&rtcp.PictureLossIndication{MediaSSRC: videoTrack.SSRC()}))
 					}
 				}()
 
diff --git a/peerconnection.go b/peerconnection.go
index 58b3c81c..4d8c46f8 100644
--- a/peerconnection.go
+++ b/peerconnection.go
@@ -1309,9 +1309,9 @@ func (pc *PeerConnection) SetIdentityProvider(provider string) error {
 	return fmt.Errorf("TODO SetIdentityProvider")
 }
 
-// SendRTCP sends a user provided RTCP packet to the connected peer
+// WriteRTCP sends a user provided RTCP packet to the connected peer
 // If no peer is connected the packet is discarded
-func (pc *PeerConnection) SendRTCP(pkt rtcp.Packet) error {
+func (pc *PeerConnection) WriteRTCP(pkt rtcp.Packet) error {
 	raw, err := pkt.Marshal()
 	if err != nil {
 		return err
@@ -1319,19 +1319,19 @@ func (pc *PeerConnection) SendRTCP(pkt rtcp.Packet) error {
 
 	srtcpSession, err := pc.dtlsTransport.getSRTCPSession()
 	if err != nil {
-		return nil // TODO SendRTCP before would gracefully discard packets until ready
+		return nil // TODO WriteRTCP before would gracefully discard packets until ready
 	}
 
 	writeStream, err := srtcpSession.OpenWriteStream()
 	if err != nil {
-		return fmt.Errorf("SendRTCP failed to open WriteStream: %v", err)
+		return fmt.Errorf("WriteRTCP failed to open WriteStream: %v", err)
 	}
 
 	if _, err := writeStream.Write(raw); err != nil {
 		if err == ice.ErrNoCandidatePairs {
 			return nil
 		}
-		return fmt.Errorf("SendRTCP failed to write: %v", err)
+		return fmt.Errorf("WriteRTCP failed to write: %v", err)
 	}
 	return nil
 }
diff --git a/peerconnection_js.go b/peerconnection_js.go
index bf12678d..2e17c7d7 100644
--- a/peerconnection_js.go
+++ b/peerconnection_js.go
@@ -355,8 +355,8 @@ func (pc *PeerConnection) SetIdentityProvider(provider string) (err error) {
 	return nil
 }
 
-// Note: SendRTCP is not supported.
-// func (pc *PeerConnection) SendRTCP(pkt rtcp.Packet) error {
+// Note: WriteRTCP is not supported.
+// func (pc *PeerConnection) WriteRTCP(pkt rtcp.Packet) error {
 // 	return errors.New("Not yet implemented")
 // }
 


Test patch:
diff --git a/peerconnection_media_test.go b/peerconnection_media_test.go
index 5cb6246e..3e437d7d 100644
--- a/peerconnection_media_test.go
+++ b/peerconnection_media_test.go
@@ -50,7 +50,7 @@ func TestPeerConnection_Media_Sample(t *testing.T) {
 		go func() {
 			for {
 				time.Sleep(time.Millisecond * 100)
-				if routineErr := pcAnswer.SendRTCP(&rtcp.RapidResynchronizationRequest{SenderSSRC: track.SSRC(), MediaSSRC: track.SSRC()}); routineErr != nil {
+				if routineErr := pcAnswer.WriteRTCP(&rtcp.RapidResynchronizationRequest{SenderSSRC: track.SSRC(), MediaSSRC: track.SSRC()}); routineErr != nil {
 					awaitRTCPRecieverSend <- routineErr
 					return
 				}
@@ -114,7 +114,7 @@ func TestPeerConnection_Media_Sample(t *testing.T) {
 	go func() {
 		for {
 			time.Sleep(time.Millisecond * 100)
-			if routineErr := pcOffer.SendRTCP(&rtcp.PictureLossIndication{SenderSSRC: vp8Track.SSRC(), MediaSSRC: vp8Track.SSRC()}); routineErr != nil {
+			if routineErr := pcOffer.WriteRTCP(&rtcp.PictureLossIndication{SenderSSRC: vp8Track.SSRC(), MediaSSRC: vp8Track.SSRC()}); routineErr != nil {
 				awaitRTCPSenderSend <- routineErr
 			}
 
@@ -336,7 +336,7 @@ func TestPeerConnection_Media_Disconnected(t *testing.T) {
 	for i := 0; i <= 5; i++ {
 		if rtpErr := vp8Track.WriteSample(media.Sample{Data: []byte{0x00}, Samples: 1}); rtpErr != nil {
 			t.Fatal(rtpErr)
-		} else if rtcpErr := pcOffer.SendRTCP(&rtcp.PictureLossIndication{MediaSSRC: 0}); rtcpErr != nil {
+		} else if rtcpErr := pcOffer.WriteRTCP(&rtcp.PictureLossIndication{MediaSSRC: 0}); rtcpErr != nil {
 			t.Fatal(rtcpErr)
 		}
 	}