mirror of
				https://github.com/pion/webrtc.git
				synced 2025-10-31 10:46:39 +08:00 
			
		
		
		
	Add corrections to comply with govet, golint, etc.
This commit is contained in:
		 Konstantin Itskov
					Konstantin Itskov
				
			
				
					committed by
					
						 Sean DuBois
						Sean DuBois
					
				
			
			
				
	
			
			
			 Sean DuBois
						Sean DuBois
					
				
			
						parent
						
							7b7a349071
						
					
				
				
					commit
					902cf087aa
				
			
							
								
								
									
										37
									
								
								errors.go
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								errors.go
									
									
									
									
									
								
							| @@ -6,19 +6,56 @@ import ( | |||||||
| ) | ) | ||||||
|  |  | ||||||
| var ( | var ( | ||||||
|  | 	// ErrUnknownType indicates an error with Unknown info. | ||||||
| 	ErrUnknownType = errors.New("unknown") | 	ErrUnknownType = errors.New("unknown") | ||||||
|  |  | ||||||
|  | 	// ErrConnectionClosed indicates an operation executed after connection | ||||||
|  | 	// has already been closed. | ||||||
| 	ErrConnectionClosed = errors.New("connection closed") | 	ErrConnectionClosed = errors.New("connection closed") | ||||||
|  |  | ||||||
|  | 	// ErrCertificateExpired indicates that an x509 certificate has expired. | ||||||
| 	ErrCertificateExpired = errors.New("x509Cert expired") | 	ErrCertificateExpired = errors.New("x509Cert expired") | ||||||
|  |  | ||||||
|  | 	// ErrNoTurnCredencials indicates that a TURN server URL was provided | ||||||
|  | 	// without required credentials. | ||||||
| 	ErrNoTurnCredencials = errors.New("turn server credentials required") | 	ErrNoTurnCredencials = errors.New("turn server credentials required") | ||||||
|  |  | ||||||
|  | 	// ErrTurnCredencials indicates that provided TURN credentials are partial | ||||||
|  | 	// or malformed. | ||||||
| 	ErrTurnCredencials = errors.New("invalid turn server credentials") | 	ErrTurnCredencials = errors.New("invalid turn server credentials") | ||||||
|  |  | ||||||
|  | 	// ErrExistingTrack indicates that a track already exists. | ||||||
| 	ErrExistingTrack = errors.New("track aready exists") | 	ErrExistingTrack = errors.New("track aready exists") | ||||||
|  |  | ||||||
|  | 	// ErrPrivateKeyType indicates that a particular private key encryption | ||||||
|  | 	// chosen to generate a certificate is not supported. | ||||||
| 	ErrPrivateKeyType = errors.New("private key type not supported") | 	ErrPrivateKeyType = errors.New("private key type not supported") | ||||||
|  |  | ||||||
|  | 	// ErrModifyingPeerIdentity indicates that an attempt to modify | ||||||
|  | 	// PeerIdentity was made after RTCPeerConnection has been initialized. | ||||||
| 	ErrModifyingPeerIdentity = errors.New("peerIdentity cannot be modified") | 	ErrModifyingPeerIdentity = errors.New("peerIdentity cannot be modified") | ||||||
|  |  | ||||||
|  | 	// ErrModifyingCertificates indicates that an attempt to modify | ||||||
|  | 	// Certificates was made after RTCPeerConnection has been initialized. | ||||||
| 	ErrModifyingCertificates = errors.New("certificates cannot be modified") | 	ErrModifyingCertificates = errors.New("certificates cannot be modified") | ||||||
|  |  | ||||||
|  | 	// ErrModifyingBundlePolicy indicates that an attempt to modify | ||||||
|  | 	// BundlePolicy was made after RTCPeerConnection has been initialized. | ||||||
| 	ErrModifyingBundlePolicy = errors.New("bundle policy cannot be modified") | 	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 = 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 = errors.New("ice candidate pool size cannot be modified") | ||||||
|  |  | ||||||
|  | 	// ErrInvalidValue indicates that an invalid value was provided. | ||||||
| 	ErrInvalidValue = errors.New("invalid value") | 	ErrInvalidValue = errors.New("invalid value") | ||||||
|  |  | ||||||
|  | 	// ErrMaxDataChannels indicates that the maximum number of data channels | ||||||
|  | 	// was reached. | ||||||
| 	ErrMaxDataChannels = errors.New("maximum number of datachannels reached") | 	ErrMaxDataChannels = errors.New("maximum number of datachannels reached") | ||||||
| ) | ) | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										4
									
								
								media.go
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								media.go
									
									
									
									
									
								
							| @@ -181,14 +181,14 @@ func (pc *RTCPeerConnection) NewRTCTrack(payloadType uint8, id, label string) (* | |||||||
| // AddTrack adds a RTCTrack to the RTCPeerConnection | // AddTrack adds a RTCTrack to the RTCPeerConnection | ||||||
| func (pc *RTCPeerConnection) AddTrack(track *RTCTrack) (*RTCRtpSender, error) { | func (pc *RTCPeerConnection) AddTrack(track *RTCTrack) (*RTCRtpSender, error) { | ||||||
| 	if pc.IsClosed { | 	if pc.IsClosed { | ||||||
| 		return nil, &InvalidStateError{ErrConnectionClosed} | 		return nil, &InvalidStateError{Err: ErrConnectionClosed} | ||||||
| 	} | 	} | ||||||
| 	for _, transceiver := range pc.rtpTransceivers { | 	for _, transceiver := range pc.rtpTransceivers { | ||||||
| 		if transceiver.Sender.Track == nil { | 		if transceiver.Sender.Track == nil { | ||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
| 		if track.ID == transceiver.Sender.Track.ID { | 		if track.ID == transceiver.Sender.Track.ID { | ||||||
| 			return nil, &InvalidAccessError{ErrExistingTrack} | 			return nil, &InvalidAccessError{Err: ErrExistingTrack} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	var transceiver *RTCRtpTransceiver | 	var transceiver *RTCRtpTransceiver | ||||||
|   | |||||||
| @@ -5,27 +5,26 @@ import ( | |||||||
| 	"github.com/pkg/errors" | 	"github.com/pkg/errors" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // Types of InvalidStateErrors |  | ||||||
| var ( | var ( | ||||||
| 	// ErrUnknownType indicates a Unknown info | 	// ErrUnknownType indicates an error with Unknown info. | ||||||
| 	ErrUnknownType = errors.New("Unknown") | 	ErrUnknownType = errors.New("Unknown") | ||||||
|  |  | ||||||
| 	// ErrServerType indicates the scheme type could not be parsed | 	// ErrSchemeType indicates the scheme type could not be parsed. | ||||||
| 	ErrSchemeType = errors.New("unknown scheme type") | 	ErrSchemeType = errors.New("unknown scheme type") | ||||||
|  |  | ||||||
| 	// ErrSTUNQuery indicates query arguments are provided in a STUN URL | 	// ErrSTUNQuery indicates query arguments are provided in a STUN URL. | ||||||
| 	ErrSTUNQuery = errors.New("queries not supported in stun address") | 	ErrSTUNQuery = errors.New("queries not supported in stun address") | ||||||
|  |  | ||||||
| 	// ErrInvalidQuery indicates an malformed query is provided | 	// ErrInvalidQuery indicates an malformed query is provided. | ||||||
| 	ErrInvalidQuery = errors.New("invalid query") | 	ErrInvalidQuery = errors.New("invalid query") | ||||||
|  |  | ||||||
| 	// ErrHost indicates malformed hostname is provided | 	// ErrHost indicates malformed hostname is provided. | ||||||
| 	ErrHost = errors.New("invalid hostname") | 	ErrHost = errors.New("invalid hostname") | ||||||
|  |  | ||||||
| 	// ErrPort indicates malformed port is provided | 	// ErrPort indicates malformed port is provided. | ||||||
| 	ErrPort = errors.New("invalid port") | 	ErrPort = errors.New("invalid port") | ||||||
|  |  | ||||||
| 	// ErrProtoType indicates an unsupported transport type was provided | 	// ErrProtoType indicates an unsupported transport type was provided. | ||||||
| 	ErrProtoType = errors.New("invalid transport protocol type") | 	ErrProtoType = errors.New("invalid transport protocol type") | ||||||
| ) | ) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -8,20 +8,26 @@ import ( | |||||||
|  |  | ||||||
| // TODO: Migrate address parsing to STUN/TURN packages? | // TODO: Migrate address parsing to STUN/TURN packages? | ||||||
|  |  | ||||||
| // Scheme indicates the type of server used | // SchemeType indicates the type of server used in the ice.URL structure. | ||||||
| type SchemeType int | type SchemeType int | ||||||
|  |  | ||||||
| const ( | const ( | ||||||
| 	// SchemeTypeSTUN indicates the URL represents a STUN server | 	// SchemeTypeSTUN indicates the URL represents a STUN server. | ||||||
| 	SchemeTypeSTUN SchemeType = iota + 1 | 	SchemeTypeSTUN SchemeType = iota + 1 | ||||||
|  |  | ||||||
|  | 	// SchemeTypeSTUNS indicates the URL represents a STUNS (secure) server. | ||||||
| 	SchemeTypeSTUNS | 	SchemeTypeSTUNS | ||||||
|  |  | ||||||
| 	// SchemeTypeTURN indicates the URL represents a TURN server | 	// SchemeTypeTURN indicates the URL represents a TURN server. | ||||||
| 	SchemeTypeTURN | 	SchemeTypeTURN | ||||||
|  |  | ||||||
|  | 	// SchemeTypeTURNS indicates the URL represents a TURNS (secure) server. | ||||||
| 	SchemeTypeTURNS | 	SchemeTypeTURNS | ||||||
| ) | ) | ||||||
|  |  | ||||||
| func NewSchemeType(raw string) (unknown SchemeType) { | // NewSchemeType defines a procedure for creating a new SchemeType from a raw | ||||||
|  | // string naming the scheme type. | ||||||
|  | func NewSchemeType(raw string) (SchemeType) { | ||||||
| 	switch raw { | 	switch raw { | ||||||
| 	case "stun": | 	case "stun": | ||||||
| 		return SchemeTypeSTUN | 		return SchemeTypeSTUN | ||||||
| @@ -32,7 +38,7 @@ func NewSchemeType(raw string) (unknown SchemeType) { | |||||||
| 	case "turns": | 	case "turns": | ||||||
| 		return SchemeTypeTURNS | 		return SchemeTypeTURNS | ||||||
| 	default: | 	default: | ||||||
| 		return unknown | 		return SchemeType(Unknown) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -51,25 +57,28 @@ func (t SchemeType) String() string { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| // Proto indicates the transport that is used | // ProtoType indicates the transport protocol type that is used in the ice.URL | ||||||
|  | // structure. | ||||||
| type ProtoType int | type ProtoType int | ||||||
|  |  | ||||||
| const ( | const ( | ||||||
| 	// ProtoTypeUDP indicates the URL uses a UDP transport | 	// ProtoTypeUDP indicates the URL uses a UDP transport. | ||||||
| 	ProtoTypeUDP ProtoType = iota + 1 | 	ProtoTypeUDP ProtoType = iota + 1 | ||||||
|  |  | ||||||
| 	// ProtoTypeTCP indicates the URL uses a TCP transport | 	// ProtoTypeTCP indicates the URL uses a TCP transport. | ||||||
| 	ProtoTypeTCP | 	ProtoTypeTCP | ||||||
| ) | ) | ||||||
|  |  | ||||||
| func NewProtoType(raw string) (unknown ProtoType) { | // NewProtoType defines a procedure for creating a new ProtoType from a raw | ||||||
|  | // string naming the transport protocol type. | ||||||
|  | func NewProtoType(raw string) (ProtoType) { | ||||||
| 	switch raw { | 	switch raw { | ||||||
| 	case "udp": | 	case "udp": | ||||||
| 		return ProtoTypeUDP | 		return ProtoTypeUDP | ||||||
| 	case "tcp": | 	case "tcp": | ||||||
| 		return ProtoTypeTCP | 		return ProtoTypeTCP | ||||||
| 	default: | 	default: | ||||||
| 		return unknown | 		return ProtoType(Unknown) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -92,16 +101,19 @@ type URL struct { | |||||||
| 	Proto  ProtoType | 	Proto  ProtoType | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // ParseURL parses a STUN or TURN urls following the ABNF syntax described in | ||||||
|  | // https://tools.ietf.org/html/rfc7064 and https://tools.ietf.org/html/rfc7065 | ||||||
|  | // respectively. | ||||||
| func ParseURL(raw string) (*URL, error) { | func ParseURL(raw string) (*URL, error) { | ||||||
| 	rawParts, err := url.Parse(raw) | 	rawParts, err := url.Parse(raw) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, &UnknownError{err} | 		return nil, &UnknownError{Err: err} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	var u URL | 	var u URL | ||||||
| 	u.Scheme = NewSchemeType(rawParts.Scheme) | 	u.Scheme = NewSchemeType(rawParts.Scheme) | ||||||
| 	if u.Scheme == SchemeType(Unknown) { | 	if u.Scheme == SchemeType(Unknown) { | ||||||
| 		return nil, &SyntaxError{ErrSchemeType} | 		return nil, &SyntaxError{Err: ErrSchemeType} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	var rawPort string | 	var rawPort string | ||||||
| @@ -125,28 +137,28 @@ func ParseURL(raw string) (*URL, error) { | |||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		return nil, &UnknownError{err} | 		return nil, &UnknownError{Err: err} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if u.Host == "" { | 	if u.Host == "" { | ||||||
| 		return nil, &SyntaxError{ErrHost} | 		return nil, &SyntaxError{Err: ErrHost} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if u.Port, err = strconv.Atoi(rawPort); err != nil { | 	if u.Port, err = strconv.Atoi(rawPort); err != nil { | ||||||
| 		return nil, &SyntaxError{ErrPort} | 		return nil, &SyntaxError{Err: ErrPort} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	switch { | 	switch { | ||||||
| 	case u.Scheme == SchemeTypeSTUN: | 	case u.Scheme == SchemeTypeSTUN: | ||||||
| 		qArgs, err := url.ParseQuery(rawParts.RawQuery) | 		qArgs, err := url.ParseQuery(rawParts.RawQuery) | ||||||
| 		if err != nil || (err == nil && len(qArgs) > 0) { | 		if err != nil || (err == nil && len(qArgs) > 0) { | ||||||
| 			return nil, &SyntaxError{ErrSTUNQuery} | 			return nil, &SyntaxError{Err: ErrSTUNQuery} | ||||||
| 		} | 		} | ||||||
| 		u.Proto = ProtoTypeUDP | 		u.Proto = ProtoTypeUDP | ||||||
| 	case u.Scheme == SchemeTypeSTUNS: | 	case u.Scheme == SchemeTypeSTUNS: | ||||||
| 		qArgs, err := url.ParseQuery(rawParts.RawQuery) | 		qArgs, err := url.ParseQuery(rawParts.RawQuery) | ||||||
| 		if err != nil || (err == nil && len(qArgs) > 0) { | 		if err != nil || (err == nil && len(qArgs) > 0) { | ||||||
| 			return nil, &SyntaxError{ErrSTUNQuery} | 			return nil, &SyntaxError{Err: ErrSTUNQuery} | ||||||
| 		} | 		} | ||||||
| 		u.Proto = ProtoTypeTCP | 		u.Proto = ProtoTypeTCP | ||||||
| 	case u.Scheme == SchemeTypeTURN: | 	case u.Scheme == SchemeTypeTURN: | ||||||
| @@ -177,19 +189,19 @@ func ParseURL(raw string) (*URL, error) { | |||||||
| func parseProto(raw string) (ProtoType, error) { | func parseProto(raw string) (ProtoType, error) { | ||||||
| 	qArgs, err := url.ParseQuery(raw) | 	qArgs, err := url.ParseQuery(raw) | ||||||
| 	if err != nil || len(qArgs) > 1 { | 	if err != nil || len(qArgs) > 1 { | ||||||
| 		return ProtoType(Unknown), &SyntaxError{ErrInvalidQuery} | 		return ProtoType(Unknown), &SyntaxError{Err: ErrInvalidQuery} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	var proto ProtoType | 	var proto ProtoType | ||||||
| 	if rawProto := qArgs.Get("transport"); rawProto != "" { | 	if rawProto := qArgs.Get("transport"); rawProto != "" { | ||||||
| 		if proto = NewProtoType(rawProto); proto == ProtoType(0) { | 		if proto = NewProtoType(rawProto); proto == ProtoType(0) { | ||||||
| 			return ProtoType(Unknown), &NotSupportedError{ErrProtoType} | 			return ProtoType(Unknown), &NotSupportedError{Err: ErrProtoType} | ||||||
| 		} | 		} | ||||||
| 		return proto, nil | 		return proto, nil | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if len(qArgs) > 0 { | 	if len(qArgs) > 0 { | ||||||
| 		return ProtoType(Unknown), &SyntaxError{ErrInvalidQuery} | 		return ProtoType(Unknown), &SyntaxError{Err: ErrInvalidQuery} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return proto, nil | 	return proto, nil | ||||||
| @@ -203,6 +215,7 @@ func (u URL) String() string { | |||||||
| 	return rawURL | 	return rawURL | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // IsSecure returns whether the this URL's scheme describes secure scheme or not. | ||||||
| func (u URL) IsSecure() bool { | func (u URL) IsSecure() bool { | ||||||
| 	return u.Scheme == SchemeTypeSTUNS || u.Scheme == SchemeTypeTURNS | 	return u.Scheme == SchemeTypeSTUNS || u.Scheme == SchemeTypeTURNS | ||||||
| } | } | ||||||
|   | |||||||
| @@ -47,19 +47,19 @@ func TestParseURL(t *testing.T) { | |||||||
| 			rawURL      string | 			rawURL      string | ||||||
| 			expectedErr error | 			expectedErr error | ||||||
| 		}{ | 		}{ | ||||||
| 			{"", &SyntaxError{ErrSchemeType}}, | 			{"", &SyntaxError{Err: ErrSchemeType}}, | ||||||
| 			{":::", &UnknownError{errors.New("parse :::: missing protocol scheme")}}, | 			{":::", &UnknownError{Err: errors.New("parse :::: missing protocol scheme")}}, | ||||||
| 			{"stun:[::1]:123:", &UnknownError{errors.New("address [::1]:123:: too many colons in address")}}, | 			{"stun:[::1]:123:", &UnknownError{Err: errors.New("address [::1]:123:: too many colons in address")}}, | ||||||
| 			{"stun:[::1]:123a", &SyntaxError{ErrPort}}, | 			{"stun:[::1]:123a", &SyntaxError{Err: ErrPort}}, | ||||||
| 			{"google.de", &SyntaxError{ErrSchemeType}}, | 			{"google.de", &SyntaxError{Err: ErrSchemeType}}, | ||||||
| 			{"stun:", &SyntaxError{ErrHost}}, | 			{"stun:", &SyntaxError{Err: ErrHost}}, | ||||||
| 			{"stun:google.de:abc", &SyntaxError{ErrPort}}, | 			{"stun:google.de:abc", &SyntaxError{Err: ErrPort}}, | ||||||
| 			{"stun:google.de?transport=udp", &SyntaxError{ErrSTUNQuery}}, | 			{"stun:google.de?transport=udp", &SyntaxError{Err: ErrSTUNQuery}}, | ||||||
| 			{"stuns:google.de?transport=udp", &SyntaxError{ErrSTUNQuery}}, | 			{"stuns:google.de?transport=udp", &SyntaxError{Err: ErrSTUNQuery}}, | ||||||
| 			{"turn:google.de?trans=udp", &SyntaxError{ErrInvalidQuery}}, | 			{"turn:google.de?trans=udp", &SyntaxError{Err: ErrInvalidQuery}}, | ||||||
| 			{"turns:google.de?trans=udp", &SyntaxError{ErrInvalidQuery}}, | 			{"turns:google.de?trans=udp", &SyntaxError{Err: ErrInvalidQuery}}, | ||||||
| 			{"turns:google.de?transport=udp&another=1", &SyntaxError{ErrInvalidQuery}}, | 			{"turns:google.de?transport=udp&another=1", &SyntaxError{Err: ErrInvalidQuery}}, | ||||||
| 			{"turn:google.de?transport=ip", &NotSupportedError{ErrProtoType}}, | 			{"turn:google.de?transport=ip", &NotSupportedError{Err: ErrProtoType}}, | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		for i, testCase := range testCases { | 		for i, testCase := range testCases { | ||||||
|   | |||||||
| @@ -24,7 +24,7 @@ const ( | |||||||
| 	RTCBundlePolicyMaxBundle | 	RTCBundlePolicyMaxBundle | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // NewRTCBundlePolicy defines a proceedure for creating a new RTCBundlePolicy | // NewRTCBundlePolicy defines a procedure for creating a new RTCBundlePolicy | ||||||
| // from a raw string naming the bundle policy. | // from a raw string naming the bundle policy. | ||||||
| func NewRTCBundlePolicy(raw string) RTCBundlePolicy { | func NewRTCBundlePolicy(raw string) RTCBundlePolicy { | ||||||
| 	switch raw { | 	switch raw { | ||||||
|   | |||||||
| @@ -18,6 +18,10 @@ type RTCCertificate struct { | |||||||
| 	x509Cert  *x509.Certificate | 	x509Cert  *x509.Certificate | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // NewRTCCertificate generates a new x509 compliant RTCCertificate 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 NewRTCCertificate(key crypto.PrivateKey, tpl x509.Certificate) (*RTCCertificate, error) { | ||||||
| 	var err error | 	var err error | ||||||
| 	var certDER []byte | 	var certDER []byte | ||||||
| @@ -27,28 +31,29 @@ func NewRTCCertificate(key crypto.PrivateKey, tpl x509.Certificate) (*RTCCertifi | |||||||
| 		tpl.SignatureAlgorithm = x509.SHA256WithRSA | 		tpl.SignatureAlgorithm = x509.SHA256WithRSA | ||||||
| 		certDER, err = x509.CreateCertificate(rand.Reader, &tpl, &tpl, pk, sk) | 		certDER, err = x509.CreateCertificate(rand.Reader, &tpl, &tpl, pk, sk) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, &UnknownError{err} | 			return nil, &UnknownError{Err: err} | ||||||
| 		} | 		} | ||||||
| 	case *ecdsa.PrivateKey: | 	case *ecdsa.PrivateKey: | ||||||
| 		pk := sk.Public() | 		pk := sk.Public() | ||||||
| 		tpl.SignatureAlgorithm = x509.ECDSAWithSHA256 | 		tpl.SignatureAlgorithm = x509.ECDSAWithSHA256 | ||||||
| 		certDER, err = x509.CreateCertificate(rand.Reader, &tpl, &tpl, pk, sk) | 		certDER, err = x509.CreateCertificate(rand.Reader, &tpl, &tpl, pk, sk) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, &UnknownError{err} | 			return nil, &UnknownError{Err: err} | ||||||
| 		} | 		} | ||||||
| 	default: | 	default: | ||||||
| 		return nil, &NotSupportedError{ErrPrivateKeyType} | 		return nil, &NotSupportedError{Err: ErrPrivateKeyType} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	cert, err := x509.ParseCertificate(certDER) | 	cert, err := x509.ParseCertificate(certDER) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, &UnknownError{err} | 		return nil, &UnknownError{Err: err} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return &RTCCertificate{secretKey: key, x509Cert: cert}, nil | 	return &RTCCertificate{secretKey: key, x509Cert: cert}, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| // Equals determines if two certificates are identical | // Equals determines if two certificates are identical by comparing both the | ||||||
|  | // secretKeys and x509Certificates. | ||||||
| func (c RTCCertificate) Equals(o RTCCertificate) bool { | func (c RTCCertificate) Equals(o RTCCertificate) bool { | ||||||
| 	switch cSK := c.secretKey.(type) { | 	switch cSK := c.secretKey.(type) { | ||||||
| 	case *rsa.PrivateKey: | 	case *rsa.PrivateKey: | ||||||
| @@ -72,6 +77,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 RTCCertificate) Expires() time.Time { | ||||||
| 	if c.x509Cert == nil { | 	if c.x509Cert == nil { | ||||||
| 		return time.Time{} | 		return time.Time{} | ||||||
| @@ -79,14 +85,18 @@ func (c RTCCertificate) Expires() time.Time { | |||||||
| 	return c.x509Cert.NotAfter | 	return c.x509Cert.NotAfter | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // 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() { | func (c RTCCertificate) GetFingerprints() { | ||||||
|  | 	panic("not implemented yet.") | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // 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) (*RTCCertificate, error) { | ||||||
| 	origin := make([]byte, 16) | 	origin := make([]byte, 16) | ||||||
| 	if _, err := rand.Read(origin); err != nil { | 	if _, err := rand.Read(origin); err != nil { | ||||||
| 		return nil, &UnknownError{err} | 		return nil, &UnknownError{Err: err} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// Max random value, a 130-bits integer, i.e 2^130 - 1 | 	// Max random value, a 130-bits integer, i.e 2^130 - 1 | ||||||
| @@ -94,7 +104,7 @@ func GenerateCertificate(secretKey crypto.PrivateKey) (*RTCCertificate, error) { | |||||||
| 	maxBigInt.Exp(big.NewInt(2), big.NewInt(130), nil).Sub(maxBigInt, big.NewInt(1)) | 	maxBigInt.Exp(big.NewInt(2), big.NewInt(130), nil).Sub(maxBigInt, big.NewInt(1)) | ||||||
| 	serialNumber, err := rand.Int(rand.Reader, maxBigInt) | 	serialNumber, err := rand.Int(rand.Reader, maxBigInt) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, &UnknownError{err} | 		return nil, &UnknownError{Err: err} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return NewRTCCertificate(secretKey, x509.Certificate{ | 	return NewRTCCertificate(secretKey, x509.Certificate{ | ||||||
|   | |||||||
| @@ -65,11 +65,11 @@ type RTCDataChannelInit struct { | |||||||
| // CreateDataChannel creates a new RTCDataChannel object with the given label and optitional options. | // CreateDataChannel creates a new RTCDataChannel object with the given label and optitional options. | ||||||
| func (pc *RTCPeerConnection) CreateDataChannel(label string, options *RTCDataChannelInit) (*RTCDataChannel, error) { | func (pc *RTCPeerConnection) CreateDataChannel(label string, options *RTCDataChannelInit) (*RTCDataChannel, error) { | ||||||
| 	if pc.IsClosed { | 	if pc.IsClosed { | ||||||
| 		return nil, &InvalidStateError{ErrConnectionClosed} | 		return nil, &InvalidStateError{Err: ErrConnectionClosed} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if len(label) > 65535 { | 	if len(label) > 65535 { | ||||||
| 		return nil, &TypeError{ErrInvalidValue} | 		return nil, &TypeError{Err: ErrInvalidValue} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// Defaults | 	// Defaults | ||||||
| @@ -95,12 +95,12 @@ func (pc *RTCPeerConnection) CreateDataChannel(label string, options *RTCDataCha | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if id > 65534 { | 	if id > 65534 { | ||||||
| 		return nil, &TypeError{ErrInvalidValue} | 		return nil, &TypeError{Err: ErrInvalidValue} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if pc.sctp.State == RTCSctpTransportStateConnected && | 	if pc.sctp.State == RTCSctpTransportStateConnected && | ||||||
| 		id >= pc.sctp.MaxChannels { | 		id >= pc.sctp.MaxChannels { | ||||||
| 		return nil, &OperationError{ErrMaxDataChannels} | 		return nil, &OperationError{Err: ErrMaxDataChannels} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	_ = ordered  // TODO | 	_ = ordered  // TODO | ||||||
| @@ -132,13 +132,13 @@ func (pc *RTCPeerConnection) generateDataChannelID(client bool) (uint16, error) | |||||||
| 			return id, nil | 			return id, nil | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	return 0, &OperationError{ErrMaxDataChannels} | 	return 0, &OperationError{Err: ErrMaxDataChannels} | ||||||
| } | } | ||||||
|  |  | ||||||
| // SendOpenChannelMessage is a test to send OpenChannel manually | // SendOpenChannelMessage is a test to send OpenChannel manually | ||||||
| func (d *RTCDataChannel) SendOpenChannelMessage() error { | func (d *RTCDataChannel) SendOpenChannelMessage() error { | ||||||
| 	if err := d.rtcPeerConnection.networkManager.SendOpenChannelMessage(d.ID, d.Label); err != nil { | 	if err := d.rtcPeerConnection.networkManager.SendOpenChannelMessage(d.ID, d.Label); err != nil { | ||||||
| 		return &UnknownError{err} | 		return &UnknownError{Err: err} | ||||||
| 	} | 	} | ||||||
| 	return nil | 	return nil | ||||||
|  |  | ||||||
| @@ -147,7 +147,7 @@ func (d *RTCDataChannel) SendOpenChannelMessage() error { | |||||||
| // Send sends the passed message to the DataChannel peer | // Send sends the passed message to the DataChannel peer | ||||||
| func (d *RTCDataChannel) Send(p datachannel.Payload) error { | func (d *RTCDataChannel) Send(p datachannel.Payload) error { | ||||||
| 	if err := d.rtcPeerConnection.networkManager.SendDataChannelMessage(p, d.ID); err != nil { | 	if err := d.rtcPeerConnection.networkManager.SendDataChannelMessage(p, d.ID); err != nil { | ||||||
| 		return &UnknownError{err} | 		return &UnknownError{Err: err} | ||||||
| 	} | 	} | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|   | |||||||
| @@ -14,7 +14,7 @@ const ( | |||||||
| 	RTCIceCredentialTypeOauth | 	RTCIceCredentialTypeOauth | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // NewRTCIceCredentialType defines a proceedure for creating a new | // NewRTCIceCredentialType defines a procedure for creating a new | ||||||
| // RTCIceCredentialType from a raw string naming the ice credential type. | // RTCIceCredentialType from a raw string naming the ice credential type. | ||||||
| func NewRTCIceCredentialType(raw string) RTCIceCredentialType { | func NewRTCIceCredentialType(raw string) RTCIceCredentialType { | ||||||
| 	switch raw { | 	switch raw { | ||||||
|   | |||||||
| @@ -27,23 +27,23 @@ func (s RTCIceServer) validate() error { | |||||||
| 		if url.Scheme == ice.SchemeTypeTURN || url.Scheme == ice.SchemeTypeTURNS { | 		if url.Scheme == ice.SchemeTypeTURN || url.Scheme == ice.SchemeTypeTURNS { | ||||||
| 			// https://www.w3.org/TR/webrtc/#set-the-configuration (step #11.3.2) | 			// https://www.w3.org/TR/webrtc/#set-the-configuration (step #11.3.2) | ||||||
| 			if s.Username == "" || s.Credential == nil { | 			if s.Username == "" || s.Credential == nil { | ||||||
| 				return &InvalidAccessError{ErrNoTurnCredencials} | 				return &InvalidAccessError{Err: ErrNoTurnCredencials} | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			switch s.CredentialType { | 			switch s.CredentialType { | ||||||
| 			case RTCIceCredentialTypePassword: | 			case RTCIceCredentialTypePassword: | ||||||
| 				// https://www.w3.org/TR/webrtc/#set-the-configuration (step #11.3.3) | 				// https://www.w3.org/TR/webrtc/#set-the-configuration (step #11.3.3) | ||||||
| 				if _, ok := s.Credential.(string); !ok { | 				if _, ok := s.Credential.(string); !ok { | ||||||
| 					return &InvalidAccessError{ErrTurnCredencials} | 					return &InvalidAccessError{Err: ErrTurnCredencials} | ||||||
| 				} | 				} | ||||||
| 			case RTCIceCredentialTypeOauth: | 			case RTCIceCredentialTypeOauth: | ||||||
| 				// https://www.w3.org/TR/webrtc/#set-the-configuration (step #11.3.4) | 				// https://www.w3.org/TR/webrtc/#set-the-configuration (step #11.3.4) | ||||||
| 				if _, ok := s.Credential.(RTCOAuthCredential); !ok { | 				if _, ok := s.Credential.(RTCOAuthCredential); !ok { | ||||||
| 					return &InvalidAccessError{ErrTurnCredencials} | 					return &InvalidAccessError{Err: ErrTurnCredencials} | ||||||
| 				} | 				} | ||||||
|  |  | ||||||
| 			default: | 			default: | ||||||
| 				return &InvalidAccessError{ErrTurnCredencials} | 				return &InvalidAccessError{Err: ErrTurnCredencials} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -40,25 +40,25 @@ func TestRTCIceServer_validate(t *testing.T) { | |||||||
| 		}{ | 		}{ | ||||||
| 			{RTCIceServer{ | 			{RTCIceServer{ | ||||||
| 				URLs: []string{"turn:192.158.29.39?transport=udp"}, | 				URLs: []string{"turn:192.158.29.39?transport=udp"}, | ||||||
| 			}, &InvalidAccessError{ErrNoTurnCredencials}}, | 			}, &InvalidAccessError{Err: ErrNoTurnCredencials}}, | ||||||
| 			{RTCIceServer{ | 			{RTCIceServer{ | ||||||
| 				URLs:           []string{"turn:192.158.29.39?transport=udp"}, | 				URLs:           []string{"turn:192.158.29.39?transport=udp"}, | ||||||
| 				Username:       "unittest", | 				Username:       "unittest", | ||||||
| 				Credential:     false, | 				Credential:     false, | ||||||
| 				CredentialType: RTCIceCredentialTypePassword, | 				CredentialType: RTCIceCredentialTypePassword, | ||||||
| 			}, &InvalidAccessError{ErrTurnCredencials}}, | 			}, &InvalidAccessError{Err: ErrTurnCredencials}}, | ||||||
| 			{RTCIceServer{ | 			{RTCIceServer{ | ||||||
| 				URLs:           []string{"turn:192.158.29.39?transport=udp"}, | 				URLs:           []string{"turn:192.158.29.39?transport=udp"}, | ||||||
| 				Username:       "unittest", | 				Username:       "unittest", | ||||||
| 				Credential:     false, | 				Credential:     false, | ||||||
| 				CredentialType: RTCIceCredentialTypeOauth, | 				CredentialType: RTCIceCredentialTypeOauth, | ||||||
| 			}, &InvalidAccessError{ErrTurnCredencials}}, | 			}, &InvalidAccessError{Err: ErrTurnCredencials}}, | ||||||
| 			{RTCIceServer{ | 			{RTCIceServer{ | ||||||
| 				URLs:           []string{"turn:192.158.29.39?transport=udp"}, | 				URLs:           []string{"turn:192.158.29.39?transport=udp"}, | ||||||
| 				Username:       "unittest", | 				Username:       "unittest", | ||||||
| 				Credential:     false, | 				Credential:     false, | ||||||
| 				CredentialType: Unknown, | 				CredentialType: Unknown, | ||||||
| 			}, &InvalidAccessError{ErrTurnCredencials}}, | 			}, &InvalidAccessError{Err: ErrTurnCredencials}}, | ||||||
| 			{RTCIceServer{ | 			{RTCIceServer{ | ||||||
| 				URLs:           []string{"stun:google.de?transport=udp"}, | 				URLs:           []string{"stun:google.de?transport=udp"}, | ||||||
| 				Username:       "unittest", | 				Username:       "unittest", | ||||||
|   | |||||||
| @@ -13,7 +13,7 @@ const ( | |||||||
| 	RTCIceTransportPolicyAll | 	RTCIceTransportPolicyAll | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // NewRTCIceTransportPolicy defines a proceedure for creating a new | // NewRTCIceTransportPolicy defines a procedure for creating a new | ||||||
| // RTCIceTransportPolicy from a raw string naming the ice transport policy. | // RTCIceTransportPolicy from a raw string naming the ice transport policy. | ||||||
| func NewRTCIceTransportPolicy(raw string) RTCIceTransportPolicy { | func NewRTCIceTransportPolicy(raw string) RTCIceTransportPolicy { | ||||||
| 	switch raw { | 	switch raw { | ||||||
|   | |||||||
| @@ -138,14 +138,14 @@ func (pc *RTCPeerConnection) initConfiguration(configuration RTCConfiguration) e | |||||||
| 		now := time.Now() | 		now := time.Now() | ||||||
| 		for _, x509Cert := range configuration.Certificates { | 		for _, x509Cert := range configuration.Certificates { | ||||||
| 			if !x509Cert.Expires().IsZero() && now.After(x509Cert.Expires()) { | 			if !x509Cert.Expires().IsZero() && now.After(x509Cert.Expires()) { | ||||||
| 				return &InvalidAccessError{ErrCertificateExpired} | 				return &InvalidAccessError{Err: ErrCertificateExpired} | ||||||
| 			} | 			} | ||||||
| 			pc.configuration.Certificates = append(pc.configuration.Certificates, x509Cert) | 			pc.configuration.Certificates = append(pc.configuration.Certificates, x509Cert) | ||||||
| 		} | 		} | ||||||
| 	} else { | 	} else { | ||||||
| 		sk, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) | 		sk, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return &UnknownError{err} | 			return &UnknownError{Err: err} | ||||||
| 		} | 		} | ||||||
| 		certificate, err := GenerateCertificate(sk) | 		certificate, err := GenerateCertificate(sk) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| @@ -185,13 +185,13 @@ func (pc *RTCPeerConnection) initConfiguration(configuration RTCConfiguration) e | |||||||
| func (pc *RTCPeerConnection) SetConfiguration(configuration RTCConfiguration) error { | func (pc *RTCPeerConnection) SetConfiguration(configuration RTCConfiguration) error { | ||||||
| 	// https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-setconfiguration (step #2) | 	// https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-setconfiguration (step #2) | ||||||
| 	if pc.IsClosed { | 	if pc.IsClosed { | ||||||
| 		return &InvalidStateError{ErrConnectionClosed} | 		return &InvalidStateError{Err: ErrConnectionClosed} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// https://www.w3.org/TR/webrtc/#set-the-configuration (step #3) | 	// https://www.w3.org/TR/webrtc/#set-the-configuration (step #3) | ||||||
| 	if configuration.PeerIdentity != "" { | 	if configuration.PeerIdentity != "" { | ||||||
| 		if configuration.PeerIdentity != pc.configuration.PeerIdentity { | 		if configuration.PeerIdentity != pc.configuration.PeerIdentity { | ||||||
| 			return &InvalidModificationError{ErrModifyingPeerIdentity} | 			return &InvalidModificationError{Err: ErrModifyingPeerIdentity} | ||||||
| 		} | 		} | ||||||
| 		pc.configuration.PeerIdentity = configuration.PeerIdentity | 		pc.configuration.PeerIdentity = configuration.PeerIdentity | ||||||
| 	} | 	} | ||||||
| @@ -199,12 +199,12 @@ func (pc *RTCPeerConnection) SetConfiguration(configuration RTCConfiguration) er | |||||||
| 	// https://www.w3.org/TR/webrtc/#set-the-configuration (step #4) | 	// https://www.w3.org/TR/webrtc/#set-the-configuration (step #4) | ||||||
| 	if len(configuration.Certificates) > 0 { | 	if len(configuration.Certificates) > 0 { | ||||||
| 		if len(configuration.Certificates) != len(pc.configuration.Certificates) { | 		if len(configuration.Certificates) != len(pc.configuration.Certificates) { | ||||||
| 			return &InvalidModificationError{ErrModifyingCertificates} | 			return &InvalidModificationError{Err: ErrModifyingCertificates} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		for i, certificate := range configuration.Certificates { | 		for i, certificate := range configuration.Certificates { | ||||||
| 			if !pc.configuration.Certificates[i].Equals(certificate) { | 			if !pc.configuration.Certificates[i].Equals(certificate) { | ||||||
| 				return &InvalidModificationError{ErrModifyingCertificates} | 				return &InvalidModificationError{Err: ErrModifyingCertificates} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		pc.configuration.Certificates = configuration.Certificates | 		pc.configuration.Certificates = configuration.Certificates | ||||||
| @@ -213,7 +213,7 @@ func (pc *RTCPeerConnection) SetConfiguration(configuration RTCConfiguration) er | |||||||
| 	// https://www.w3.org/TR/webrtc/#set-the-configuration (step #5) | 	// https://www.w3.org/TR/webrtc/#set-the-configuration (step #5) | ||||||
| 	if configuration.BundlePolicy != RTCBundlePolicy(Unknown) { | 	if configuration.BundlePolicy != RTCBundlePolicy(Unknown) { | ||||||
| 		if configuration.BundlePolicy != pc.configuration.BundlePolicy { | 		if configuration.BundlePolicy != pc.configuration.BundlePolicy { | ||||||
| 			return &InvalidModificationError{ErrModifyingBundlePolicy} | 			return &InvalidModificationError{Err: ErrModifyingBundlePolicy} | ||||||
| 		} | 		} | ||||||
| 		pc.configuration.BundlePolicy = configuration.BundlePolicy | 		pc.configuration.BundlePolicy = configuration.BundlePolicy | ||||||
| 	} | 	} | ||||||
| @@ -221,7 +221,7 @@ func (pc *RTCPeerConnection) SetConfiguration(configuration RTCConfiguration) er | |||||||
| 	// https://www.w3.org/TR/webrtc/#set-the-configuration (step #6) | 	// https://www.w3.org/TR/webrtc/#set-the-configuration (step #6) | ||||||
| 	if configuration.RtcpMuxPolicy != RTCRtcpMuxPolicy(Unknown) { | 	if configuration.RtcpMuxPolicy != RTCRtcpMuxPolicy(Unknown) { | ||||||
| 		if configuration.RtcpMuxPolicy != pc.configuration.RtcpMuxPolicy { | 		if configuration.RtcpMuxPolicy != pc.configuration.RtcpMuxPolicy { | ||||||
| 			return &InvalidModificationError{ErrModifyingRtcpMuxPolicy} | 			return &InvalidModificationError{Err: ErrModifyingRtcpMuxPolicy} | ||||||
| 		} | 		} | ||||||
| 		pc.configuration.RtcpMuxPolicy = configuration.RtcpMuxPolicy | 		pc.configuration.RtcpMuxPolicy = configuration.RtcpMuxPolicy | ||||||
| 	} | 	} | ||||||
| @@ -230,7 +230,7 @@ func (pc *RTCPeerConnection) SetConfiguration(configuration RTCConfiguration) er | |||||||
| 	if configuration.IceCandidatePoolSize != 0 { | 	if configuration.IceCandidatePoolSize != 0 { | ||||||
| 		if pc.configuration.IceCandidatePoolSize != configuration.IceCandidatePoolSize && | 		if pc.configuration.IceCandidatePoolSize != configuration.IceCandidatePoolSize && | ||||||
| 			pc.LocalDescription() != nil { | 			pc.LocalDescription() != nil { | ||||||
| 			return &InvalidModificationError{ErrModifyingIceCandidatePoolSize} | 			return &InvalidModificationError{Err: ErrModifyingIceCandidatePoolSize} | ||||||
| 		} | 		} | ||||||
| 		pc.configuration.IceCandidatePoolSize = configuration.IceCandidatePoolSize | 		pc.configuration.IceCandidatePoolSize = configuration.IceCandidatePoolSize | ||||||
| 	} | 	} | ||||||
| @@ -256,7 +256,7 @@ func (pc *RTCPeerConnection) SetConfiguration(configuration RTCConfiguration) er | |||||||
| // GetConfiguration returns an RTCConfiguration object representing the current | // GetConfiguration returns an RTCConfiguration object representing the current | ||||||
| // configuration of this RTCPeerConnection object. The returned object is a | // configuration of this RTCPeerConnection object. The returned object is a | ||||||
| // copy and direct mutation on it will not take affect until SetConfiguration | // copy and direct mutation on it will not take affect until SetConfiguration | ||||||
| // has been called with RTCConfiguration passed as its only arguement. | // has been called with RTCConfiguration passed as its only argument. | ||||||
| // https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-getconfiguration | // https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-getconfiguration | ||||||
| func (pc *RTCPeerConnection) GetConfiguration() RTCConfiguration { | func (pc *RTCPeerConnection) GetConfiguration() RTCConfiguration { | ||||||
| 	return pc.configuration | 	return pc.configuration | ||||||
| @@ -452,7 +452,7 @@ func (pc *RTCPeerConnection) CreateOffer(options *RTCOfferOptions) (RTCSessionDe | |||||||
| 	} else if useIdentity { | 	} else if useIdentity { | ||||||
| 		return RTCSessionDescription{}, errors.Errorf("TODO handle identity provider") | 		return RTCSessionDescription{}, errors.Errorf("TODO handle identity provider") | ||||||
| 	} else if pc.IsClosed { | 	} else if pc.IsClosed { | ||||||
| 		return RTCSessionDescription{}, &InvalidStateError{ErrConnectionClosed} | 		return RTCSessionDescription{}, &InvalidStateError{Err: ErrConnectionClosed} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	d := sdp.NewJSEPSessionDescription(pc.networkManager.DTLSFingerprint(), useIdentity) | 	d := sdp.NewJSEPSessionDescription(pc.networkManager.DTLSFingerprint(), useIdentity) | ||||||
| @@ -491,7 +491,7 @@ func (pc *RTCPeerConnection) CreateAnswer(options *RTCAnswerOptions) (RTCSession | |||||||
| 	} else if useIdentity { | 	} else if useIdentity { | ||||||
| 		return RTCSessionDescription{}, errors.Errorf("TODO handle identity provider") | 		return RTCSessionDescription{}, errors.Errorf("TODO handle identity provider") | ||||||
| 	} else if pc.IsClosed { | 	} else if pc.IsClosed { | ||||||
| 		return RTCSessionDescription{}, &InvalidStateError{ErrConnectionClosed} | 		return RTCSessionDescription{}, &InvalidStateError{Err: ErrConnectionClosed} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	candidates := pc.generateLocalCandidates() | 	candidates := pc.generateLocalCandidates() | ||||||
|   | |||||||
| @@ -64,7 +64,7 @@ func TestNew(t *testing.T) { | |||||||
| 				return New(RTCConfiguration{ | 				return New(RTCConfiguration{ | ||||||
| 					Certificates: []RTCCertificate{*certificate}, | 					Certificates: []RTCCertificate{*certificate}, | ||||||
| 				}) | 				}) | ||||||
| 			}, &InvalidAccessError{ErrCertificateExpired}}, | 			}, &InvalidAccessError{Err: ErrCertificateExpired}}, | ||||||
| 			{func() (*RTCPeerConnection, error) { | 			{func() (*RTCPeerConnection, error) { | ||||||
| 				return New(RTCConfiguration{ | 				return New(RTCConfiguration{ | ||||||
| 					IceServers: []RTCIceServer{ | 					IceServers: []RTCIceServer{ | ||||||
| @@ -77,7 +77,7 @@ func TestNew(t *testing.T) { | |||||||
| 						}, | 						}, | ||||||
| 					}, | 					}, | ||||||
| 				}) | 				}) | ||||||
| 			}, &InvalidAccessError{ErrNoTurnCredencials}}, | 			}, &InvalidAccessError{Err: ErrNoTurnCredencials}}, | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		for i, testCase := range testCases { | 		for i, testCase := range testCases { | ||||||
| @@ -140,14 +140,14 @@ func TestRTCPeerConnection_SetConfiguration(t *testing.T) { | |||||||
| 				return pc, err | 				return pc, err | ||||||
| 			}, func() RTCConfiguration { | 			}, func() RTCConfiguration { | ||||||
| 				return RTCConfiguration{} | 				return RTCConfiguration{} | ||||||
| 			}, &InvalidStateError{ErrConnectionClosed}}, | 			}, &InvalidStateError{Err: ErrConnectionClosed}}, | ||||||
| 			{func() (*RTCPeerConnection, error) { | 			{func() (*RTCPeerConnection, error) { | ||||||
| 				return New(RTCConfiguration{}) | 				return New(RTCConfiguration{}) | ||||||
| 			}, func() RTCConfiguration { | 			}, func() RTCConfiguration { | ||||||
| 				return RTCConfiguration{ | 				return RTCConfiguration{ | ||||||
| 					PeerIdentity: "unittest", | 					PeerIdentity: "unittest", | ||||||
| 				} | 				} | ||||||
| 			}, &InvalidModificationError{ErrModifyingPeerIdentity}}, | 			}, &InvalidModificationError{Err: ErrModifyingPeerIdentity}}, | ||||||
| 			{func() (*RTCPeerConnection, error) { | 			{func() (*RTCPeerConnection, error) { | ||||||
| 				return New(RTCConfiguration{}) | 				return New(RTCConfiguration{}) | ||||||
| 			}, func() RTCConfiguration { | 			}, func() RTCConfiguration { | ||||||
| @@ -166,7 +166,7 @@ func TestRTCPeerConnection_SetConfiguration(t *testing.T) { | |||||||
| 				return RTCConfiguration{ | 				return RTCConfiguration{ | ||||||
| 					Certificates: []RTCCertificate{*certificate1, *certificate2}, | 					Certificates: []RTCCertificate{*certificate1, *certificate2}, | ||||||
| 				} | 				} | ||||||
| 			}, &InvalidModificationError{ErrModifyingCertificates}}, | 			}, &InvalidModificationError{Err: ErrModifyingCertificates}}, | ||||||
| 			{func() (*RTCPeerConnection, error) { | 			{func() (*RTCPeerConnection, error) { | ||||||
| 				return New(RTCConfiguration{}) | 				return New(RTCConfiguration{}) | ||||||
| 			}, func() RTCConfiguration { | 			}, func() RTCConfiguration { | ||||||
| @@ -179,21 +179,21 @@ func TestRTCPeerConnection_SetConfiguration(t *testing.T) { | |||||||
| 				return RTCConfiguration{ | 				return RTCConfiguration{ | ||||||
| 					Certificates: []RTCCertificate{*certificate}, | 					Certificates: []RTCCertificate{*certificate}, | ||||||
| 				} | 				} | ||||||
| 			}, &InvalidModificationError{ErrModifyingCertificates}}, | 			}, &InvalidModificationError{Err: ErrModifyingCertificates}}, | ||||||
| 			{func() (*RTCPeerConnection, error) { | 			{func() (*RTCPeerConnection, error) { | ||||||
| 				return New(RTCConfiguration{}) | 				return New(RTCConfiguration{}) | ||||||
| 			}, func() RTCConfiguration { | 			}, func() RTCConfiguration { | ||||||
| 				return RTCConfiguration{ | 				return RTCConfiguration{ | ||||||
| 					BundlePolicy: RTCBundlePolicyMaxCompat, | 					BundlePolicy: RTCBundlePolicyMaxCompat, | ||||||
| 				} | 				} | ||||||
| 			}, &InvalidModificationError{ErrModifyingBundlePolicy}}, | 			}, &InvalidModificationError{Err: ErrModifyingBundlePolicy}}, | ||||||
| 			{func() (*RTCPeerConnection, error) { | 			{func() (*RTCPeerConnection, error) { | ||||||
| 				return New(RTCConfiguration{}) | 				return New(RTCConfiguration{}) | ||||||
| 			}, func() RTCConfiguration { | 			}, func() RTCConfiguration { | ||||||
| 				return RTCConfiguration{ | 				return RTCConfiguration{ | ||||||
| 					RtcpMuxPolicy: RTCRtcpMuxPolicyNegotiate, | 					RtcpMuxPolicy: RTCRtcpMuxPolicyNegotiate, | ||||||
| 				} | 				} | ||||||
| 			}, &InvalidModificationError{ErrModifyingRtcpMuxPolicy}}, | 			}, &InvalidModificationError{Err: ErrModifyingRtcpMuxPolicy}}, | ||||||
| 			// TODO Unittest for IceCandidatePoolSize cannot be done now needs pc.LocalDescription() | 			// TODO Unittest for IceCandidatePoolSize cannot be done now needs pc.LocalDescription() | ||||||
| 			{func() (*RTCPeerConnection, error) { | 			{func() (*RTCPeerConnection, error) { | ||||||
| 				return New(RTCConfiguration{}) | 				return New(RTCConfiguration{}) | ||||||
| @@ -209,7 +209,7 @@ func TestRTCPeerConnection_SetConfiguration(t *testing.T) { | |||||||
| 						}, | 						}, | ||||||
| 					}, | 					}, | ||||||
| 				} | 				} | ||||||
| 			}, &InvalidAccessError{ErrNoTurnCredencials}}, | 			}, &InvalidAccessError{Err: ErrNoTurnCredencials}}, | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		for i, testCase := range testCases { | 		for i, testCase := range testCases { | ||||||
|   | |||||||
| @@ -34,7 +34,7 @@ const ( | |||||||
| 	RTCPeerConnectionStateClosed | 	RTCPeerConnectionStateClosed | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // NewRTCPeerConnectionState defines a proceedure for creating a new | // NewRTCPeerConnectionState defines a procedure for creating a new | ||||||
| // RTCPeerConnectionState from a raw string naming the peer connection state. | // RTCPeerConnectionState from a raw string naming the peer connection state. | ||||||
| func NewRTCPeerConnectionState(raw string) RTCPeerConnectionState { | func NewRTCPeerConnectionState(raw string) RTCPeerConnectionState { | ||||||
| 	switch raw { | 	switch raw { | ||||||
|   | |||||||
| @@ -17,7 +17,7 @@ const ( | |||||||
| 	RTCRtcpMuxPolicyRequire | 	RTCRtcpMuxPolicyRequire | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // NewRTCRtcpMuxPolicy defines a proceedure for creating a new RTCRtcpMuxPolicy | // NewRTCRtcpMuxPolicy defines a procedure for creating a new RTCRtcpMuxPolicy | ||||||
| // from a raw string naming the rtcp multiplexing policy. | // from a raw string naming the rtcp multiplexing policy. | ||||||
| func NewRTCRtcpMuxPolicy(raw string) RTCRtcpMuxPolicy { | func NewRTCRtcpMuxPolicy(raw string) RTCRtcpMuxPolicy { | ||||||
| 	switch raw { | 	switch raw { | ||||||
|   | |||||||
| @@ -28,7 +28,7 @@ const ( | |||||||
| 	RTCSdpTypeRollback | 	RTCSdpTypeRollback | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // NewRTCSdpType defines a proceedure for creating a new RTCSdpType from a raw | // NewRTCSdpType defines a procedure for creating a new RTCSdpType from a raw | ||||||
| // string naming the session description protocol type. | // string naming the session description protocol type. | ||||||
| func NewRTCSdpType(raw string) RTCSdpType { | func NewRTCSdpType(raw string) RTCSdpType { | ||||||
| 	switch raw { | 	switch raw { | ||||||
|   | |||||||
| @@ -31,7 +31,7 @@ const ( | |||||||
| 	RTCSignalingStateClosed | 	RTCSignalingStateClosed | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // NewRTCSignalingState defines a proceedure for creating a new | // NewRTCSignalingState defines a procedure for creating a new | ||||||
| // RTCSignalingState from a raw string naming the signaling state. | // RTCSignalingState from a raw string naming the signaling state. | ||||||
| func NewRTCSignalingState(raw string) RTCSignalingState { | func NewRTCSignalingState(raw string) RTCSignalingState { | ||||||
| 	switch raw { | 	switch raw { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user