diff --git a/protocol/rtcp/client.go b/protocol/rtcp/client.go index 1aebc18d..fda4f866 100644 --- a/protocol/rtcp/client.go +++ b/protocol/rtcp/client.go @@ -54,7 +54,7 @@ type log func(lvl int8, msg string, args ...interface{}) // Client is an RTCP Client that will handle receiving SenderReports from a server // and sending out ReceiverReports. type Client struct { - ErrChan chan error // Client will send any errors through this chan. + err chan error // Client will send any errors through this chan. Can be accessed by Err(). cAddr *net.UDPAddr // Address of client. sAddr *net.UDPAddr // Address of RTSP server. @@ -81,7 +81,7 @@ func NewClient(clientAddress, serverAddress, name string, sendInterval time.Dura c := &Client{ name: name, - ErrChan: make(chan error, 2), + err: make(chan error), quitSend: make(chan struct{}), quitRecv: make(chan struct{}), interval: sendInterval, @@ -127,6 +127,11 @@ func (c *Client) Stop() { c.wg.Wait() } +// Err provides read access to the Client err channel. +func (c *Client) Err() <-chan error { + return c.err +} + // recv reads from the UDP connection and parses SenderReports. func (c *Client) recv() { defer c.wg.Done() @@ -139,7 +144,7 @@ func (c *Client) recv() { default: n, _, err := c.conn.ReadFromUDP(buf) if err != nil { - c.ErrChan <- err + c.err <- err continue } c.log(logger.Debug, pkg+"sender report received", "report", buf[:n]) @@ -204,7 +209,7 @@ func (c *Client) send() { c.log(logger.Debug, pkg+"sending receiver report") _, err := c.conn.Write(c.formPayload(&report, &description)) if err != nil { - c.ErrChan <- err + c.err <- err } } } @@ -228,7 +233,7 @@ func (c *Client) parse(buf []byte) { c.markReceivedTime() t, err := Timestamp(buf) if err != nil { - c.ErrChan <- errors.New(fmt.Sprintf("could not get timestamp from sender report, failed with error: %v", err)) + c.err <- errors.New(fmt.Sprintf("could not get timestamp from sender report, failed with error: %v", err)) } c.setSenderTs(t) } diff --git a/protocol/rtcp/client_test.go b/protocol/rtcp/client_test.go index 62491bf9..dd7a6ff4 100644 --- a/protocol/rtcp/client_test.go +++ b/protocol/rtcp/client_test.go @@ -163,7 +163,7 @@ func TestReceiveAndSend(t *testing.T) { go func() { for { select { - case err := <-c.ErrChan: + case err := <-c.Err(): const errConnClosed = "use of closed network connection" if !strings.Contains(err.Error(), errConnClosed) { t.Fatalf("error received from client error chan: %v\n", err)