mirror of
https://github.com/pion/webrtc.git
synced 2025-12-24 11:51:03 +08:00
Remove pkg/errors dependency
Lots of people are paying attention to what dependecies we add to their projects now. This just makes things a little cleaner. Resolves #469
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
||||
|
||||
"github.com/pions/datachannel"
|
||||
"github.com/pions/webrtc/pkg/rtcerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const dataChannelBufferSize = 16384 // Lowest common denominator among browsers
|
||||
@@ -195,7 +194,7 @@ func (d *DataChannel) open(sctpTransport *SCTPTransport) error {
|
||||
func (d *DataChannel) ensureSCTP() error {
|
||||
if d.sctpTransport == nil ||
|
||||
d.sctpTransport.association == nil {
|
||||
return errors.New("SCTP not establisched")
|
||||
return fmt.Errorf("SCTP not establisched")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -386,11 +385,11 @@ func (d *DataChannel) Detach() (*datachannel.DataChannel, error) {
|
||||
defer d.mu.Unlock()
|
||||
|
||||
if !d.api.settingEngine.detach.DataChannels {
|
||||
return nil, errors.New("enable detaching by calling webrtc.DetachDataChannels()")
|
||||
return nil, fmt.Errorf("enable detaching by calling webrtc.DetachDataChannels()")
|
||||
}
|
||||
|
||||
if d.dataChannel == nil {
|
||||
return nil, errors.New("datachannel not opened yet, try calling Detach from OnOpen")
|
||||
return nil, fmt.Errorf("datachannel not opened yet, try calling Detach from OnOpen")
|
||||
}
|
||||
|
||||
return d.dataChannel, nil
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/pions/transport/test"
|
||||
"github.com/pions/webrtc/internal/util"
|
||||
)
|
||||
|
||||
func TestDataChannel_ORTCE2E(t *testing.T) {
|
||||
@@ -153,7 +154,7 @@ func (s *testORTCStack) close() error {
|
||||
closeErrs = append(closeErrs, err)
|
||||
}
|
||||
|
||||
return flattenErrs(closeErrs)
|
||||
return util.FlattenErrs(closeErrs)
|
||||
}
|
||||
|
||||
type testORTCSignal struct {
|
||||
@@ -234,5 +235,5 @@ func signalORTCPair(stackA *testORTCStack, stackB *testORTCStack) error {
|
||||
|
||||
closeErrs := []error{errA, errB}
|
||||
|
||||
return flattenErrs(closeErrs)
|
||||
return util.FlattenErrs(closeErrs)
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/pions/dtls"
|
||||
"github.com/pions/srtp"
|
||||
"github.com/pions/webrtc/internal/mux"
|
||||
"github.com/pions/webrtc/internal/util"
|
||||
"github.com/pions/webrtc/pkg/rtcerr"
|
||||
)
|
||||
|
||||
@@ -245,7 +246,7 @@ func (t *DTLSTransport) Stop() error {
|
||||
closeErrs = append(closeErrs, err)
|
||||
}
|
||||
}
|
||||
return flattenErrs(closeErrs)
|
||||
return util.FlattenErrs(closeErrs)
|
||||
}
|
||||
|
||||
func (t *DTLSTransport) validateFingerPrint(remoteParameters DTLSParameters, remoteCert *x509.Certificate) error {
|
||||
|
||||
1
go.mod
1
go.mod
@@ -11,6 +11,5 @@ require (
|
||||
github.com/pions/srtp v1.0.4
|
||||
github.com/pions/stun v0.2.0
|
||||
github.com/pions/transport v0.2.0
|
||||
github.com/pkg/errors v0.8.1
|
||||
github.com/stretchr/testify v1.3.0
|
||||
)
|
||||
|
||||
@@ -10,9 +10,10 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"errors"
|
||||
|
||||
"github.com/pions/stun"
|
||||
"github.com/pions/webrtc/internal/util"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -282,30 +283,30 @@ func allocateUDP(network string, url *URL) (*net.UDPAddr, *stun.XorAddress, erro
|
||||
// TODO Do we want the timeout to be configurable?
|
||||
client, err := stun.NewClient(network, fmt.Sprintf("%s:%d", url.Host, url.Port), time.Second*5)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrapf(err, "Failed to create STUN client")
|
||||
return nil, nil, util.FlattenErrs([]error{errors.New("failed to create STUN client"), err})
|
||||
}
|
||||
localAddr, ok := client.LocalAddr().(*net.UDPAddr)
|
||||
if !ok {
|
||||
return nil, nil, errors.Errorf("Failed to cast STUN client to UDPAddr")
|
||||
return nil, nil, fmt.Errorf("failed to cast STUN client to UDPAddr")
|
||||
}
|
||||
|
||||
resp, err := client.Request()
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrapf(err, "Failed to make STUN request")
|
||||
return nil, nil, util.FlattenErrs([]error{errors.New("failed to make STUN request"), err})
|
||||
}
|
||||
|
||||
if err = client.Close(); err != nil {
|
||||
return nil, nil, errors.Wrapf(err, "Failed to close STUN client")
|
||||
return nil, nil, util.FlattenErrs([]error{errors.New("failed to close STUN client"), err})
|
||||
}
|
||||
|
||||
attr, ok := resp.GetOneAttribute(stun.AttrXORMappedAddress)
|
||||
if !ok {
|
||||
return nil, nil, errors.Errorf("Got respond from STUN server that did not contain XORAddress")
|
||||
return nil, nil, fmt.Errorf("got response from STUN server that did not contain XORAddress")
|
||||
}
|
||||
|
||||
var addr stun.XorAddress
|
||||
if err = addr.Unpack(resp, attr); err != nil {
|
||||
return nil, nil, errors.Wrapf(err, "Failed to unpack STUN XorAddress response")
|
||||
return nil, nil, util.FlattenErrs([]error{errors.New("failed to unpack STUN XorAddress response"), err})
|
||||
}
|
||||
|
||||
return localAddr, &addr, nil
|
||||
@@ -314,11 +315,11 @@ func allocateUDP(network string, url *URL) (*net.UDPAddr, *stun.XorAddress, erro
|
||||
func (a *Agent) startConnectivityChecks(isControlling bool, remoteUfrag, remotePwd string) error {
|
||||
switch {
|
||||
case a.haveStarted:
|
||||
return errors.Errorf("Attempted to start agent twice")
|
||||
return fmt.Errorf("attempted to start agent twice")
|
||||
case remoteUfrag == "":
|
||||
return errors.Errorf("remoteUfrag is empty")
|
||||
return fmt.Errorf("remoteUfrag is empty")
|
||||
case remotePwd == "":
|
||||
return errors.Errorf("remotePwd is empty")
|
||||
return fmt.Errorf("remotePwd is empty")
|
||||
}
|
||||
iceLog.Debugf("Started agent: isControlling? %t, remoteUfrag: %q, remotePwd: %q", isControlling, remoteUfrag, remotePwd)
|
||||
|
||||
@@ -702,7 +703,7 @@ func (a *Agent) handleNewPeerReflexiveCandidate(local *Candidate, remote net.Add
|
||||
ip = addr.IP
|
||||
port = addr.Port
|
||||
default:
|
||||
return errors.Errorf("unsupported address type %T", addr)
|
||||
return fmt.Errorf("unsupported address type %T", addr)
|
||||
}
|
||||
|
||||
pflxCandidate, err := NewCandidatePeerReflexive(
|
||||
@@ -715,7 +716,7 @@ func (a *Agent) handleNewPeerReflexiveCandidate(local *Candidate, remote net.Add
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to create peer-reflexive candidate: %v", remote)
|
||||
return util.FlattenErrs([]error{fmt.Errorf("failed to create peer-reflexive candidate: %v", remote), err})
|
||||
}
|
||||
|
||||
// Add pflxCandidate to the remote candidate list
|
||||
@@ -780,7 +781,7 @@ func (a *Agent) getBestPair() (*candidatePair, error) {
|
||||
out := <-res
|
||||
|
||||
if out == nil {
|
||||
return nil, errors.New("No Valid Candidate Pairs Available")
|
||||
return nil, errors.New("no Valid Candidate Pairs Available")
|
||||
}
|
||||
|
||||
return out, nil
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package ice
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
import "errors"
|
||||
|
||||
var (
|
||||
// ErrUnknownType indicates an error with Unknown info.
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package ice
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/pions/webrtc/pkg/rtcerr"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -15,3 +17,20 @@ func RandSeq(n int) string {
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// FlattenErrs flattens multiple errors into one
|
||||
func FlattenErrs(errs []error) error {
|
||||
var errstrings []string
|
||||
|
||||
for _, err := range errs {
|
||||
if err != nil {
|
||||
errstrings = append(errstrings, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
if len(errstrings) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf(strings.Join(errstrings, "\n"))
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@ import (
|
||||
"github.com/pions/rtcp"
|
||||
"github.com/pions/sdp/v2"
|
||||
"github.com/pions/webrtc/internal/ice"
|
||||
"github.com/pions/webrtc/internal/util"
|
||||
"github.com/pions/webrtc/pkg/logging"
|
||||
"github.com/pions/webrtc/pkg/rtcerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var pcLog = logging.NewScopedLogger("pc")
|
||||
@@ -422,9 +422,9 @@ func (pc *PeerConnection) CreateOffer(options *OfferOptions) (SessionDescription
|
||||
useIdentity := pc.idpLoginURL != nil
|
||||
switch {
|
||||
case options != nil:
|
||||
return SessionDescription{}, errors.Errorf("TODO handle options")
|
||||
return SessionDescription{}, fmt.Errorf("TODO handle options")
|
||||
case useIdentity:
|
||||
return SessionDescription{}, errors.Errorf("TODO handle identity provider")
|
||||
return SessionDescription{}, fmt.Errorf("TODO handle identity provider")
|
||||
case pc.isClosed:
|
||||
return SessionDescription{}, &rtcerr.InvalidStateError{Err: ErrConnectionClosed}
|
||||
}
|
||||
@@ -528,9 +528,9 @@ func (pc *PeerConnection) CreateAnswer(options *AnswerOptions) (SessionDescripti
|
||||
useIdentity := pc.idpLoginURL != nil
|
||||
switch {
|
||||
case options != nil:
|
||||
return SessionDescription{}, errors.Errorf("TODO handle options")
|
||||
return SessionDescription{}, fmt.Errorf("TODO handle options")
|
||||
case useIdentity:
|
||||
return SessionDescription{}, errors.Errorf("TODO handle identity provider")
|
||||
return SessionDescription{}, fmt.Errorf("TODO handle identity provider")
|
||||
case pc.isClosed:
|
||||
return SessionDescription{}, &rtcerr.InvalidStateError{Err: ErrConnectionClosed}
|
||||
}
|
||||
@@ -610,8 +610,8 @@ func (pc *PeerConnection) setDescription(sd *SessionDescription, op stateChangeO
|
||||
cur := pc.SignalingState
|
||||
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")}
|
||||
newSDPDoesNotMatchOffer := &rtcerr.InvalidModificationError{Err: fmt.Errorf("new sdp does not match previous offer")}
|
||||
newSDPDoesNotMatchAnswer := &rtcerr.InvalidModificationError{Err: fmt.Errorf("new sdp does not match previous answer")}
|
||||
|
||||
var nextState SignalingState
|
||||
var err error
|
||||
@@ -744,7 +744,7 @@ func (pc *PeerConnection) LocalDescription() *SessionDescription {
|
||||
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")
|
||||
return fmt.Errorf("remoteDescription is already defined, SetRemoteDescription can only be called once")
|
||||
}
|
||||
if pc.isClosed {
|
||||
return &rtcerr.InvalidStateError{Err: ErrConnectionClosed}
|
||||
@@ -794,13 +794,13 @@ func (pc *PeerConnection) SetRemoteDescription(desc SessionDescription) error {
|
||||
if !ok {
|
||||
fingerprint, ok = desc.parsed.MediaDescriptions[0].Attribute("fingerprint")
|
||||
if !ok {
|
||||
return errors.New("could not find fingerprint")
|
||||
return fmt.Errorf("could not find fingerprint")
|
||||
}
|
||||
}
|
||||
var fingerprintHash string
|
||||
parts := strings.Split(fingerprint, " ")
|
||||
if len(parts) != 2 {
|
||||
return errors.New("invalid fingerprint")
|
||||
return fmt.Errorf("invalid fingerprint")
|
||||
}
|
||||
fingerprint = parts[1]
|
||||
fingerprintHash = parts[0]
|
||||
@@ -1278,7 +1278,7 @@ func (pc *PeerConnection) generateDataChannelID(client bool) (uint16, error) {
|
||||
|
||||
// SetIdentityProvider is used to configure an identity provider to generate identity assertions
|
||||
func (pc *PeerConnection) SetIdentityProvider(provider string) error {
|
||||
return errors.Errorf("TODO SetIdentityProvider")
|
||||
return fmt.Errorf("TODO SetIdentityProvider")
|
||||
}
|
||||
|
||||
// SendRTCP sends a user provided RTCP packet to the connected peer
|
||||
@@ -1360,24 +1360,7 @@ func (pc *PeerConnection) Close() error {
|
||||
|
||||
// TODO: Figure out stopping ICE transport & Gatherer independently.
|
||||
// pc.iceGatherer()
|
||||
|
||||
return flattenErrs(closeErrs)
|
||||
}
|
||||
|
||||
func flattenErrs(errs []error) error {
|
||||
var errstrings []string
|
||||
|
||||
for _, err := range errs {
|
||||
if err != nil {
|
||||
errstrings = append(errstrings, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
if len(errstrings) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf(strings.Join(errstrings, "\n"))
|
||||
return util.FlattenErrs(closeErrs)
|
||||
}
|
||||
|
||||
func (pc *PeerConnection) iceStateChange(newState ICEConnectionState) {
|
||||
@@ -1499,7 +1482,7 @@ func (pc *PeerConnection) NewTrack(payloadType uint8, ssrc uint32, id, label str
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if codec.Payloader == nil {
|
||||
return nil, errors.New("codec payloader not set")
|
||||
return nil, fmt.Errorf("codec payloader not set")
|
||||
}
|
||||
|
||||
return NewTrack(payloadType, ssrc, id, label, codec)
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/pions/quic"
|
||||
"github.com/pions/transport/test"
|
||||
"github.com/pions/webrtc/internal/util"
|
||||
)
|
||||
|
||||
func TestQUICTransport_E2E(t *testing.T) {
|
||||
@@ -143,7 +144,7 @@ func (s *testQuicStack) close() error {
|
||||
closeErrs = append(closeErrs, err)
|
||||
}
|
||||
|
||||
return flattenErrs(closeErrs)
|
||||
return util.FlattenErrs(closeErrs)
|
||||
}
|
||||
|
||||
type testQuicSignal struct {
|
||||
@@ -217,5 +218,5 @@ func signalQuicPair(stackA *testQuicStack, stackB *testQuicStack) error {
|
||||
|
||||
closeErrs := []error{errA, errB}
|
||||
|
||||
return flattenErrs(closeErrs)
|
||||
return util.FlattenErrs(closeErrs)
|
||||
}
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
package webrtc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
import "fmt"
|
||||
|
||||
// RTPTransceiver represents a combination of an RTPSender and an RTPReceiver that share a common mid.
|
||||
type RTPTransceiver struct {
|
||||
@@ -20,7 +16,7 @@ type RTPTransceiver struct {
|
||||
|
||||
func (t *RTPTransceiver) setSendingTrack(track *Track) error {
|
||||
if track == nil {
|
||||
return fmt.Errorf("Track must not be nil")
|
||||
return fmt.Errorf("track must not be nil")
|
||||
}
|
||||
|
||||
t.Sender.track = track
|
||||
@@ -31,7 +27,7 @@ func (t *RTPTransceiver) setSendingTrack(track *Track) error {
|
||||
case RTPTransceiverDirectionInactive:
|
||||
t.Direction = RTPTransceiverDirectionSendonly
|
||||
default:
|
||||
return errors.Errorf("Invalid state change in RTPTransceiver.setSending")
|
||||
return fmt.Errorf("invalid state change in RTPTransceiver.setSending")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pions/webrtc/pkg/rtcerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type stateChangeOp int
|
||||
@@ -108,7 +107,7 @@ func checkNextSignalingState(cur, next SignalingState, op stateChangeOp, sdpType
|
||||
// Special case for rollbacks
|
||||
if sdpType == SDPTypeRollback && cur == SignalingStateStable {
|
||||
return cur, &rtcerr.InvalidModificationError{
|
||||
Err: errors.New("Can't rollback from stable state"),
|
||||
Err: fmt.Errorf("can't rollback from stable state"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user